annotate Tools/unicode/listcodecs.py @ 58689:514b56efd89a 3.1

Merged revisions 77962 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r77962 | r.david.murray | 2010-02-04 11:41:57 -0500 (Thu, 04 Feb 2010) | 17 lines Merged revisions 77943,77959-77960 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77943 | r.david.murray | 2010-02-03 08:36:23 -0500 (Wed, 03 Feb 2010) | 2 lines Explicitly mention the default value for formatdate's usegmt parameter. ........ r77959 | nick.coghlan | 2010-02-04 07:43:58 -0500 (Thu, 04 Feb 2010) | 1 line Issue 6760: Clarify args handling for subprocess.Popen. Patch by Chris Rebert ........ r77960 | r.david.murray | 2010-02-04 11:33:31 -0500 (Thu, 04 Feb 2010) | 2 lines Add Chris Rebert to ACKS for issue 6760 Popen doc improvements. ........ ................
author R. David Murray <rdmurray@bitdance.com>
date Thu, 04 Feb 2010 16:44:31 +0000
parents 46625e6122e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35761
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
1 """ List all available codec modules.
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
2
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
3 (c) Copyright 2005, Marc-Andre Lemburg (mal@lemburg.com).
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
4
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
5 Licensed to PSF under a Contributor Agreement.
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
6
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
7 """
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
8
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
9 import os, codecs, encodings
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
10
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
11 _debug = 0
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
12
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
13 def listcodecs(dir):
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
14 names = []
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
15 for filename in os.listdir(dir):
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
16 if filename[-3:] != '.py':
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
17 continue
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
18 name = filename[:-3]
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
19 # Check whether we've found a true codec
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
20 try:
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
21 codecs.lookup(name)
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
22 except LookupError:
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
23 # Codec not found
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
24 continue
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 35761
diff changeset
25 except Exception as reason:
35761
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
26 # Probably an error from importing the codec; still it's
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
27 # a valid code name
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
28 if _debug:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 40587
diff changeset
29 print('* problem importing codec %r: %s' % \
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 40587
diff changeset
30 (name, reason))
35761
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
31 names.append(name)
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
32 return names
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
33
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
34
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
35 if __name__ == '__main__':
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
36 names = listcodecs(encodings.__path__[0])
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
37 names.sort()
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 40587
diff changeset
38 print('all_codecs = [')
35761
7a5ac203154a Add two new tools to compare codecs and show differences and to
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
39 for name in names:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 40587
diff changeset
40 print(' %r,' % name)
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 40587
diff changeset
41 print(']')