summaryrefslogtreecommitdiff
path: root/pygments/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'pygments/__init__.py')
-rw-r--r--pygments/__init__.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/pygments/__init__.py b/pygments/__init__.py
index 2bfd8ba5..1ce34b2a 100644
--- a/pygments/__init__.py
+++ b/pygments/__init__.py
@@ -22,11 +22,11 @@
.. _Pygments tip:
http://bitbucket.org/birkenfeld/pygments-main/get/tip.zip#egg=Pygments-dev
- :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
+ :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
-__version__ = '1.6'
+__version__ = '2.1a0'
__docformat__ = 'restructuredtext'
__all__ = ['lex', 'format', 'highlight']
@@ -43,9 +43,10 @@ def lex(code, lexer):
"""
try:
return lexer.get_tokens(code)
- except TypeError, err:
+ except TypeError as err:
if isinstance(err.args[0], str) and \
- 'unbound method get_tokens' in err.args[0]:
+ ('unbound method get_tokens' in err.args[0] or
+ 'missing 1 required positional argument' in err.args[0]):
raise TypeError('lex() argument must be a lexer instance, '
'not a class')
raise
@@ -61,15 +62,15 @@ def format(tokens, formatter, outfile=None):
"""
try:
if not outfile:
- #print formatter, 'using', formatter.encoding
- realoutfile = formatter.encoding and BytesIO() or StringIO()
+ realoutfile = getattr(formatter, 'encoding', None) and BytesIO() or StringIO()
formatter.format(tokens, realoutfile)
return realoutfile.getvalue()
else:
formatter.format(tokens, outfile)
- except TypeError, err:
+ except TypeError as err:
if isinstance(err.args[0], str) and \
- 'unbound method format' in err.args[0]:
+ ('unbound method format' in err.args[0] or
+ 'missing 1 required positional argument' in err.args[0]):
raise TypeError('format() argument must be a formatter instance, '
'not a class')
raise
@@ -86,6 +87,6 @@ def highlight(code, lexer, formatter, outfile=None):
return format(lex(code, lexer), formatter, outfile)
-if __name__ == '__main__':
+if __name__ == '__main__': # pragma: no cover
from pygments.cmdline import main
sys.exit(main(sys.argv))