Skip to content

Commit

Permalink
use xrange in array and map unpacking
Browse files Browse the repository at this point in the history
and alias it to range under python 3.

Resolves #11.
  • Loading branch information
vsergeev committed Apr 6, 2015
1 parent 099fb5f commit 4a08514
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test_umsgpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def test_namespacing(self):
# Get a list of global variables from umsgpack module
exported_vars = list(filter(lambda x: not x.startswith("_"), dir(umsgpack)))
# Ignore imports
exported_vars = list(filter(lambda x: x != "struct" and x != "collections" and x != "sys" and x != "io", exported_vars))
exported_vars = list(filter(lambda x: x != "struct" and x != "collections" and x != "sys" and x != "io" and x != "xrange", exported_vars))

self.assertTrue(len(exported_vars) == len(exported_vars_test_vector))
for var in exported_vars_test_vector:
Expand Down
6 changes: 4 additions & 2 deletions umsgpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def _unpack_array(code, fp):
else:
raise Exception("logic error, not array: 0x%02x" % ord(code))

return [_unpack(fp) for i in range(length)]
return [_unpack(fp) for i in xrange(length)]

def _deep_list_to_tuple(obj):
if isinstance(obj, list):
Expand All @@ -618,7 +618,7 @@ def _unpack_map(code, fp):
raise Exception("logic error, not map: 0x%02x" % ord(code))

d = {}
for i in range(length):
for i in xrange(length):
# Unpack key
k = _unpack(fp)

Expand Down Expand Up @@ -793,6 +793,7 @@ def __init():
global compatibility
global _float_size
global _unpack_dispatch_table
global xrange

# Compatibility mode for handling strings/bytes with the old specification
compatibility = False
Expand All @@ -813,6 +814,7 @@ def __init():
unpackb = _unpackb3
load = _unpack3
loads = _unpackb3
xrange = range
else:
pack = _pack2
packb = _packb2
Expand Down

0 comments on commit 4a08514

Please sign in to comment.