ThirdParty/Pygments/pygments/__init__.py

changeset 4172
4f20dba37ab6
parent 3145
a9de05d4a22f
child 4697
c2e9bf425554
equal deleted inserted replaced
4170:8bc578136279 4172:4f20dba37ab6
20 The `Pygments tip`_ is installable with ``easy_install Pygments==dev``. 20 The `Pygments tip`_ is installable with ``easy_install Pygments==dev``.
21 21
22 .. _Pygments tip: 22 .. _Pygments tip:
23 http://bitbucket.org/birkenfeld/pygments-main/get/tip.zip#egg=Pygments-dev 23 http://bitbucket.org/birkenfeld/pygments-main/get/tip.zip#egg=Pygments-dev
24 24
25 :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. 25 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
26 :license: BSD, see LICENSE for details. 26 :license: BSD, see LICENSE for details.
27 """ 27 """
28 28
29 from __future__ import unicode_literals 29 __version__ = '2.0.2'
30
31 __version__ = '1.6'
32 __docformat__ = 'restructuredtext' 30 __docformat__ = 'restructuredtext'
33 31
34 __all__ = ['lex', 'format', 'highlight'] 32 __all__ = ['lex', 'format', 'highlight']
35 33
36 34
45 """ 43 """
46 try: 44 try:
47 return lexer.get_tokens(code) 45 return lexer.get_tokens(code)
48 except TypeError as err: 46 except TypeError as err:
49 if isinstance(err.args[0], str) and \ 47 if isinstance(err.args[0], str) and \
50 'unbound method get_tokens' in err.args[0]: 48 ('unbound method get_tokens' in err.args[0] or
49 'missing 1 required positional argument' in err.args[0]):
51 raise TypeError('lex() argument must be a lexer instance, ' 50 raise TypeError('lex() argument must be a lexer instance, '
52 'not a class') 51 'not a class')
53 raise 52 raise
54 53
55 54
61 with a ``write`` method), the result will be written to it, otherwise 60 with a ``write`` method), the result will be written to it, otherwise
62 it is returned as a string. 61 it is returned as a string.
63 """ 62 """
64 try: 63 try:
65 if not outfile: 64 if not outfile:
66 #print formatter, 'using', formatter.encoding 65 realoutfile = getattr(formatter, 'encoding', None) and BytesIO() or StringIO()
67 realoutfile = formatter.encoding and BytesIO() or StringIO()
68 formatter.format(tokens, realoutfile) 66 formatter.format(tokens, realoutfile)
69 return realoutfile.getvalue() 67 return realoutfile.getvalue()
70 else: 68 else:
71 formatter.format(tokens, outfile) 69 formatter.format(tokens, outfile)
72 except TypeError as err: 70 except TypeError as err:
73 if isinstance(err.args[0], str) and \ 71 if isinstance(err.args[0], str) and \
74 'unbound method format' in err.args[0]: 72 ('unbound method format' in err.args[0] or
73 'missing 1 required positional argument' in err.args[0]):
75 raise TypeError('format() argument must be a formatter instance, ' 74 raise TypeError('format() argument must be a formatter instance, '
76 'not a class') 75 'not a class')
77 raise 76 raise
78 77
79 78
86 it is returned as a string. 85 it is returned as a string.
87 """ 86 """
88 return format(lex(code, lexer), formatter, outfile) 87 return format(lex(code, lexer), formatter, outfile)
89 88
90 89
91 if __name__ == '__main__': 90 if __name__ == '__main__': # pragma: no cover
92 from pygments.cmdline import main 91 from pygments.cmdline import main
93 sys.exit(main(sys.argv)) 92 sys.exit(main(sys.argv))

eric ide

mercurial