correctly fixed pygments to work with Python3
This commit is contained in:
parent
840d4e17f1
commit
ce8d9af149
3 changed files with 16 additions and 16 deletions
|
@ -43,7 +43,7 @@ def lex(code, lexer):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return lexer.get_tokens(code)
|
return lexer.get_tokens(code)
|
||||||
except (TypeError as err):
|
except TypeError as err:
|
||||||
if isinstance(err.args[0], str) and \
|
if isinstance(err.args[0], str) and \
|
||||||
'unbound method get_tokens' in err.args[0]:
|
'unbound method get_tokens' in err.args[0]:
|
||||||
raise TypeError('lex() argument must be a lexer instance, '
|
raise TypeError('lex() argument must be a lexer instance, '
|
||||||
|
@ -67,7 +67,7 @@ def format(tokens, formatter, outfile=None):
|
||||||
return realoutfile.getvalue()
|
return realoutfile.getvalue()
|
||||||
else:
|
else:
|
||||||
formatter.format(tokens, outfile)
|
formatter.format(tokens, outfile)
|
||||||
except (TypeError as err):
|
except TypeError as err:
|
||||||
if isinstance(err.args[0], str) and \
|
if isinstance(err.args[0], str) and \
|
||||||
'unbound method format' in err.args[0]:
|
'unbound method format' in err.args[0]:
|
||||||
raise TypeError('format() argument must be a formatter instance, '
|
raise TypeError('format() argument must be a formatter instance, '
|
||||||
|
|
|
@ -202,7 +202,7 @@ def main(args=sys.argv):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:hVHg")
|
popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:hVHg")
|
||||||
except (getopt.GetoptError as err):
|
except getopt.GetoptError as err:
|
||||||
print >>sys.stderr, usage
|
print >>sys.stderr, usage
|
||||||
return 2
|
return 2
|
||||||
opts = {}
|
opts = {}
|
||||||
|
@ -279,9 +279,9 @@ def main(args=sys.argv):
|
||||||
if infn is not None:
|
if infn is not None:
|
||||||
try:
|
try:
|
||||||
lexer = get_lexer_for_filename(infn, **parsed_opts)
|
lexer = get_lexer_for_filename(infn, **parsed_opts)
|
||||||
except (ClassNotFound as err):
|
except ClassNotFound as err:
|
||||||
lexer = TextLexer()
|
lexer = TextLexer()
|
||||||
except (OptionError as err):
|
except OptionError as err:
|
||||||
print >>sys.stderr, 'Error:', err
|
print >>sys.stderr, 'Error:', err
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -303,14 +303,14 @@ def main(args=sys.argv):
|
||||||
try:
|
try:
|
||||||
parsed_opts['style'] = S_opt
|
parsed_opts['style'] = S_opt
|
||||||
fmter = get_formatter_by_name(f_opt, **parsed_opts)
|
fmter = get_formatter_by_name(f_opt, **parsed_opts)
|
||||||
except (ClassNotFound as err):
|
except ClassNotFound as err:
|
||||||
print >>sys.stderr, err
|
print >>sys.stderr, err
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
arg = a_opt or ''
|
arg = a_opt or ''
|
||||||
try:
|
try:
|
||||||
print fmter.get_style_defs(arg)
|
print fmter.get_style_defs(arg)
|
||||||
except (Exception as err):
|
except Exception as err:
|
||||||
print >>sys.stderr, 'Error:', err
|
print >>sys.stderr, 'Error:', err
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
@ -330,7 +330,7 @@ def main(args=sys.argv):
|
||||||
if fmter:
|
if fmter:
|
||||||
try:
|
try:
|
||||||
fmter = get_formatter_by_name(fmter, **parsed_opts)
|
fmter = get_formatter_by_name(fmter, **parsed_opts)
|
||||||
except ((OptionError, ClassNotFound) as err):
|
except (OptionError, ClassNotFound) as err:
|
||||||
print >>sys.stderr, 'Error:', err
|
print >>sys.stderr, 'Error:', err
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -338,12 +338,12 @@ def main(args=sys.argv):
|
||||||
if not fmter:
|
if not fmter:
|
||||||
try:
|
try:
|
||||||
fmter = get_formatter_for_filename(outfn, **parsed_opts)
|
fmter = get_formatter_for_filename(outfn, **parsed_opts)
|
||||||
except ((OptionError, ClassNotFound) as err):
|
except (OptionError, ClassNotFound) as err:
|
||||||
print >>sys.stderr, 'Error:', err
|
print >>sys.stderr, 'Error:', err
|
||||||
return 1
|
return 1
|
||||||
try:
|
try:
|
||||||
outfile = open(outfn, 'wb')
|
outfile = open(outfn, 'wb')
|
||||||
except (Exception as err):
|
except Exception as err:
|
||||||
print >>sys.stderr, 'Error: cannot open outfile:', err
|
print >>sys.stderr, 'Error: cannot open outfile:', err
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
|
@ -356,7 +356,7 @@ def main(args=sys.argv):
|
||||||
if lexer:
|
if lexer:
|
||||||
try:
|
try:
|
||||||
lexer = get_lexer_by_name(lexer, **parsed_opts)
|
lexer = get_lexer_by_name(lexer, **parsed_opts)
|
||||||
except ((OptionError, ClassNotFound) as err):
|
except (OptionError, ClassNotFound) as err:
|
||||||
print >>sys.stderr, 'Error:', err
|
print >>sys.stderr, 'Error:', err
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -368,14 +368,14 @@ def main(args=sys.argv):
|
||||||
infn = args[0]
|
infn = args[0]
|
||||||
try:
|
try:
|
||||||
code = open(infn, 'rb').read()
|
code = open(infn, 'rb').read()
|
||||||
except (Exception as err):
|
except Exception as err:
|
||||||
print >>sys.stderr, 'Error: cannot read infile:', err
|
print >>sys.stderr, 'Error: cannot read infile:', err
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if not lexer:
|
if not lexer:
|
||||||
try:
|
try:
|
||||||
lexer = get_lexer_for_filename(infn, code, **parsed_opts)
|
lexer = get_lexer_for_filename(infn, code, **parsed_opts)
|
||||||
except (ClassNotFound as err):
|
except ClassNotFound as err:
|
||||||
if '-g' in opts:
|
if '-g' in opts:
|
||||||
try:
|
try:
|
||||||
lexer = guess_lexer(code, **parsed_opts)
|
lexer = guess_lexer(code, **parsed_opts)
|
||||||
|
@ -384,7 +384,7 @@ def main(args=sys.argv):
|
||||||
else:
|
else:
|
||||||
print >>sys.stderr, 'Error:', err
|
print >>sys.stderr, 'Error:', err
|
||||||
return 1
|
return 1
|
||||||
except (OptionError as err):
|
except OptionError as err:
|
||||||
print >>sys.stderr, 'Error:', err
|
print >>sys.stderr, 'Error:', err
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -426,7 +426,7 @@ def main(args=sys.argv):
|
||||||
for fname, fopts in F_opts:
|
for fname, fopts in F_opts:
|
||||||
lexer.add_filter(fname, **fopts)
|
lexer.add_filter(fname, **fopts)
|
||||||
highlight(code, lexer, fmter, outfile)
|
highlight(code, lexer, fmter, outfile)
|
||||||
except (Exception as err):
|
except Exception as err:
|
||||||
import traceback
|
import traceback
|
||||||
info = traceback.format_exception(*sys.exc_info())
|
info = traceback.format_exception(*sys.exc_info())
|
||||||
msg = info[-1].strip()
|
msg = info[-1].strip()
|
||||||
|
|
|
@ -453,7 +453,7 @@ class RegexLexerMeta(LexerMeta):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rex = cls._process_regex(tdef[0], rflags)
|
rex = cls._process_regex(tdef[0], rflags)
|
||||||
except (Exception as err):
|
except Exception as err:
|
||||||
raise ValueError("uncompilable regex %r in state %r of %r: %s" %
|
raise ValueError("uncompilable regex %r in state %r of %r: %s" %
|
||||||
(tdef[0], state, cls, err))
|
(tdef[0], state, cls, err))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue