Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r59353:dcd5c7c5b9c3
Date: 2012-12-06 18:14 -0800
http://bitbucket.org/pypy/pypy/changeset/dcd5c7c5b9c3/
Log: fix from_bytes on iterables of ints
diff --git a/pypy/objspace/std/longtype.py b/pypy/objspace/std/longtype.py
--- a/pypy/objspace/std/longtype.py
+++ b/pypy/objspace/std/longtype.py
@@ -113,10 +113,11 @@
raise OperationError(space.w_OverflowError,
space.wrap("too many digits in integer"))
-@unwrap_spec(s='bufferstr', byteorder=str, signed=bool)
-def descr_from_bytes(space, w_cls, s, byteorder, signed=False):
+@unwrap_spec(byteorder=str, signed=bool)
+def descr_from_bytes(space, w_cls, w_obj, byteorder, signed=False):
+ bytes = space.bytes_w(space.call_function(space.w_bytes, w_obj))
try:
- bigint = rbigint.frombytes(s, byteorder=byteorder, signed=signed)
+ bigint = rbigint.frombytes(bytes, byteorder=byteorder, signed=signed)
except InvalidEndiannessError:
raise OperationError(
space.w_ValueError,
diff --git a/pypy/objspace/std/test/test_longobject.py
b/pypy/objspace/std/test/test_longobject.py
--- a/pypy/objspace/std/test/test_longobject.py
+++ b/pypy/objspace/std/test/test_longobject.py
@@ -304,6 +304,7 @@
assert int.from_bytes(b'\x01\x01', 'little') == 257
assert int.from_bytes(b'\x01\x00', 'big') == 256
assert int.from_bytes(b'\x00\x80', 'little', signed=True) == -32768
+ assert int.from_bytes([255, 0, 0], 'big', signed=True) == -65536
raises(TypeError, int.from_bytes, '', 'big')
raises(ValueError, int.from_bytes, b'c', 'foo')
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit