4 'cn': ('gb2312', 'gbk', 'gb18030', 'hz'),
5 'tw': ('big5', 'cp950'),
7 'jp': ('cp932', 'shift_jis', 'euc_jp', 'euc_jisx0213', 'shift_jisx0213',
8 'euc_jis_2004', 'shift_jis_2004'),
9 'kr': ('cp949', 'euc_kr', 'johab'),
10 'iso2022': ('iso2022_jp', 'iso2022_jp_1', 'iso2022_jp_2',
11 'iso2022_jp_2004', 'iso2022_jp_3', 'iso2022_jp_ext',
15 TEMPLATE
= string
.Template("""\
17 # $encoding.py: Python Unicode Codec for $ENCODING
19 # Written by Hye-Shik Chang <perky@FreeBSD.org>
22 import _codecs_$owner, codecs
23 import _multibytecodec as mbc
25 codec = _codecs_$owner.getcodec('$encoding')
27 class Codec(codecs.Codec):
31 class IncrementalEncoder(mbc.MultibyteIncrementalEncoder,
32 codecs.IncrementalEncoder):
35 class IncrementalDecoder(mbc.MultibyteIncrementalDecoder,
36 codecs.IncrementalDecoder):
39 class StreamReader(Codec, mbc.MultibyteStreamReader, codecs.StreamReader):
42 class StreamWriter(Codec, mbc.MultibyteStreamWriter, codecs.StreamWriter):
46 return codecs.CodecInfo(
48 encode=Codec().encode,
49 decode=Codec().decode,
50 incrementalencoder=IncrementalEncoder,
51 incrementaldecoder=IncrementalDecoder,
52 streamreader=StreamReader,
53 streamwriter=StreamWriter,
57 def gencodecs(prefix
):
58 for loc
, encodings
in codecs
.iteritems():
60 code
= TEMPLATE
.substitute(ENCODING
=enc
.upper(),
63 codecpath
= os
.path
.join(prefix
, enc
+ '.py')
64 open(codecpath
, 'w').write(code
)
66 if __name__
== '__main__':
68 gencodecs(sys
.argv
[1])