[pypy-svn] r78844 - in pypy/branch/fast-forward/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Sun Nov 7 22:37:13 CET 2010
Author: afa
Date: Sun Nov 7 22:37:11 2010
New Revision: 78844
Added:
pypy/branch/fast-forward/pypy/module/cpyext/codecs.py (contents, props changed)
pypy/branch/fast-forward/pypy/module/cpyext/test/test_codecs.py (contents, props changed)
Modified:
pypy/branch/fast-forward/pypy/module/cpyext/__init__.py
Log:
Add PyCodec_IncrementalEncoder, PyCodec_IncrementalDecoder
Modified: pypy/branch/fast-forward/pypy/module/cpyext/__init__.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/cpyext/__init__.py (original)
+++ pypy/branch/fast-forward/pypy/module/cpyext/__init__.py Sun Nov 7 22:37:11 2010
@@ -70,6 +70,7 @@
import pypy.module.cpyext.funcobject
import pypy.module.cpyext.classobject
import pypy.module.cpyext.memoryobject
+import pypy.module.cpyext.codecs
# now that all rffi_platform.Struct types are registered, configure them
api.configure_types()
Added: pypy/branch/fast-forward/pypy/module/cpyext/codecs.py
==============================================================================
--- (empty file)
+++ pypy/branch/fast-forward/pypy/module/cpyext/codecs.py Sun Nov 7 22:37:11 2010
@@ -0,0 +1,22 @@
+from pypy.rpython.lltypesystem import rffi
+from pypy.module.cpyext.api import cpython_api, PyObject, CONST_STRING
+from pypy.module._codecs import interp_codecs
+
+ at cpython_api([CONST_STRING, CONST_STRING], PyObject)
+def PyCodec_IncrementalEncoder(space, encoding, errors):
+ w_codec = interp_codecs.lookup_codec(space, rffi.charp2str(encoding))
+ if errors:
+ w_errors = space.wrap(rffi.charp2str(errors))
+ return space.call_method(w_codec, "incrementalencoder", w_errors)
+ else:
+ return space.call_method(w_codec, "incrementalencoder")
+
+ at cpython_api([CONST_STRING, CONST_STRING], PyObject)
+def PyCodec_IncrementalDecoder(space, encoding, errors):
+ w_codec = interp_codecs.lookup_codec(space, rffi.charp2str(encoding))
+ if errors:
+ w_errors = space.wrap(rffi.charp2str(errors))
+ return space.call_method(w_codec, "incrementaldecoder", w_errors)
+ else:
+ return space.call_method(w_codec, "incrementaldecoder")
+
Added: pypy/branch/fast-forward/pypy/module/cpyext/test/test_codecs.py
==============================================================================
--- (empty file)
+++ pypy/branch/fast-forward/pypy/module/cpyext/test/test_codecs.py Sun Nov 7 22:37:11 2010
@@ -0,0 +1,14 @@
+# encoding: iso-8859-15
+from pypy.module.cpyext.test.test_api import BaseApiTest
+from pypy.rpython.lltypesystem import rffi, lltype
+
+class TestCodecs(BaseApiTest):
+ def test_incremental(self, space, api):
+ utf8 = rffi.str2charp('utf-8')
+ w_encoder = api.PyCodec_IncrementalEncoder(utf8, None)
+ w_encoded = space.call_method(w_encoder, 'encode', space.wrap(u'späm'))
+ w_decoder = api.PyCodec_IncrementalDecoder(utf8, None)
+ w_decoded = space.call_method(w_decoder, 'decode', w_encoded)
+ assert space.unwrap(w_decoded) == u'späm'
+ rffi.free_charp(utf8)
+
More information about the Pypy-commit
mailing list