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

Python code coverage for Tools/unicode/listcodecs.py

#countcontent
1n/a""" List all available codec modules.
2n/a
3n/a(c) Copyright 2005, Marc-Andre Lemburg (mal@lemburg.com).
4n/a
5n/a Licensed to PSF under a Contributor Agreement.
6n/a
7n/a"""
8n/a
9n/aimport os, codecs, encodings
10n/a
11n/a_debug = 0
12n/a
13n/adef listcodecs(dir):
14n/a names = []
15n/a for filename in os.listdir(dir):
16n/a if filename[-3:] != '.py':
17n/a continue
18n/a name = filename[:-3]
19n/a # Check whether we've found a true codec
20n/a try:
21n/a codecs.lookup(name)
22n/a except LookupError:
23n/a # Codec not found
24n/a continue
25n/a except Exception as reason:
26n/a # Probably an error from importing the codec; still it's
27n/a # a valid code name
28n/a if _debug:
29n/a print('* problem importing codec %r: %s' % \
30n/a (name, reason))
31n/a names.append(name)
32n/a return names
33n/a
34n/a
35n/aif __name__ == '__main__':
36n/a names = listcodecs(encodings.__path__[0])
37n/a names.sort()
38n/a print('all_codecs = [')
39n/a for name in names:
40n/a print(' %r,' % name)
41n/a print(']')