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

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


Author: afa
Date: Thu Jul  1 18:49:54 2010
New Revision: 75725

Modified:
   pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py
   pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
Log:
charmap_encode: mapping should yield bytes <256.


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:49:54 2010
@@ -534,7 +534,11 @@
             if not e.match(space, space.w_TypeError):
                 raise
         else:
-            return chr(x)
+            if 0 <= x < 256:
+                return chr(x)
+            else:
+                raise OperationError(space.w_TypeError, space.wrap(
+                    "character mapping must be in range(256)"))
 
         # 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:49:54 2010
@@ -526,6 +526,9 @@
     def test_charmap_encode(self):
         assert 'xxx'.encode('charmap') == 'xxx'
 
+        import codecs
+        raises(TypeError, codecs.charmap_encode, u'\xff', "replace",  {0xff: 300})
+
     def test_charmap_encode_replace(self):
         charmap = dict([ (ord(c), 2*c.upper()) for c in "abcdefgh"])
         charmap[ord("?")] = "XYZ"



More information about the Pypy-commit mailing list