Author: Armin Rigo <[email protected]>
Branch:
Changeset: r44054:c5c360ae4de7
Date: 2011-05-10 16:21 +0200
http://bitbucket.org/pypy/pypy/changeset/c5c360ae4de7/
Log: Write a bit more of the app-level interface. Untested so far.
diff --git a/lib_pypy/_codecs_cn.py b/lib_pypy/_codecs_cn.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/_codecs_cn.py
@@ -0,0 +1,7 @@
+# this getcodec() function supports any multibyte codec, although
+# for compatibility with CPython it should only be used for the
+# codecs from this module, i.e.:
+#
+# 'gb2312', 'gbk', 'gb18030', 'hz'
+
+from _multibytecodec import __getcodec as getcodec
diff --git a/lib_pypy/_codecs_hk.py b/lib_pypy/_codecs_hk.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/_codecs_hk.py
@@ -0,0 +1,7 @@
+# this getcodec() function supports any multibyte codec, although
+# for compatibility with CPython it should only be used for the
+# codecs from this module, i.e.:
+#
+# 'big5hkscs'
+
+from _multibytecodec import __getcodec as getcodec
diff --git a/lib_pypy/_codecs_iso2022.py b/lib_pypy/_codecs_iso2022.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/_codecs_iso2022.py
@@ -0,0 +1,8 @@
+# this getcodec() function supports any multibyte codec, although
+# for compatibility with CPython it should only be used for the
+# codecs from this module, i.e.:
+#
+# 'iso2022_kr', 'iso2022_jp', 'iso2022_jp_1', 'iso2022_jp_2',
+# 'iso2022_jp_2004', 'iso2022_jp_3', 'iso2022_jp_ext'
+
+from _multibytecodec import __getcodec as getcodec
diff --git a/lib_pypy/_codecs_jp.py b/lib_pypy/_codecs_jp.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/_codecs_jp.py
@@ -0,0 +1,8 @@
+# this getcodec() function supports any multibyte codec, although
+# for compatibility with CPython it should only be used for the
+# codecs from this module, i.e.:
+#
+# 'shift_jis', 'cp932', 'euc_jp', 'shift_jis_2004',
+# 'euc_jis_2004', 'euc_jisx0213', 'shift_jisx0213'
+
+from _multibytecodec import __getcodec as getcodec
diff --git a/lib_pypy/_codecs_kr.py b/lib_pypy/_codecs_kr.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/_codecs_kr.py
@@ -0,0 +1,7 @@
+# this getcodec() function supports any multibyte codec, although
+# for compatibility with CPython it should only be used for the
+# codecs from this module, i.e.:
+#
+# 'euc_kr', 'cp949', 'johab'
+
+from _multibytecodec import __getcodec as getcodec
diff --git a/lib_pypy/_codecs_tw.py b/lib_pypy/_codecs_tw.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/_codecs_tw.py
@@ -0,0 +1,7 @@
+# this getcodec() function supports any multibyte codec, although
+# for compatibility with CPython it should only be used for the
+# codecs from this module, i.e.:
+#
+# 'big5', 'cp950'
+
+from _multibytecodec import __getcodec as getcodec
diff --git a/pypy/module/_multibytecodec/__init__.py
b/pypy/module/_multibytecodec/__init__.py
--- a/pypy/module/_multibytecodec/__init__.py
+++ b/pypy/module/_multibytecodec/__init__.py
@@ -4,7 +4,18 @@
class Module(MixedModule):
interpleveldefs = {
+ # for compatibility this name is obscured, and should be called
+ # via the _codecs_*.py modules written in lib_pypy.
+ '__getcodec': 'interp_multibytecodec.getcodec',
}
appleveldefs = {
+ 'MultibyteIncrementalEncoder':
+ 'app_multibytecodec.MultibyteIncrementalEncoder',
+ 'MultibyteIncrementalDecoder':
+ 'app_multibytecodec.MultibyteIncrementalDecoder',
+ 'MultibyteStreamReader':
+ 'app_multibytecodec.MultibyteStreamReader',
+ 'MultibyteStreamWriter':
+ 'app_multibytecodec.MultibyteStreamWriter',
}
diff --git a/pypy/module/_multibytecodec/app_multibytecodec.py
b/pypy/module/_multibytecodec/app_multibytecodec.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_multibytecodec/app_multibytecodec.py
@@ -0,0 +1,33 @@
+#
+# These classes are not supported so far.
+#
+# My theory is that they are not widely used on CPython either, because
+# I found two bugs just by looking at their .c source: they always call
+# encreset() after a piece of data, even though I think it's wrong ---
+# it should be called only once at the end; and mbiencoder_reset() calls
+# decreset() instead of encreset().
+#
+
+class MultibyteIncrementalEncoder(object):
+ def __init__(self, *args, **kwds):
+ raise NotImplementedError(
+ "MultibyteIncrementalEncoder not supported; "
+ "see pypy/module/_multibytecodec/app_multibytecodec.py")
+
+class MultibyteIncrementalDecoder(object):
+ def __init__(self, *args, **kwds):
+ raise NotImplementedError(
+ "MultibyteIncrementalDecoder not supported; "
+ "see pypy/module/_multibytecodec/app_multibytecodec.py")
+
+class MultibyteStreamReader(object):
+ def __init__(self, *args, **kwds):
+ raise NotImplementedError(
+ "MultibyteStreamReader not supported; "
+ "see pypy/module/_multibytecodec/app_multibytecodec.py")
+
+class MultibyteStreamWriter(object):
+ def __init__(self, *args, **kwds):
+ raise NotImplementedError(
+ "MultibyteStreamWriter not supported; "
+ "see pypy/module/_multibytecodec/app_multibytecodec.py")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit