[pypy-commit] pypy py3k: allow unicode spaces in int literals

antocuni noreply at buildbot.pypy.org
Wed Oct 10 17:04:49 CEST 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r57973:76ac06f4ecdf
Date: 2012-10-10 16:08 +0200
http://bitbucket.org/pypy/pypy/changeset/76ac06f4ecdf/

Log:	allow unicode spaces in int literals

diff --git a/pypy/objspace/std/test/test_unicodeobject.py b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -1,7 +1,20 @@
+# -*- encoding: utf-8 -*-
 import py
 import sys
 from pypy.conftest import gettestobjspace
 
+def test_unicode_to_decimal_w():
+    from pypy.objspace.std.unicodeobject import unicode_to_decimal_w
+    space = gettestobjspace(usemodules=('unicodedata',))
+    w_s = space.wrap(u"\N{EM SPACE}-3\N{EN SPACE}")
+    s2 = unicode_to_decimal_w(space, w_s)
+    assert s2 == " -3 "
+    #
+    w_s = space.wrap(u'\U0001D7CF\U0001D7CE') # 𝟏𝟎
+    s2 = unicode_to_decimal_w(space, w_s)
+    assert s2 == "10"
+
+
 class AppTestUnicodeStringStdOnly:
     def test_compares(self):
         assert type('a') != type(b'a')
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -99,6 +99,9 @@
     for i in xrange(len(unistr)):
         uchr = ord(unistr[i])
         if uchr > 127:
+            if unicodedb.isspace(uchr):
+                result[i] = ' '
+                continue
             try:
                 uchr = ord(u'0') + unicodedb.decimal(uchr)
             except KeyError:


More information about the pypy-commit mailing list