|
5 | 5 |
|
6 | 6 | import mockredis
|
7 | 7 | import redis
|
8 |
| -import swsssdk |
9 | 8 | from swsssdk import SonicV2Connector
|
10 | 9 | from swsssdk import SonicDBConfig
|
11 | 10 | from swsssdk.interface import DBInterface
|
|
16 | 15 | long = int
|
17 | 16 | xrange = range
|
18 | 17 | basestring = str
|
19 |
| - from functools import reduce |
20 | 18 |
|
21 | 19 | def clean_up_config():
|
22 | 20 | # Set SonicDBConfig variables to initial state
|
@@ -111,20 +109,14 @@ def __init__(self, *args, **kwargs):
|
111 | 109 |
|
112 | 110 | # Patch mockredis/mockredis/client.py
|
113 | 111 | # The offical implementation assume decode_responses=False
|
114 |
| - # Here we detect the option first and only encode when decode_responses=False |
| 112 | + # Here we detect the option and decode after doing encode |
115 | 113 | def _encode(self, value):
|
116 | 114 | "Return a bytestring representation of the value. Taken from redis-py connection.py"
|
117 |
| - if isinstance(value, bytes): |
118 |
| - return value |
119 |
| - elif isinstance(value, (int, long)): |
120 |
| - value = str(value).encode('utf-8') |
121 |
| - elif isinstance(value, float): |
122 |
| - value = repr(value).encode('utf-8') |
123 |
| - elif not isinstance(value, basestring): |
124 |
| - value = str(value).encode('utf-8') |
125 |
| - elif not self.decode_responses: |
126 |
| - value = value.encode('utf-8', 'strict') |
127 |
| - return value |
| 115 | + |
| 116 | + value = super(SwssSyncClient, self)._encode(value) |
| 117 | + |
| 118 | + if self.decode_responses: |
| 119 | + return value.decode('utf-8') |
128 | 120 |
|
129 | 121 | # Patch mockredis/mockredis/client.py
|
130 | 122 | # The official implementation will filter out keys with a slash '/'
|
|
0 commit comments