summaryrefslogtreecommitdiffstats
path: root/Lib/encodings/iconv_codec.py
blob: 8bd0c3fafc1cb114f77b53d421f44ce5ef3221d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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