summaryrefslogtreecommitdiffstats
path: root/Lib/encodings
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/encodings')
-rw-r--r--Lib/encodings/__init__.py6
-rw-r--r--Lib/encodings/iconv_codec.py34
2 files changed, 40 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