Remove obsolete warning filters in regrtest.py (from issue #7092 -- patch by
[python.git] / Tools / unicode / gencjkcodecs.py
blob975c19cb8040b33cc07640ac8d2e4e24e15b5a3c
1 import os, string
3 codecs = {
4 'cn': ('gb2312', 'gbk', 'gb18030', 'hz'),
5 'tw': ('big5', 'cp950'),
6 'hk': ('big5hkscs',),
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',
12 'iso2022_kr'),
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):
28 encode = codec.encode
29 decode = codec.decode
31 class IncrementalEncoder(mbc.MultibyteIncrementalEncoder,
32 codecs.IncrementalEncoder):
33 codec = codec
35 class IncrementalDecoder(mbc.MultibyteIncrementalDecoder,
36 codecs.IncrementalDecoder):
37 codec = codec
39 class StreamReader(Codec, mbc.MultibyteStreamReader, codecs.StreamReader):
40 codec = codec
42 class StreamWriter(Codec, mbc.MultibyteStreamWriter, codecs.StreamWriter):
43 codec = codec
45 def getregentry():
46 return codecs.CodecInfo(
47 name='$encoding',
48 encode=Codec().encode,
49 decode=Codec().decode,
50 incrementalencoder=IncrementalEncoder,
51 incrementaldecoder=IncrementalDecoder,
52 streamreader=StreamReader,
53 streamwriter=StreamWriter,
55 """)
57 def gencodecs(prefix):
58 for loc, encodings in codecs.iteritems():
59 for enc in encodings:
60 code = TEMPLATE.substitute(ENCODING=enc.upper(),
61 encoding=enc.lower(),
62 owner=loc)
63 codecpath = os.path.join(prefix, enc + '.py')
64 open(codecpath, 'w').write(code)
66 if __name__ == '__main__':
67 import sys
68 gencodecs(sys.argv[1])