ยปCore Development>Code coverage>Tools/unicode/gencjkcodecs.py

Python code coverage for Tools/unicode/gencjkcodecs.py

#countcontent
1n/aimport os, string
2n/a
3n/acodecs = {
4n/a 'cn': ('gb2312', 'gbk', 'gb18030', 'hz'),
5n/a 'tw': ('big5', 'cp950'),
6n/a 'hk': ('big5hkscs',),
7n/a 'jp': ('cp932', 'shift_jis', 'euc_jp', 'euc_jisx0213', 'shift_jisx0213',
8n/a 'euc_jis_2004', 'shift_jis_2004'),
9n/a 'kr': ('cp949', 'euc_kr', 'johab'),
10n/a 'iso2022': ('iso2022_jp', 'iso2022_jp_1', 'iso2022_jp_2',
11n/a 'iso2022_jp_2004', 'iso2022_jp_3', 'iso2022_jp_ext',
12n/a 'iso2022_kr'),
13n/a}
14n/a
15n/aTEMPLATE = string.Template("""\
16n/a#
17n/a# $encoding.py: Python Unicode Codec for $ENCODING
18n/a#
19n/a# Written by Hye-Shik Chang <perky@FreeBSD.org>
20n/a#
21n/a
22n/aimport _codecs_$owner, codecs
23n/aimport _multibytecodec as mbc
24n/a
25n/acodec = _codecs_$owner.getcodec('$encoding')
26n/a
27n/aclass Codec(codecs.Codec):
28n/a encode = codec.encode
29n/a decode = codec.decode
30n/a
31n/aclass IncrementalEncoder(mbc.MultibyteIncrementalEncoder,
32n/a codecs.IncrementalEncoder):
33n/a codec = codec
34n/a
35n/aclass IncrementalDecoder(mbc.MultibyteIncrementalDecoder,
36n/a codecs.IncrementalDecoder):
37n/a codec = codec
38n/a
39n/aclass StreamReader(Codec, mbc.MultibyteStreamReader, codecs.StreamReader):
40n/a codec = codec
41n/a
42n/aclass StreamWriter(Codec, mbc.MultibyteStreamWriter, codecs.StreamWriter):
43n/a codec = codec
44n/a
45n/adef getregentry():
46n/a return codecs.CodecInfo(
47n/a name='$encoding',
48n/a encode=Codec().encode,
49n/a decode=Codec().decode,
50n/a incrementalencoder=IncrementalEncoder,
51n/a incrementaldecoder=IncrementalDecoder,
52n/a streamreader=StreamReader,
53n/a streamwriter=StreamWriter,
54n/a )
55n/a""")
56n/a
57n/adef gencodecs(prefix):
58n/a for loc, encodings in codecs.items():
59n/a for enc in encodings:
60n/a code = TEMPLATE.substitute(ENCODING=enc.upper(),
61n/a encoding=enc.lower(),
62n/a owner=loc)
63n/a codecpath = os.path.join(prefix, enc + '.py')
64n/a open(codecpath, 'w').write(code)
65n/a
66n/aif __name__ == '__main__':
67n/a import sys
68n/a gencodecs(sys.argv[1])