Staging
v0.5.1
https://github.com/python/cpython
Revision 76c71ed9c5bb3e3e85a8295c8a137579bba977ec authored by Mark Dickinson on 20 December 2009, 20:38:25 UTC, committed by Mark Dickinson on 20 December 2009, 20:38:25 UTC
................
  r76950 | mark.dickinson | 2009-12-20 20:37:56 +0000 (Sun, 20 Dec 2009) | 10 lines

  Merged revisions 76948 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r76948 | mark.dickinson | 2009-12-20 20:34:44 +0000 (Sun, 20 Dec 2009) | 3 lines

    Issue #7554:  Various fixups in test_cmath.py:  remove code duplication,
    use new-style formatting.  Thanks Florent Xicluna for the patch.
  ........
................
1 parent e0b4590
Raw File
Tip revision: 76c71ed9c5bb3e3e85a8295c8a137579bba977ec authored by Mark Dickinson on 20 December 2009, 20:38:25 UTC
Blocked revisions 76950 via svnmerge
Tip revision: 76c71ed
listcodecs.py
""" List all available codec modules.

(c) Copyright 2005, Marc-Andre Lemburg (mal@lemburg.com).

    Licensed to PSF under a Contributor Agreement.

"""

import os, codecs, encodings

_debug = 0

def listcodecs(dir):
    names = []
    for filename in os.listdir(dir):
        if filename[-3:] != '.py':
            continue
        name = filename[:-3]
        # Check whether we've found a true codec
        try:
            codecs.lookup(name)
        except LookupError:
            # Codec not found
            continue
        except Exception as reason:
            # Probably an error from importing the codec; still it's
            # a valid code name
            if _debug:
                print('* problem importing codec %r: %s' % \
                      (name, reason))
        names.append(name)
    return names


if __name__ == '__main__':
    names = listcodecs(encodings.__path__[0])
    names.sort()
    print('all_codecs = [')
    for name in names:
        print('    %r,' % name)
    print(']')
back to top