[pypy-svn] r75726 - in pypy/branch/interplevel-codecs/pypy/module/_codecs: . test

afa at codespeak.net afa at codespeak.net
Thu Jul 1 18:56:19 CEST 2010


Author: afa
Date: Thu Jul  1 18:56:17 2010
New Revision: 75726

Modified:
   pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py
   pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
Log:
charmap_decode: mapping should yield chars <= 65535
(even on wide unicode builds)


Modified: pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py	(original)
+++ pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py	Thu Jul  1 18:56:17 2010
@@ -494,7 +494,11 @@
             if not e.match(space, space.w_TypeError):
                 raise
         else:
-            return unichr(x)
+            if 0 <= x < 65536: # Even on wide unicode builds...
+                return unichr(x)
+            else:
+                raise OperationError(space.w_TypeError, space.wrap(
+                    "character mapping must be in range(65536)"))
 
         # Charmap may return None
         if space.is_w(w_ch, space.w_None):

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	Thu Jul  1 18:56:17 2010
@@ -106,12 +106,15 @@
 
     def test_charmap_decode(self):
         from _codecs import charmap_decode
+        import sys
         assert charmap_decode('', 'strict', 'blablabla') == ('', 0)
         assert charmap_decode('xxx') == ('xxx', 3)
         assert charmap_decode('xxx', 'strict', {ord('x'): u'XX'}) == ('XXXXXX', 3)
         map = tuple([unichr(i) for i in range(256)])
         assert charmap_decode('xxx\xff', 'strict', map) == (u'xxx\xff', 4)
 
+        raises(TypeError, charmap_decode, '\xff', "replace",  {0xff: 0x10001})
+
     def test_unicode_escape(self):
         from _codecs import unicode_escape_encode, unicode_escape_decode
         assert unicode_escape_encode(u'abc') == (u'abc'.encode('unicode_escape'), 3)



More information about the Pypy-commit mailing list