Commit 80ac79bc authored by Tim Peters's avatar Tim Peters

decode_long(): Simplified the "is it negative?" test.

parent b828cd7a
...@@ -590,14 +590,17 @@ def decode_long(data): ...@@ -590,14 +590,17 @@ def decode_long(data):
-256L -256L
>>> decode_long("\x00\x80") >>> decode_long("\x00\x80")
-32768L -32768L
>>> >>> decode_long("\x80")
-128L
>>> decode_long("\x7f")
127L
""" """
x = 0L x = 0L
i = 0L i = 0L
for c in data: for c in data:
x |= long(ord(c)) << i x |= long(ord(c)) << i
i += 8L i += 8L
if i and (x & (1L << (i-1L))): if data and ord(c) >= 0x80:
x -= 1L << i x -= 1L << i
return x return x
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment