[pypy-commit] pypy py3k: fix int(bytearray(...))

antocuni noreply at buildbot.pypy.org
Wed Jul 18 17:06:02 CEST 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r56168:abd04a3ac161
Date: 2012-07-18 16:38 +0200
http://bitbucket.org/pypy/pypy/changeset/abd04a3ac161/

Log:	fix int(bytearray(...))

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
@@ -32,8 +32,8 @@
             return string_to_w_long(space, w_longtype,
                                     unicode_to_decimal_w(space, w_value))
         elif space.isinstance_w(w_value, space.w_bytearray):
-            # XXX: convert to unicode
-            return string_to_w_long(space, w_longtype, space.bufferstr_w(w_value))
+            strvalue = space.bufferstr_w(w_value)
+            return string_to_w_long(space, w_longtype, strvalue.decode('latin1'))
         else:
             # otherwise, use the __int__() or the __trunc__ methods
             w_obj = w_value
@@ -57,7 +57,8 @@
             s = unicode_to_decimal_w(space, w_value)
         else:
             try:
-                s = space.bufferstr_w(w_value)
+                strval = space.bufferstr_w(w_value)
+                s = strval.decode('latin1')
             except OperationError, e:
                 raise OperationError(space.w_TypeError,
                                      space.wrap("long() can't convert non-string "
diff --git a/pypy/objspace/std/strutil.py b/pypy/objspace/std/strutil.py
--- a/pypy/objspace/std/strutil.py
+++ b/pypy/objspace/std/strutil.py
@@ -37,7 +37,6 @@
 class NumberStringParser:
 
     def error(self):
-        import pdb;pdb.set_trace()
         raise ParseStringError(u"invalid literal for %s() with base %d: '%s'" %
                                (self.fname, self.original_base, self.literal))
 
@@ -101,6 +100,7 @@
         else:
             return -1
 
+ at enforceargs(unicode, None)
 def string_to_int(s, base=10):
     """Utility to converts a string to an integer.
     If base is 0, the proper base is guessed based on the leading
@@ -125,6 +125,7 @@
         except OverflowError:
             raise ParseStringOverflowError(p)
 
+ at enforceargs(unicode, None, None)
 def string_to_bigint(s, base=10, parser=None):
     """As string_to_int(), but ignores an optional 'l' or 'L' suffix
     and returns an rbigint."""


More information about the pypy-commit mailing list