[pypy-svn] r61081 - in pypy/trunk/pypy/module/_codecs: . test

fijal at codespeak.net fijal at codespeak.net
Sun Jan 18 16:41:43 CET 2009


Author: fijal
Date: Sun Jan 18 16:41:42 2009
New Revision: 61081

Modified:
   pypy/trunk/pypy/module/_codecs/__init__.py
   pypy/trunk/pypy/module/_codecs/app_codecs.py
   pypy/trunk/pypy/module/_codecs/interp_codecs.py
   pypy/trunk/pypy/module/_codecs/test/test_codecs.py
Log:
A small bit of cleanup, more to follow


Modified: pypy/trunk/pypy/module/_codecs/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/_codecs/__init__.py	(original)
+++ pypy/trunk/pypy/module/_codecs/__init__.py	Sun Jan 18 16:41:42 2009
@@ -4,7 +4,6 @@
     appleveldefs = {
          '__doc__' :  'app_codecs.__doc__',
          '__name__' :  'app_codecs.__name__',
-         'charbuffer_encode' :  'app_codecs.charbuffer_encode',
          'charmap_decode' :  'app_codecs.charmap_decode',
          'charmap_encode' :  'app_codecs.charmap_encode',
          'escape_decode' :  'app_codecs.escape_decode',
@@ -13,7 +12,6 @@
          'mbcs_encode' :  'app_codecs.mbcs_encode',
          'raw_unicode_escape_decode' :  'app_codecs.raw_unicode_escape_decode',
          'raw_unicode_escape_encode' :  'app_codecs.raw_unicode_escape_encode',
-         'readbuffer_encode' :  'app_codecs.readbuffer_encode',
          'unicode_escape_decode' :  'app_codecs.unicode_escape_decode',
          'unicode_escape_encode' :  'app_codecs.unicode_escape_encode',
          'unicode_internal_decode' :  'app_codecs.unicode_internal_decode',
@@ -45,6 +43,8 @@
          'utf_16_le_decode' : 'interp_codecs.utf_16_le_decode',
          'utf_16_le_encode' : 'interp_codecs.utf_16_le_encode',
          'utf_16_ex_decode' : 'interp_codecs.utf_16_ex_decode',
+         'charbuffer_encode': 'interp_codecs.buffer_encode',
+         'readbuffer_encode': 'interp_codecs.buffer_encode',
     }
 
     def setup_after_space_initialization(self):

Modified: pypy/trunk/pypy/module/_codecs/app_codecs.py
==============================================================================
--- pypy/trunk/pypy/module/_codecs/app_codecs.py	(original)
+++ pypy/trunk/pypy/module/_codecs/app_codecs.py	Sun Jan 18 16:41:42 2009
@@ -199,13 +199,6 @@
     res = ''.join(res)    
     return res, len(data)
 
-def charbuffer_encode( obj, errors='strict'):
-    """None
-    """
-    res = str(obj)
-    res = ''.join(res)
-    return res, len(res)
-
 def charmap_decode( data, errors='strict', mapping=None):
     """None
     """

Modified: pypy/trunk/pypy/module/_codecs/interp_codecs.py
==============================================================================
--- pypy/trunk/pypy/module/_codecs/interp_codecs.py	(original)
+++ pypy/trunk/pypy/module/_codecs/interp_codecs.py	Sun Jan 18 16:41:42 2009
@@ -149,6 +149,10 @@
         assert 0, "XXX, what to do here?"
 encode.unwrap_spec = [ObjSpace, W_Root, W_Root, str]
 
+def buffer_encode(space, s, errors='strict'):
+    return space.newtuple([space.wrap(s), space.wrap(len(s))])
+buffer_encode.unwrap_spec = [ObjSpace, 'bufferstr', str]
+
 def decode(space, w_obj, w_encoding=NoneNotWrapped, errors='strict'):
     """decode(obj, [encoding[,errors]]) -> object
 

Modified: pypy/trunk/pypy/module/_codecs/test/test_codecs.py
==============================================================================
--- pypy/trunk/pypy/module/_codecs/test/test_codecs.py	(original)
+++ pypy/trunk/pypy/module/_codecs/test/test_codecs.py	Sun Jan 18 16:41:42 2009
@@ -337,9 +337,18 @@
         for (i, line) in enumerate(reader):
             assert line == s[i]
 
+    def test_array(self):
+        import _codecs, array
+        _codecs.readbuffer_encode(array.array('c', 'spam')) == ('spam', 4)
+
+    def test_utf8sig(self):
+        import codecs
+        d = codecs.getincrementaldecoder("utf-8-sig")()
+        s = u"spam"
+        assert d.decode(s.encode("utf-8-sig")) == s
+
     def test_escape_decode_escaped_newline(self):
         import _codecs
         s = '\\\n'
         decoded = _codecs.unicode_escape_decode(s)[0]
         assert decoded == ''
-



More information about the Pypy-commit mailing list