Skip to content

Commit 3273421

Browse files
authored
Amir py3 future fixes (#5)
* Keeping bytes as bytes. str(b'horrifying') gives 'b\'horrifying\'' results * python3 got no iteritems()
1 parent 3449a9a commit 3273421

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

mockredis/client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ def sunionstore(self, dest, keys, *args):
10911091
def zadd(self, name, mappings):
10921092
zset = self._get_zset(name, "ZADD", create=True)
10931093
insert_count = lambda member, score: 1 if zset.insert(self._encode(member), float(score)) else 0 # noqa
1094-
return sum((insert_count(member, score) for member, score in mappings.iteritems()))
1094+
return sum((insert_count(member, score) for member, score in list(mappings.items())))
10951095

10961096
def zcard(self, name):
10971097
zset = self._get_zset(name, "ZCARD")
@@ -1533,7 +1533,7 @@ def _score_inclusive(self, score):
15331533
def _encode(self, value):
15341534
"Return a bytestring representation of the value. Originally taken from redis-py connection.py"
15351535
if isinstance(value, (newbytes, bytes)):
1536-
return str(value)
1536+
value = value
15371537
elif isinstance(value, (int, long)):
15381538
value = str(value).encode('utf-8')
15391539
elif isinstance(value, float):
@@ -1543,10 +1543,7 @@ def _encode(self, value):
15431543
else:
15441544
value = value.encode('utf-8', 'strict')
15451545

1546-
if isinstance(value, bytes):
1547-
value = value.decode('utf-8', 'strict')
1548-
1549-
return value
1546+
return value.decode('utf-8', 'strict')
15501547

15511548
def _log(self, level, msg):
15521549
pass

mockredis/script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def _python_to_lua(pval):
190190
# in Lua returns: {k1, v1, k2, v2, k3, v3}
191191
lua_dict = lua.eval("{}")
192192
lua_table = lua.eval("table")
193-
for k, v in pval.iteritems():
193+
for k, v in list(pval.items()):
194194
lua_table.insert(lua_dict, Script._python_to_lua(k))
195195
lua_table.insert(lua_dict, Script._python_to_lua(v))
196196
return lua_dict

0 commit comments

Comments
 (0)