diff options
Diffstat (limited to 'pygments')
-rw-r--r-- | pygments/__init__.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/pygments/__init__.py b/pygments/__init__.py index 1d8faebd..c1ea2af4 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 |