Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r59352:b1a4f4d62d78
Date: 2012-12-06 17:52 -0800
http://bitbucket.org/pypy/pypy/changeset/b1a4f4d62d78/
Log: fix frombytes on empty strings
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -273,6 +273,8 @@
def frombytes(s, byteorder, signed):
if byteorder not in ('big', 'little'):
raise InvalidEndiannessError()
+ if not s:
+ return NULLRBIGINT
if byteorder != BYTEORDER:
msb = ord(s[0])
diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py
--- a/pypy/rlib/test/test_rbigint.py
+++ b/pypy/rlib/test/test_rbigint.py
@@ -771,6 +771,8 @@
assert res == -42.0
def test_frombytes(self):
+ bigint = rbigint.frombytes('', byteorder='big', signed=True)
+ assert bigint.tolong() == 0
s = "\xFF\x12\x34\x56"
bigint = rbigint.frombytes(s, byteorder="big", signed=False)
assert bigint.tolong() == 0xFF123456
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit