[pypy-commit] pypy py3k: sync with upstream rpython

pjenvey noreply at buildbot.pypy.org
Mon Feb 3 06:43:29 CET 2014


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r69053:9d1738eabe37
Date: 2014-02-02 21:38 -0800
http://bitbucket.org/pypy/pypy/changeset/9d1738eabe37/

Log:	sync with upstream rpython

diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py
--- a/rpython/rlib/rarithmetic.py
+++ b/rpython/rlib/rarithmetic.py
@@ -684,7 +684,6 @@
 # String parsing support
 # ---------------------------
 
- at objectmodel.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
@@ -694,7 +693,7 @@
     from rpython.rlib.rstring import (
         NumberStringParser, ParseStringOverflowError, strip_spaces)
     s = literal = strip_spaces(s)
-    p = NumberStringParser(s, literal, base, u'int')
+    p = NumberStringParser(s, literal, base, 'int')
     base = p.base
     result = 0
     while True:
diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -4,7 +4,7 @@
 from rpython.rlib.rfloat import isinf, isnan
 from rpython.rlib.rstring import StringBuilder
 from rpython.rlib.debug import make_sure_not_resized, check_regular_int
-from rpython.rlib.objectmodel import we_are_translated, specialize, enforceargs
+from rpython.rlib.objectmodel import we_are_translated, specialize
 from rpython.rlib import jit
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rtyper import extregistry
@@ -254,8 +254,7 @@
 
     @staticmethod
     @jit.elidable
-    @enforceargs(unicode, None, None, None)
-    def fromstr(s, base=0, ignore_l_suffix=False, fname=u'long'):
+    def fromstr(s, base=0, ignore_l_suffix=False, fname='long'):
         """As string_to_int(), but optionally ignores an optional 'l' or
         'L' suffix and returns an rbigint.
         """
diff --git a/rpython/rlib/rfloat.py b/rpython/rlib/rfloat.py
--- a/rpython/rlib/rfloat.py
+++ b/rpython/rlib/rfloat.py
@@ -41,22 +41,7 @@
     if not s:
         raise ParseStringError(INVALID_MSG)
 
-    try:
-        ascii_s = s.encode('ascii')
-    except UnicodeEncodeError:
-        # if s is not ASCII, it certainly is not a float literal (because the
-        # unicode-decimal to ascii-decimal conversion already happened
-        # earlier). We just set ascii_s to something which will fail when
-        # passed to rstring_to_float, to keep the code as similar as possible
-        # to the one we have on default.
-        #
-        # Note that CPython does something different and it encodes the string
-        # to UTF-8 before trying to parse it. We cannot since .encode('utf-8')
-        # is not RPython. However, it doesn't change anything since the UTF-8
-        # encoded string would make rstring_to_float to fail anyway.
-        ascii_s = "not a float"
-
-    low = ascii_s.lower()
+    low = s.lower()
     if low == "-inf" or low == "-infinity":
         return -INFINITY
     elif low == "inf" or low == "+inf":
@@ -69,7 +54,7 @@
         return -NAN
 
     try:
-        return rstring_to_float(ascii_s)
+        return rstring_to_float(s)
     except ValueError:
         raise ParseStringError(INVALID_MSG)
 
diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py
--- a/rpython/rlib/rstring.py
+++ b/rpython/rlib/rstring.py
@@ -6,12 +6,11 @@
     SomeInteger, SomeUnicodeCodePoint, SomeUnicodeString, SomePBC)
 from rpython.rtyper.llannotation import SomePtr
 from rpython.rlib import jit
-from rpython.rlib.objectmodel import newlist_hint, specialize, enforceargs
+from rpython.rlib.objectmodel import newlist_hint, specialize
 from rpython.rlib.rarithmetic import ovfcheck
 from rpython.rlib.unicodedata import unicodedb_5_2_0 as unicodedb
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from rpython.tool.pairtype import pairtype
-from rpython.tool.sourcetools import with_unicode_literals
 
 
 # -------------- public API for string functions -----------------------
@@ -264,8 +263,6 @@
 
 # -------------- numeric parsing support --------------------
 
- at enforceargs(unicode)
- at with_unicode_literals
 def strip_spaces(s):
     # XXX this is not locale-dependent
     p = 0
@@ -278,7 +275,6 @@
     return s[p:q]
 
 class ParseStringError(Exception):
-    @enforceargs(None, unicode)
     def __init__(self, msg):
         self.msg = msg
 
@@ -296,8 +292,6 @@
         raise ParseStringError("invalid literal for %s() with base %d" %
                                (self.fname, self.original_base))
 
-    @enforceargs(None, unicode, unicode, int, unicode)
-    @with_unicode_literals
     def __init__(self, s, literal, base, fname):
         self.fname = fname
         sign = 1
@@ -337,7 +331,6 @@
     def rewind(self):
         self.i = 0
 
-    @with_unicode_literals
     def next_digit(self): # -1 => exhausted
         if self.i < self.n:
             c = self.s[self.i]
diff --git a/rpython/rlib/test/test_rarithmetic.py b/rpython/rlib/test/test_rarithmetic.py
--- a/rpython/rlib/test/test_rarithmetic.py
+++ b/rpython/rlib/test/test_rarithmetic.py
@@ -413,49 +413,49 @@
 class TestStringToInt:
 
     def test_string_to_int(self):
-        cases = [(u'0', 0),
-                 (u'1', 1),
-                 (u'9', 9),
-                 (u'10', 10),
-                 (u'09', 9),
-                 (u'0000101', 101),    # not octal unless base 0 or 8
-                 (u'5123', 5123),
-                 (u' 0', 0),
-                 (u'0  ', 0),
-                 (u' \t \n   32313  \f  \v   \r  \n\r    ', 32313),
-                 (u'+12', 12),
-                 (u'-5', -5),
-                 (u'- 5', -5),
-                 (u'+ 5', 5),
-                 (u'  -123456789 ', -123456789),
+        cases = [('0', 0),
+                 ('1', 1),
+                 ('9', 9),
+                 ('10', 10),
+                 ('09', 9),
+                 ('0000101', 101),    # not octal unless base 0 or 8
+                 ('5123', 5123),
+                 (' 0', 0),
+                 ('0  ', 0),
+                 (' \t \n   32313  \f  \v   \r  \n\r    ', 32313),
+                 ('+12', 12),
+                 ('-5', -5),
+                 ('- 5', -5),
+                 ('+ 5', 5),
+                 ('  -123456789 ', -123456789),
                  ]
         for s, expected in cases:
             assert string_to_int(s) == expected
             #assert string_to_bigint(s).tolong() == expected
 
     def test_string_to_int_base(self):
-        cases = [(u'111', 2, 7),
-                 (u'010', 2, 2),
-                 (u'102', 3, 11),
-                 (u'103', 4, 19),
-                 (u'107', 8, 71),
-                 (u'109', 10, 109),
-                 (u'10A', 11, 131),
-                 (u'10a', 11, 131),
-                 (u'10f', 16, 271),
-                 (u'10F', 16, 271),
-                 (u'0x10f', 16, 271),
-                 (u'0x10F', 16, 271),
-                 (u'10z', 36, 1331),
-                 (u'10Z', 36, 1331),
-                 (u'12',   0, 12),
-                 (u'015',  0, 13),
-                 (u'0x10', 0, 16),
-                 (u'0XE',  0, 14),
-                 (u'0',    0, 0),
-                 (u'0b11', 2, 3),
-                 (u'0B10', 2, 2),
-                 (u'0o77', 8, 63),
+        cases = [('111', 2, 7),
+                 ('010', 2, 2),
+                 ('102', 3, 11),
+                 ('103', 4, 19),
+                 ('107', 8, 71),
+                 ('109', 10, 109),
+                 ('10A', 11, 131),
+                 ('10a', 11, 131),
+                 ('10f', 16, 271),
+                 ('10F', 16, 271),
+                 ('0x10f', 16, 271),
+                 ('0x10F', 16, 271),
+                 ('10z', 36, 1331),
+                 ('10Z', 36, 1331),
+                 ('12',   0, 12),
+                 ('015',  0, 13),
+                 ('0x10', 0, 16),
+                 ('0XE',  0, 14),
+                 ('0',    0, 0),
+                 ('0b11', 2, 3),
+                 ('0B10', 2, 2),
+                 ('0o77', 8, 63),
                  ]
         for s, base, expected in cases:
             assert string_to_int(s, base) == expected
@@ -466,21 +466,21 @@
             assert string_to_int('-'+s+'  ', base) == -expected
 
     def test_string_to_int_error(self):
-        cases = [u'0x123',    # must use base 0 or 16
-                 u' 0X12 ',
-                 u'0b01',
-                 u'0o01',
-                 u'',
-                 u'++12',
-                 u'+-12',
-                 u'-+12',
-                 u'--12',
-                 u'12a6',
-                 u'12A6',
-                 u'f',
-                 u'Z',
-                 u'.',
-                 u'@',
+        cases = ['0x123',    # must use base 0 or 16
+                 ' 0X12 ',
+                 '0b01',
+                 '0o01',
+                 '',
+                 '++12',
+                 '+-12',
+                 '-+12',
+                 '--12',
+                 '12a6',
+                 '12A6',
+                 'f',
+                 'Z',
+                 '.',
+                 '@',
                  ]
         for s in cases:
             py.test.raises(ParseStringError, string_to_int, s)
@@ -488,39 +488,39 @@
             py.test.raises(ParseStringError, string_to_int, s+'  ')
             py.test.raises(ParseStringError, string_to_int, '+'+s)
             py.test.raises(ParseStringError, string_to_int, '-'+s)
-        py.test.raises(ParseStringError, string_to_int, u'0x', 16)
-        py.test.raises(ParseStringError, string_to_int, u'-0x', 16)
+        py.test.raises(ParseStringError, string_to_int, '0x', 16)
+        py.test.raises(ParseStringError, string_to_int, '-0x', 16)
 
-        exc = py.test.raises(ParseStringError, string_to_int, u'')
+        exc = py.test.raises(ParseStringError, string_to_int, '')
         assert exc.value.msg == "invalid literal for int() with base 10: ''"
-        exc = py.test.raises(ParseStringError, string_to_int, u'', 0)
+        exc = py.test.raises(ParseStringError, string_to_int, '', 0)
         assert exc.value.msg == "invalid literal for int() with base 0: ''"
 
     def test_string_to_int_overflow(self):
         import sys
         py.test.raises(ParseStringOverflowError, string_to_int,
-               unicode(sys.maxint*17))
+               str(sys.maxint*17))
 
     def test_string_to_int_not_overflow(self):
         import sys
         for x in [-sys.maxint-1, sys.maxint]:
-            y = string_to_int(unicode(x))
+            y = string_to_int(str(x))
             assert y == x
 
     def test_string_to_int_base_error(self):
-        cases = [(u'1', 1),
-                 (u'1', 37),
-                 (u'a', 0),
-                 (u'9', 9),
-                 (u'0x123', 7),
-                 (u'145cdf', 15),
-                 (u'12', 37),
-                 (u'12', 98172),
-                 (u'12', -1),
-                 (u'12', -908),
-                 (u'12.3', 10),
-                 (u'12.3', 13),
-                 (u'12.3', 16),
+        cases = [('1', 1),
+                 ('1', 37),
+                 ('a', 0),
+                 ('9', 9),
+                 ('0x123', 7),
+                 ('145cdf', 15),
+                 ('12', 37),
+                 ('12', 98172),
+                 ('12', -1),
+                 ('12', -908),
+                 ('12.3', 10),
+                 ('12.3', 13),
+                 ('12.3', 16),
                  ]
         for s, base in cases:
             py.test.raises(ParseStringError, string_to_int, s, base)
diff --git a/rpython/rlib/test/test_rbigint.py b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -212,24 +212,24 @@
 
     def test_fromstr(self):
         from rpython.rlib.rstring import ParseStringError
-        assert rbigint.fromstr(u'123L').tolong() == 123
-        assert rbigint.fromstr(u'123L  ').tolong() == 123
-        py.test.raises(ParseStringError, rbigint.fromstr, u'123L  ',
+        assert rbigint.fromstr('123L').tolong() == 123
+        assert rbigint.fromstr('123L  ').tolong() == 123
+        py.test.raises(ParseStringError, rbigint.fromstr, '123L  ',
                        ignore_l_suffix=True)
-        py.test.raises(ParseStringError, rbigint.fromstr, u'L')
-        py.test.raises(ParseStringError, rbigint.fromstr, u'L  ')
-        e = py.test.raises(ParseStringError, rbigint.fromstr, u'L  ',
-                           fname=u'int')
-        assert u'int()' in e.value.msg
-        assert rbigint.fromstr(u'123L', 4).tolong() == 27
-        assert rbigint.fromstr(u'123L', 30).tolong() == 27000 + 1800 + 90 + 21
-        assert rbigint.fromstr(u'123L', 22).tolong() == 10648 + 968 + 66 + 21
-        assert rbigint.fromstr(u'123L', 21).tolong() == 441 + 42 + 3
-        assert rbigint.fromstr(u'1891234174197319').tolong() == 1891234174197319
+        py.test.raises(ParseStringError, rbigint.fromstr, 'L')
+        py.test.raises(ParseStringError, rbigint.fromstr, 'L  ')
+        e = py.test.raises(ParseStringError, rbigint.fromstr, 'L  ',
+                           fname='int')
+        assert 'int()' in e.value.msg
+        assert rbigint.fromstr('123L', 4).tolong() == 27
+        assert rbigint.fromstr('123L', 30).tolong() == 27000 + 1800 + 90 + 21
+        assert rbigint.fromstr('123L', 22).tolong() == 10648 + 968 + 66 + 21
+        assert rbigint.fromstr('123L', 21).tolong() == 441 + 42 + 3
+        assert rbigint.fromstr('1891234174197319').tolong() == 1891234174197319
 
     def test_from_numberstring_parser(self):
         from rpython.rlib.rstring import NumberStringParser
-        parser = NumberStringParser(u"1231231241", u"1231231241", 10, u"long")
+        parser = NumberStringParser("1231231241", "1231231241", 10, "long")
         assert rbigint._from_numberstring_parser(parser).tolong() == 1231231241
 
     def test_add(self):
diff --git a/rpython/rlib/test/test_rfloat.py b/rpython/rlib/test/test_rfloat.py
--- a/rpython/rlib/test/test_rfloat.py
+++ b/rpython/rlib/test/test_rfloat.py
@@ -217,19 +217,19 @@
 def test_string_to_float():
     from rpython.rlib.rstring import ParseStringError
     import random
-    assert string_to_float(u'0') == 0.0
-    assert string_to_float(u'1') == 1.0
-    assert string_to_float(u'-1.5') == -1.5
-    assert string_to_float(u'1.5E2') == 150.0
-    assert string_to_float(u'2.5E-1') == 0.25
-    assert string_to_float(u'1e1111111111111') == float('1e1111111111111')
-    assert string_to_float(u'1e-1111111111111') == float('1e-1111111111111')
-    assert string_to_float(u'-1e1111111111111') == float('-1e1111111111111')
-    assert string_to_float(u'-1e-1111111111111') == float('-1e-1111111111111')
-    assert string_to_float(u'1e111111111111111111111') == float('1e111111111111111111111')
-    assert string_to_float(u'1e-111111111111111111111') == float('1e-111111111111111111111')
-    assert string_to_float(u'-1e111111111111111111111') == float('-1e111111111111111111111')
-    assert string_to_float(u'-1e-111111111111111111111') == float('-1e-111111111111111111111')
+    assert string_to_float('0') == 0.0
+    assert string_to_float('1') == 1.0
+    assert string_to_float('-1.5') == -1.5
+    assert string_to_float('1.5E2') == 150.0
+    assert string_to_float('2.5E-1') == 0.25
+    assert string_to_float('1e1111111111111') == float('1e1111111111111')
+    assert string_to_float('1e-1111111111111') == float('1e-1111111111111')
+    assert string_to_float('-1e1111111111111') == float('-1e1111111111111')
+    assert string_to_float('-1e-1111111111111') == float('-1e-1111111111111')
+    assert string_to_float('1e111111111111111111111') == float('1e111111111111111111111')
+    assert string_to_float('1e-111111111111111111111') == float('1e-111111111111111111111')
+    assert string_to_float('-1e111111111111111111111') == float('-1e111111111111111111111')
+    assert string_to_float('-1e-111111111111111111111') == float('-1e-111111111111111111111')
 
     valid_parts = [['', '  ', ' \f\n\r\t\v'],
                    ['', '+', '-'],
@@ -251,7 +251,7 @@
             for part2 in valid_parts[2]:
                 for part3 in valid_parts[3]:
                     for part4 in valid_parts[4]:
-                        s = unicode(part0+part1+part2+part3+part4)
+                        s = part0+part1+part2+part3+part4
                         assert (abs(string_to_float(s) - float(s)) <=
                                 1E-13 * abs(float(s)))
 
@@ -260,8 +260,8 @@
             for i in range(20):
                 parts = [random.choice(lst) for lst in valid_parts]
                 parts[j] = invalid
-                s = u''.join(parts)
+                s = ''.join(parts)
                 print repr(s)
                 if s.strip(): # empty s raises OperationError directly
                     py.test.raises(ParseStringError, string_to_float, s)
-    py.test.raises(ParseStringError, string_to_float, u"")
+    py.test.raises(ParseStringError, string_to_float, "")


More information about the pypy-commit mailing list