Skip to content
This repository was archived by the owner on Jan 3, 2024. It is now read-only.

Commit ea6ef41

Browse files
committed
Merge branch 'topic/default/issue3178' into 'branch/default'
Issue 3178: encode unicodes even in (built-in) files opened in binary mode See merge request pypy/pypy!717
2 parents 6ef3ab3 + 4690b9b commit ea6ef41

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

pypy/module/_file/interp_file.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,16 +502,16 @@ def file_write(self, w_data):
502502
the file on disk reflects the data written."""
503503
space = self.space
504504
self.check_writable()
505+
if space.isinstance_w(w_data, space.w_unicode):
506+
# note: "encode" is called before we acquire the lock
507+
# for this file, which is done in file_write_str().
508+
# Use a specific space method because we don't want
509+
# to call user-defined "encode" methods here.
510+
w_data = space.encode_unicode_object(w_data,
511+
self.encoding, self.errors)
505512
if self.binary:
506513
data = space.getarg_w('s*', w_data).as_str()
507514
else:
508-
if space.isinstance_w(w_data, space.w_unicode):
509-
# note: "encode" is called before we acquire the lock
510-
# for this file, which is done in file_write_str().
511-
# Use a specific space method because we don't want
512-
# to call user-defined "encode" methods here.
513-
w_data = space.encode_unicode_object(w_data,
514-
self.encoding, self.errors)
515515
data = space.charbuf_w(w_data)
516516
self.file_write_str(data)
517517

0 commit comments

Comments
 (0)