diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2003-01-26 11:30:36 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2003-01-26 11:30:36 (GMT) |
commit | 9789aefa616c14599af600bdea925299517da730 (patch) | |
tree | 801c3f6ed8aafb3aafeae179737c9aea5e185bb9 /Lib | |
parent | afef4eefa8b07287abe1c59b9ef918e91386f454 (diff) | |
download | cpython-9789aefa616c14599af600bdea925299517da730.zip cpython-9789aefa616c14599af600bdea925299517da730.tar.gz cpython-9789aefa616c14599af600bdea925299517da730.tar.bz2 |
Patch #670715: Universal Unicode Codec for POSIX iconv.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/encodings/__init__.py | 6 | ||||
-rw-r--r-- | Lib/encodings/iconv_codec.py | 34 | ||||
-rwxr-xr-x | Lib/test/regrtest.py | 3 |
3 files changed, 43 insertions, 0 deletions
diff --git a/Lib/encodings/__init__.py b/Lib/encodings/__init__.py index 66bea5c..5e4167b 100644 --- a/Lib/encodings/__init__.py +++ b/Lib/encodings/__init__.py @@ -120,3 +120,9 @@ def search_function(encoding): # Register the search_function in the Python codec registry codecs.register(search_function) + +# Register iconv_codec lookup function if available +try: + import iconv_codec +except ImportError: + pass diff --git a/Lib/encodings/iconv_codec.py b/Lib/encodings/iconv_codec.py new file mode 100644 index 0000000..8bd0c3f --- /dev/null +++ b/Lib/encodings/iconv_codec.py @@ -0,0 +1,34 @@ +""" Python 'iconv' Codec + + +Written by Hye-Shik Chang (perky@FreeBSD.org). + +Copyright(c) Python Software Foundation, All Rights Reserved. NO WARRANTY. + +""" + +import _iconv_codec +import codecs + +def lookup(enc): + class IconvCodec(_iconv_codec.iconvcodec, codecs.Codec): + encoding = enc + + try: + c = IconvCodec() + + class IconvStreamReader(IconvCodec, codecs.StreamReader): + __init__ = codecs.StreamReader.__init__ + class IconvStreamWriter(IconvCodec, codecs.StreamWriter): + __init__ = codecs.StreamWriter.__init__ + + return ( + c.encode, c.decode, + IconvStreamReader, IconvStreamWriter + ) + except ValueError: + return None + +codecs.register(lookup) + +# ex: ts=8 sts=4 et diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 433c939..c433c8b 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -556,6 +556,7 @@ _expectations = { test_gdbm test_gl test_grp + test_iconv_codec test_imgfile test_largefile test_linuxaudiodev @@ -611,6 +612,7 @@ _expectations = { test_fork1 test_gl test_grp + test_iconv_codec test_imgfile test_largefile test_linuxaudiodev @@ -898,6 +900,7 @@ _expectations = { test_dl test_email_codecs test_gl + test_iconv_codec test_imgfile test_largefile test_linuxaudiodev |