Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r88507:8c314acb8dd4
Date: 2016-11-21 09:48 +0100
http://bitbucket.org/pypy/pypy/changeset/8c314acb8dd4/

Log:    Issue #2425: actually, don't call the "encode" method generically.
        CPython doesn't do that when passed subclasses of unicode. That's
        why I have a hard time coming up with small tests that test anything
        on CPython.

diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -8,7 +8,6 @@
 from rpython.rlib.rstring import StringBuilder
 from pypy.module._file.interp_stream import W_AbstractStream, StreamErrors
 from pypy.module.posix.interp_posix import dispatch_filename
-from pypy.module.sys.interp_encoding import getdefaultencoding
 from pypy.interpreter.error import OperationError, oefmt, wrap_oserror
 from pypy.interpreter.typedef import (TypeDef, GetSetProperty,
     interp_attrproperty, make_weakref_descr, interp_attrproperty_w)
@@ -495,17 +494,12 @@
         else:
             if space.isinstance_w(w_data, space.w_unicode):
                 # note: "encode" is called before we acquire the lock
-                # for this file, which is done in file_write_str()
-                if self.encoding:
-                    w_encoding = space.wrap(self.encoding)
-                else:
-                    w_encoding = getdefaultencoding(space)
-                if self.errors:
-                    w_errors = space.wrap(self.errors)
-                else:
-                    w_errors = space.wrap("strict")
-                w_data = space.call_method(w_data, "encode",
-                                           w_encoding, w_errors)
+                # for this file, which is done in file_write_str().
+                # Direct access to unicodeobject because we don't want
+                # to call user-defined "encode" methods here.
+                from pypy.objspace.std.unicodeobject import encode_object
+                w_data = encode_object(space, w_data, self.encoding,
+                                       self.errors)
             data = space.charbuf_w(w_data)
         self.file_write_str(data)
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to