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-2015 by the Pygments team, see AUTHORS. |
25 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. |
26 :license: BSD, see LICENSE for details. |
26 :license: BSD, see LICENSE for details. |
27 """ |
27 """ |
|
28 import sys |
28 |
29 |
29 __version__ = '2.1.3' |
30 from pygments.util import StringIO, BytesIO |
|
31 |
|
32 __version__ = '2.2.0' |
30 __docformat__ = 'restructuredtext' |
33 __docformat__ = 'restructuredtext' |
31 |
34 |
32 __all__ = ['lex', 'format', 'highlight'] |
35 __all__ = ['lex', 'format', 'highlight'] |
33 |
|
34 |
|
35 import sys |
|
36 |
|
37 from pygments.util import StringIO, BytesIO |
|
38 |
36 |
39 |
37 |
40 def lex(code, lexer): |
38 def lex(code, lexer): |
41 """ |
39 """ |
42 Lex ``code`` with ``lexer`` and return an iterable of tokens. |
40 Lex ``code`` with ``lexer`` and return an iterable of tokens. |
43 """ |
41 """ |
44 try: |
42 try: |
45 return lexer.get_tokens(code) |
43 return lexer.get_tokens(code) |
46 except TypeError as err: |
44 except TypeError as err: |
47 if isinstance(err.args[0], str) and \ |
45 if (isinstance(err.args[0], str) and |
48 ('unbound method get_tokens' in err.args[0] or |
46 ('unbound method get_tokens' in err.args[0] or |
49 'missing 1 required positional argument' in err.args[0]): |
47 'missing 1 required positional argument' in err.args[0])): |
50 raise TypeError('lex() argument must be a lexer instance, ' |
48 raise TypeError('lex() argument must be a lexer instance, ' |
51 'not a class') |
49 'not a class') |
52 raise |
50 raise |
53 |
51 |
54 |
52 |
66 formatter.format(tokens, realoutfile) |
64 formatter.format(tokens, realoutfile) |
67 return realoutfile.getvalue() |
65 return realoutfile.getvalue() |
68 else: |
66 else: |
69 formatter.format(tokens, outfile) |
67 formatter.format(tokens, outfile) |
70 except TypeError as err: |
68 except TypeError as err: |
71 if isinstance(err.args[0], str) and \ |
69 if (isinstance(err.args[0], str) and |
72 ('unbound method format' in err.args[0] or |
70 ('unbound method format' in err.args[0] or |
73 'missing 1 required positional argument' in err.args[0]): |
71 'missing 1 required positional argument' in err.args[0])): |
74 raise TypeError('format() argument must be a formatter instance, ' |
72 raise TypeError('format() argument must be a formatter instance, ' |
75 'not a class') |
73 'not a class') |
76 raise |
74 raise |
77 |
75 |
78 |
76 |