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-2014 by the Pygments team, see AUTHORS. |
25 :copyright: Copyright 2006-2015 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 __version__ = '2.0.2' |
29 __version__ = '2.1' |
30 __docformat__ = 'restructuredtext' |
30 __docformat__ = 'restructuredtext' |
31 |
31 |
32 __all__ = ['lex', 'format', 'highlight'] |
32 __all__ = ['lex', 'format', 'highlight'] |
33 |
33 |
34 |
34 |
44 try: |
44 try: |
45 return lexer.get_tokens(code) |
45 return lexer.get_tokens(code) |
46 except TypeError as err: |
46 except TypeError as err: |
47 if isinstance(err.args[0], str) and \ |
47 if isinstance(err.args[0], str) and \ |
48 ('unbound method get_tokens' in err.args[0] or |
48 ('unbound method get_tokens' in err.args[0] or |
49 'missing 1 required positional argument' in err.args[0]): |
49 'missing 1 required positional argument' in err.args[0]): |
50 raise TypeError('lex() argument must be a lexer instance, ' |
50 raise TypeError('lex() argument must be a lexer instance, ' |
51 'not a class') |
51 'not a class') |
52 raise |
52 raise |
53 |
53 |
54 |
54 |
55 def format(tokens, formatter, outfile=None): |
55 def format(tokens, formatter, outfile=None): # pylint: disable=redefined-builtin |
56 """ |
56 """ |
57 Format a tokenlist ``tokens`` with the formatter ``formatter``. |
57 Format a tokenlist ``tokens`` with the formatter ``formatter``. |
58 |
58 |
59 If ``outfile`` is given and a valid file object (an object |
59 If ``outfile`` is given and a valid file object (an object |
60 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 |
68 else: |
68 else: |
69 formatter.format(tokens, outfile) |
69 formatter.format(tokens, outfile) |
70 except TypeError as err: |
70 except TypeError as err: |
71 if isinstance(err.args[0], str) and \ |
71 if isinstance(err.args[0], str) and \ |
72 ('unbound method format' in err.args[0] or |
72 ('unbound method format' in err.args[0] or |
73 'missing 1 required positional argument' in err.args[0]): |
73 'missing 1 required positional argument' in err.args[0]): |
74 raise TypeError('format() argument must be a formatter instance, ' |
74 raise TypeError('format() argument must be a formatter instance, ' |
75 'not a class') |
75 'not a class') |
76 raise |
76 raise |
77 |
77 |
78 |
78 |