[issue14304] Implement utf-8-bmp codec

Serhiy Storchaka report at bugs.python.org
Mon Apr 16 19:13:52 CEST 2012


Serhiy Storchaka <storchaka at gmail.com> added the comment:

May be I did not correctly understand the problem, but I can assume,
that this patch solves it.

'Агов!\U00010000'

----------
keywords: +patch
Added file: http://bugs.python.org/file25244/idle_escape_nonbmp.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14304>
_______________________________________
-------------- next part --------------
diff -r 13307eb5bf47 Lib/idlelib/rpc.py
--- a/Lib/idlelib/rpc.py	Sat Apr 14 14:20:29 2012 -0500
+++ b/Lib/idlelib/rpc.py	Mon Apr 16 20:08:12 2012 +0300
@@ -615,10 +615,8 @@
     try:
         sys.stdout.write(text)
     except UnicodeEncodeError:
-        # let's use ascii while utf8-bmp codec doesn't present
-        encoding = 'ascii'
-        bytes = text.encode(encoding, 'backslashreplace')
-        text = bytes.decode(encoding, 'strict')
+        # escape non-BMP characters
+        text = ''.join(c if ord(c) <= 0xffff else '\\U%08x' % ord(c) for c in text)
         sys.stdout.write(text)
     sys.stdout.write("\n")
     builtins._ = value


More information about the Python-bugs-list mailing list