summaryrefslogtreecommitdiff
path: root/pygments/__init__.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-11-11 18:38:10 +0100
committerGeorg Brandl <georg@python.org>2014-11-11 18:38:10 +0100
commitb02f506cc3f6360c25881819996dbacc93702aea (patch)
treedca7f0204f4e13726464b9dc6fb54bd84f92146c /pygments/__init__.py
parent3688370accd711bfad3da4e080a1f8a4eae24478 (diff)
downloadpygments-b02f506cc3f6360c25881819996dbacc93702aea.tar.gz
Fix and test the "lex(class)" and "format(class)" handlers.
Diffstat (limited to 'pygments/__init__.py')
-rw-r--r--pygments/__init__.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/pygments/__init__.py b/pygments/__init__.py
index 8170d5f0..dc377369 100644
--- a/pygments/__init__.py
+++ b/pygments/__init__.py
@@ -45,7 +45,8 @@ def lex(code, lexer):
return lexer.get_tokens(code)
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 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