[pypy-commit] pypy py3.5: Move the loop out of space.wrap()

arigo pypy.commits at gmail.com
Tue Nov 15 04:07:20 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r88383:c7dfd649a692
Date: 2016-11-15 10:06 +0100
http://bitbucket.org/pypy/pypy/changeset/c7dfd649a692/

Log:	Move the loop out of space.wrap()

diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -155,18 +155,7 @@
             try:
                 unicode_x = x.decode('ascii')
             except UnicodeDecodeError:
-                # poor man's x.decode('ascii', 'replace'), since it's not
-                # supported by RPython
-                if not we_are_translated():
-                    print 'WARNING: space.wrap() called on a non-ascii byte string: %r' % x
-                lst = []
-                for ch in x:
-                    ch = ord(ch)
-                    if ch > 127:
-                        lst.append(u'\ufffd')
-                    else:
-                        lst.append(unichr(ch))
-                unicode_x = u''.join(lst)
+                unicode_x = self._wrap_ascii_replace(x)
             return self.newunicode(unicode_x)
         if isinstance(x, unicode):
             return self.newunicode(x)
@@ -191,6 +180,22 @@
                 return W_LongObject.fromrarith_int(x)
         return self._wrap_not_rpython(x)
 
+    def _wrap_ascii_replace(self, x):
+        # XXX should disappear soon?
+        # poor man's x.decode('ascii', 'replace'), since it's not
+        # supported by RPython
+        if not we_are_translated():
+            print 'WARNING: space.wrap() called on a non-ascii byte string: %r' % x
+        lst = []
+        for ch in x:
+            ch = ord(ch)
+            if ch > 127:
+                lst.append(u'\ufffd')
+            else:
+                lst.append(unichr(ch))
+        unicode_x = u''.join(lst)
+        return unicode_x
+
     def _wrap_not_rpython(self, x):
         "NOT_RPYTHON"
         # _____ this code is here to support testing only _____


More information about the pypy-commit mailing list