aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'pypy/objspace/std/unicodeobject.py')
-rw-r--r--pypy/objspace/std/unicodeobject.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
index 0be4a9e55c..16edebfb03 100644
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -1216,6 +1216,9 @@ def encode_object(space, w_obj, encoding, errors):
if rutf8.has_surrogates(utf8):
utf8 = rutf8.reencode_utf8_with_surrogates(utf8)
return space.newbytes(utf8)
+ if (encoding == "latin1" or encoding == "latin-1" and
+ isinstance(w_obj, W_UnicodeObject) and w_obj.is_ascii()):
+ return space.newbytes(w_obj._utf8)
return encode(space, w_obj, encoding, errors)