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

afa at codespeak.net afa at codespeak.net
Tue Jun 29 13:34:42 CEST 2010


Author: afa
Date: Tue Jun 29 13:34:41 2010
New Revision: 75656

Modified:
   pypy/branch/interplevel-codecs/pypy/module/_codecs/__init__.py
   pypy/branch/interplevel-codecs/pypy/module/_codecs/app_codecs.py
   pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py
   pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
Log:
rewrite charmap_build() at interp-level


Modified: pypy/branch/interplevel-codecs/pypy/module/_codecs/__init__.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/module/_codecs/__init__.py	(original)
+++ pypy/branch/interplevel-codecs/pypy/module/_codecs/__init__.py	Tue Jun 29 13:34:41 2010
@@ -10,7 +10,6 @@
          'escape_encode' :  'app_codecs.escape_encode',
          'unicode_internal_decode' :  'app_codecs.unicode_internal_decode',
          'unicode_internal_encode' :  'app_codecs.unicode_internal_encode',
-         'charmap_build' : 'app_codecs.charmap_build'
     }
     interpleveldefs = {
          'encode':         'interp_codecs.encode',
@@ -19,6 +18,7 @@
          'lookup_error':   'interp_codecs.lookup_error',
          'register':       'interp_codecs.register_codec',
          'register_error': 'interp_codecs.register_error',
+         'charmap_build' : 'interp_codecs.charmap_build',
 
          # encoders and decoders
          'ascii_decode'     : 'interp_codecs.ascii_decode',

Modified: pypy/branch/interplevel-codecs/pypy/module/_codecs/app_codecs.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/module/_codecs/app_codecs.py	(original)
+++ pypy/branch/interplevel-codecs/pypy/module/_codecs/app_codecs.py	Tue Jun 29 13:34:41 2010
@@ -180,13 +180,3 @@
     else:
         raise TypeError("encoding error handler must return (unicode, int) tuple, not %s" % repr(res))
 
-
-def charmap_build(somestring):
-    m = {}
-    num = 0
-    for elem in somestring:
-        m[ord(elem)] = num
-        num += 1
-    return m
-
-    

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	Tue Jun 29 13:34:41 2010
@@ -537,6 +537,16 @@
         state.encode_error_handler, mapping)
     return space.newtuple([space.wrap(result), space.wrap(len(uni))])
 
+
+ at unwrap_spec(ObjSpace, unicode)
+def charmap_build(space, chars):
+    # XXX CPython sometimes uses a three-level trie
+    w_charmap = space.newdict()
+    for num in range(len(chars)):
+        elem = chars[num]
+        space.setitem(w_charmap, space.newint(ord(elem)), space.newint(num))
+    return w_charmap
+
 # ____________________________________________________________
 # Unicode escape
 

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	Tue Jun 29 13:34:41 2010
@@ -532,6 +532,11 @@
     def test_charmap_decode_2(self):
         assert 'foo'.decode('charmap') == 'foo'
 
+    def test_charmap_build(self):
+        import codecs
+        assert codecs.charmap_build(u'123456') == {49: 0, 50: 1, 51: 2,
+                                                   52: 3, 53: 4, 54: 5}
+
     def test_utf7_start_end_in_exception(self):
         try:
             '+IC'.decode('utf-7')



More information about the Pypy-commit mailing list