home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_2359 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  2.3 KB  |  64 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os.path as os
  5. import fnmatch
  6. from pygments.formatters._mapping import FORMATTERS
  7. from pygments.plugin import find_plugin_formatters
  8. from pygments.util import ClassNotFound
  9. ns = globals()
  10. for fcls in FORMATTERS:
  11.     ns[fcls.__name__] = fcls
  12.  
  13. del fcls
  14. __all__ = [] + [ cls.__name__ for cls in FORMATTERS ]
  15. _formatter_alias_cache = { }
  16. _formatter_filename_cache = []
  17.  
  18. def _init_formatter_cache():
  19.     if _formatter_alias_cache:
  20.         return None
  21.     for cls in get_all_formatters():
  22.         for alias in cls.aliases:
  23.             _formatter_alias_cache[alias] = cls
  24.         
  25.         for fn in cls.filenames:
  26.             _formatter_filename_cache.append((fn, cls))
  27.         
  28.     
  29.  
  30.  
  31. def find_formatter_class(name):
  32.     _init_formatter_cache()
  33.     cls = _formatter_alias_cache.get(name, None)
  34.     return cls
  35.  
  36.  
  37. def get_formatter_by_name(name, **options):
  38.     _init_formatter_cache()
  39.     cls = _formatter_alias_cache.get(name, None)
  40.     if not cls:
  41.         raise ClassNotFound('No formatter found for name %r' % name)
  42.     cls
  43.     return cls(**options)
  44.  
  45.  
  46. def get_formatter_for_filename(fn, **options):
  47.     _init_formatter_cache()
  48.     fn = os.path.basename(fn)
  49.     for pattern, cls in _formatter_filename_cache:
  50.         if fnmatch.fnmatch(fn, pattern):
  51.             return cls(**options)
  52.     
  53.     raise ClassNotFound('No formatter found for file name %r' % fn)
  54.  
  55.  
  56. def get_all_formatters():
  57.     for formatter in FORMATTERS:
  58.         yield formatter
  59.     
  60.     for _, formatter in find_plugin_formatters():
  61.         yield formatter
  62.     
  63.  
  64.