[pypy-svn] r75669 - in pypy/branch/interplevel-codecs/pypy: module/_codecs/test rlib

afa at codespeak.net afa at codespeak.net
Wed Jun 30 10:46:37 CEST 2010


Author: afa
Date: Wed Jun 30 10:46:35 2010
New Revision: 75669

Modified:
   pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
   pypy/branch/interplevel-codecs/pypy/rlib/runicode.py
Log:
use \x escape code when possible. Test and fix.


Modified: pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py	(original)
+++ pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py	Wed Jun 30 10:46:35 2010
@@ -554,6 +554,7 @@
         assert u'\\'.encode('unicode-escape') == '\\\\'
         assert '\\\\'.decode('unicode-escape') == u'\\'
         assert u'\ud801'.encode('unicode-escape') == '\\ud801'
+        assert u'\u0013'.encode('unicode-escape') == '\\x13'
 
     def test_mbcs(self):
         import sys

Modified: pypy/branch/interplevel-codecs/pypy/rlib/runicode.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/rlib/runicode.py	(original)
+++ pypy/branch/interplevel-codecs/pypy/rlib/runicode.py	Wed Jun 30 10:46:35 2010
@@ -1095,9 +1095,12 @@
     if char >= 0x10000:
         result.append("\\U")
         zeros = 8
-    else:
+    elif char >= 0x100:
         result.append("\\u")
         zeros = 4
+    else:
+        result.append("\\x")
+        zeros = 2
     nb = zeros + 2 - len(num) # num starts with '0x'
     if nb > 0:
         result.append_multiple_char('0', nb)



More information about the Pypy-commit mailing list