Author: Antonio Cuni <[email protected]>
Branch: py3k
Changeset: r57183:5e75489d575a
Date: 2012-09-04 17:25 +0200
http://bitbucket.org/pypy/pypy/changeset/5e75489d575a/

Log:    test&fix for converting bytes to int

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
@@ -31,7 +31,8 @@
                 from pypy.objspace.std.unicodeobject import 
unicode_to_decimal_w
             return string_to_w_long(space, w_longtype,
                                     unicode_to_decimal_w(space, w_value))
-        elif space.isinstance_w(w_value, space.w_bytearray):
+        elif (space.isinstance_w(w_value, space.w_bytearray) or
+              space.isinstance_w(w_value, space.w_bytes)):
             strvalue = space.bufferstr_w(w_value)
             return string_to_w_long(space, w_longtype, 
strvalue.decode('latin-1'))
         else:
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
@@ -324,6 +324,9 @@
         s = '\U0001D7CF\U0001D7CE' # &#120783;&#120782;
         assert int(s) == 10
 
+    def test_long_from_bytes(self):
+        assert int(b'1234') == 1234
+
     def test_invalid_literal_message(self):
         try:
             int('hello &#224;&#232;&#236;&#242;')
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to