ThirdParty/Pygments/pygments/__init__.py

changeset 12
1d8dd9706f46
parent 0
de9c2efb9d02
child 684
2f29a0b6e1c7
equal deleted inserted replaced
11:b0996e4a289e 12:1d8dd9706f46
23 23
24 :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS. 24 :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS.
25 :license: BSD, see LICENSE for details. 25 :license: BSD, see LICENSE for details.
26 """ 26 """
27 27
28 __version__ = '1.1' 28 __version__ = '1.1.1'
29 __docformat__ = 'restructuredtext' 29 __docformat__ = 'restructuredtext'
30 30
31 __all__ = ['lex', 'format', 'highlight'] 31 __all__ = ['lex', 'format', 'highlight']
32 32
33 33
40 """ 40 """
41 Lex ``code`` with ``lexer`` and return an iterable of tokens. 41 Lex ``code`` with ``lexer`` and return an iterable of tokens.
42 """ 42 """
43 try: 43 try:
44 return lexer.get_tokens(code) 44 return lexer.get_tokens(code)
45 except TypeError, err: 45 except TypeError as err:
46 if isinstance(err.args[0], str) and \ 46 if isinstance(err.args[0], str) and \
47 'unbound method get_tokens' in err.args[0]: 47 'unbound method get_tokens' in err.args[0]:
48 raise TypeError('lex() argument must be a lexer instance, ' 48 raise TypeError('lex() argument must be a lexer instance, '
49 'not a class') 49 'not a class')
50 raise 50 raise
64 realoutfile = formatter.encoding and BytesIO() or StringIO() 64 realoutfile = formatter.encoding and BytesIO() or StringIO()
65 formatter.format(tokens, realoutfile) 65 formatter.format(tokens, realoutfile)
66 return realoutfile.getvalue() 66 return realoutfile.getvalue()
67 else: 67 else:
68 formatter.format(tokens, outfile) 68 formatter.format(tokens, outfile)
69 except TypeError, err: 69 except TypeError as err:
70 if isinstance(err.args[0], str) and \ 70 if isinstance(err.args[0], str) and \
71 'unbound method format' in err.args[0]: 71 'unbound method format' in err.args[0]:
72 raise TypeError('format() argument must be a formatter instance, ' 72 raise TypeError('format() argument must be a formatter instance, '
73 'not a class') 73 'not a class')
74 raise 74 raise

eric ide

mercurial