Author: Armin Rigo <ar...@tunes.org>
Branch: py3.5
Changeset: r90284:12c942ae2993
Date: 2017-02-22 09:44 +0100
http://bitbucket.org/pypy/pypy/changeset/12c942ae2993/

Log:    hg merge default

diff --git a/pypy/interpreter/main.py b/pypy/interpreter/main.py
--- a/pypy/interpreter/main.py
+++ b/pypy/interpreter/main.py
@@ -18,8 +18,8 @@
 
 def compilecode(space, source, filename, cmd='exec'):
     w_code = space.builtin.call(
-        'compile', space.newbytes(source), space.wrap_fsdecoded(filename),
-        space.wrap(cmd), space.newint(0), space.newint(0))
+        'compile', space.newbytes(source), space.newfilename(filename),
+        space.newtext(cmd), space.newint(0), space.newint(0))
     pycode = space.interp_w(eval.Code, w_code)
     return pycode
 
@@ -87,10 +87,11 @@
         argv.extend(args)
     space.setitem(space.sys.w_dict, space.newtext('argv'), space.wrap(argv))
     w_import = space.builtin.get('__import__')
-    runpy = space.call_function(w_import, space.wrap('runpy'))
-    w_run_module = space.getitem(runpy.w_dict, space.wrap('run_module'))
-    return space.call_function(w_run_module, space.wrap(module_name), 
space.w_None,
-                               space.wrap('__main__'), space.w_True)
+    runpy = space.call_function(w_import, space.newtext('runpy'))
+    w_run_module = space.getitem(runpy.w_dict, space.newtext('run_module'))
+    return space.call_function(w_run_module, space.newtext(module_name),
+                               space.w_None, space.newtext('__main__'),
+                               space.w_True)
 
 
 def run_toplevel(space, f, verbose=False):
diff --git a/pypy/interpreter/unicodehelper.py 
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -37,23 +37,6 @@
                                              space.newtext(msg)]))
     return raise_unicode_exception_encode
 
-class RUnicodeEncodeError(Exception):
-    def __init__(self, encoding, object, start, end, reason):
-        assert isinstance(object, unicode)
-        self.encoding = encoding
-        self.object = object
-        self.start = start
-        self.end = end
-        self.reason = reason
-
-@specialize.memo()
-def rpy_encode_error_handler():
-    # A RPython version of the "strict" error handler.
-    def raise_unicode_exception_encode(errors, encoding, msg, u,
-                                       startingpos, endingpos):
-        raise RUnicodeEncodeError(encoding, u, startingpos, endingpos, msg)
-    return raise_unicode_exception_encode
-
 # ____________________________________________________________
 
 def fsdecode(space, w_string):
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
@@ -96,12 +96,9 @@
             if ignore_sg:
                 identifier = unicode_encode_utf8sp(u, len(u))
             else:
-                eh = unicodehelper.rpy_encode_error_handler()
-                try:
-                    identifier = unicode_encode_utf_8(u, len(u), None,
-                                                      errorhandler=eh)
-                except unicodehelper.RUnicodeEncodeError as ue:
-                    raise wrap_encode_error(space, ue)
+                eh = unicodehelper.encode_error_handler(space)
+                identifier = unicode_encode_utf_8(u, len(u), None,
+                                                  errorhandler=eh)
         return identifier
 
     def text_w(self, space):
@@ -576,19 +573,16 @@
 
 def encode_object(space, w_object, encoding, errors):
     if errors is None or errors == 'strict':
-        try:
-            if encoding is None or encoding == 'utf-8':
-                u = space.unicode_w(w_object)
-                eh = unicodehelper.encode_error_handler(space)
-                return space.newbytes(unicode_encode_utf_8(
-                        u, len(u), errors, errorhandler=eh))
-            elif encoding == 'ascii':
-                u = space.unicode_w(w_object)
-                eh = unicodehelper.encode_error_handler(space)
-                return space.newbytes(unicode_encode_ascii(
-                        u, len(u), errors, errorhandler=eh))
-        except unicodehelper.RUnicodeEncodeError as ue:
-            raise wrap_encode_error(space, ue)
+        if encoding is None or encoding == 'utf-8':
+            u = space.unicode_w(w_object)
+            eh = unicodehelper.encode_error_handler(space)
+            return space.newbytes(unicode_encode_utf_8(
+                    u, len(u), errors, errorhandler=eh))
+        elif encoding == 'ascii':
+            u = space.unicode_w(w_object)
+            eh = unicodehelper.encode_error_handler(space)
+            return space.newbytes(unicode_encode_ascii(
+                    u, len(u), errors, errorhandler=eh))
 
     from pypy.module._codecs.interp_codecs import encode_text
     w_retval = encode_text(space, w_object, encoding, errors)
@@ -599,16 +593,6 @@
     return w_retval
 
 
-def wrap_encode_error(space, ue):
-    raise OperationError(space.w_UnicodeEncodeError,
-                         space.newtuple([
-        space.newtext(ue.encoding),
-        space.newunicode(ue.object),
-        space.newint(ue.start),
-        space.newint(ue.end),
-        space.newtext(ue.reason)]))
-
-
 def decode_object(space, w_obj, encoding, errors):
     if encoding is None:
         encoding = getdefaultencoding(space)
diff --git a/rpython/rlib/runicode.py b/rpython/rlib/runicode.py
--- a/rpython/rlib/runicode.py
+++ b/rpython/rlib/runicode.py
@@ -150,6 +150,9 @@
             (ordch1 == 0xf0 and ordch2 < 0x90) or
             (ordch1 == 0xf4 and ordch2 > 0x8f))
 
+# NOTE: this is a slightly fixed algorithm when compared with
+# CPython2's.  It is closer to CPython3's.  See comments in
+# test_invalid_cb_for_3bytes_seq().
 def str_decode_utf_8_impl(s, size, errors, final, errorhandler,
                           allow_surrogates):
     if size == 0:
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to