Skip to content

Commit 03af0b0

Browse files
committed
Original pygments 2.2.0
1 parent ead3350 commit 03af0b0

File tree

205 files changed

+65315
-28109
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+65315
-28109
lines changed

__init__.py

+16-17
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,35 @@
2222
.. _Pygments tip:
2323
http://bitbucket.org/birkenfeld/pygments-main/get/tip.zip#egg=Pygments-dev
2424
25-
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
25+
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
2626
:license: BSD, see LICENSE for details.
2727
"""
28+
import sys
29+
30+
from pygments.util import StringIO, BytesIO
2831

29-
__version__ = '1.6'
32+
__version__ = '2.2.0'
3033
__docformat__ = 'restructuredtext'
3134

3235
__all__ = ['lex', 'format', 'highlight']
3336

3437

35-
import sys
36-
37-
from pygments.util import StringIO, BytesIO
38-
39-
4038
def lex(code, lexer):
4139
"""
4240
Lex ``code`` with ``lexer`` and return an iterable of tokens.
4341
"""
4442
try:
4543
return lexer.get_tokens(code)
46-
except TypeError, err:
47-
if isinstance(err.args[0], str) and \
48-
'unbound method get_tokens' in err.args[0]:
44+
except TypeError as err:
45+
if (isinstance(err.args[0], str) and
46+
('unbound method get_tokens' in err.args[0] or
47+
'missing 1 required positional argument' in err.args[0])):
4948
raise TypeError('lex() argument must be a lexer instance, '
5049
'not a class')
5150
raise
5251

5352

54-
def format(tokens, formatter, outfile=None):
53+
def format(tokens, formatter, outfile=None): # pylint: disable=redefined-builtin
5554
"""
5655
Format a tokenlist ``tokens`` with the formatter ``formatter``.
5756
@@ -61,15 +60,15 @@ def format(tokens, formatter, outfile=None):
6160
"""
6261
try:
6362
if not outfile:
64-
#print formatter, 'using', formatter.encoding
65-
realoutfile = formatter.encoding and BytesIO() or StringIO()
63+
realoutfile = getattr(formatter, 'encoding', None) and BytesIO() or StringIO()
6664
formatter.format(tokens, realoutfile)
6765
return realoutfile.getvalue()
6866
else:
6967
formatter.format(tokens, outfile)
70-
except TypeError, err:
71-
if isinstance(err.args[0], str) and \
72-
'unbound method format' in err.args[0]:
68+
except TypeError as err:
69+
if (isinstance(err.args[0], str) and
70+
('unbound method format' in err.args[0] or
71+
'missing 1 required positional argument' in err.args[0])):
7372
raise TypeError('format() argument must be a formatter instance, '
7473
'not a class')
7574
raise
@@ -86,6 +85,6 @@ def highlight(code, lexer, formatter, outfile=None):
8685
return format(lex(code, lexer), formatter, outfile)
8786

8887

89-
if __name__ == '__main__':
88+
if __name__ == '__main__': # pragma: no cover
9089
from pygments.cmdline import main
9190
sys.exit(main(sys.argv))

0 commit comments

Comments
 (0)