22
22
.. _Pygments tip:
23
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-2015 by the Pygments team, see AUTHORS.
26
26
:license: BSD, see LICENSE for details.
27
27
"""
28
28
29
- __version__ = '1.6 '
29
+ __version__ = '2.1.3 '
30
30
__docformat__ = 'restructuredtext'
31
31
32
32
__all__ = ['lex' , 'format' , 'highlight' ]
@@ -43,15 +43,16 @@ def lex(code, lexer):
43
43
"""
44
44
try :
45
45
return lexer .get_tokens (code )
46
- except TypeError , err :
46
+ except TypeError as err :
47
47
if isinstance (err .args [0 ], str ) and \
48
- '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 ]):
49
50
raise TypeError ('lex() argument must be a lexer instance, '
50
51
'not a class' )
51
52
raise
52
53
53
54
54
- def format (tokens , formatter , outfile = None ):
55
+ def format (tokens , formatter , outfile = None ): # pylint: disable=redefined-builtin
55
56
"""
56
57
Format a tokenlist ``tokens`` with the formatter ``formatter``.
57
58
@@ -61,15 +62,15 @@ def format(tokens, formatter, outfile=None):
61
62
"""
62
63
try :
63
64
if not outfile :
64
- #print formatter, 'using', formatter.encoding
65
- realoutfile = formatter .encoding and BytesIO () or StringIO ()
65
+ realoutfile = getattr (formatter , 'encoding' , None ) and BytesIO () or StringIO ()
66
66
formatter .format (tokens , realoutfile )
67
67
return realoutfile .getvalue ()
68
68
else :
69
69
formatter .format (tokens , outfile )
70
- except TypeError , err :
70
+ except TypeError as err :
71
71
if isinstance (err .args [0 ], str ) and \
72
- '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 ]):
73
74
raise TypeError ('format() argument must be a formatter instance, '
74
75
'not a class' )
75
76
raise
@@ -86,6 +87,6 @@ def highlight(code, lexer, formatter, outfile=None):
86
87
return format (lex (code , lexer ), formatter , outfile )
87
88
88
89
89
- if __name__ == '__main__' :
90
+ if __name__ == '__main__' : # pragma: no cover
90
91
from pygments .cmdline import main
91
92
sys .exit (main (sys .argv ))
0 commit comments