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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __version__ = '1.3.1'
  5. __docformat__ = 'restructuredtext'
  6. __all__ = [
  7.     'lex',
  8.     'format',
  9.     'highlight']
  10. import sys
  11. from pygments.util import StringIO, BytesIO
  12.  
  13. def lex(code, lexer):
  14.     
  15.     try:
  16.         return lexer.get_tokens(code)
  17.     except TypeError:
  18.         err = None
  19.         if isinstance(err.args[0], str) and 'unbound method get_tokens' in err.args[0]:
  20.             raise TypeError('lex() argument must be a lexer instance, not a class')
  21.         'unbound method get_tokens' in err.args[0]
  22.         raise 
  23.  
  24.  
  25.  
  26. def format(tokens, formatter, outfile = None):
  27.     
  28.     try:
  29.         if not outfile:
  30.             if not formatter.encoding or BytesIO():
  31.                 pass
  32.             realoutfile = StringIO()
  33.             formatter.format(tokens, realoutfile)
  34.             return realoutfile.getvalue()
  35.         formatter.format(tokens, outfile)
  36.     except TypeError:
  37.         err = None
  38.         if isinstance(err.args[0], str) and 'unbound method format' in err.args[0]:
  39.             raise TypeError('format() argument must be a formatter instance, not a class')
  40.         'unbound method format' in err.args[0]
  41.         raise 
  42.  
  43.  
  44.  
  45. def highlight(code, lexer, formatter, outfile = None):
  46.     return format(lex(code, lexer), formatter, outfile)
  47.  
  48. if __name__ == '__main__':
  49.     from pygments.cmdline import main
  50.     sys.exit(main(sys.argv))
  51.  
  52.