From ce8d9af149aaedbe53b0efaffff4e44355e5a4ae Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Sun, 22 Sep 2013 14:12:25 -0700 Subject: [PATCH] correctly fixed pygments to work with Python3 --- .../wakatime/packages/pygments/__init__.py | 4 +-- .../wakatime/packages/pygments/cmdline.py | 26 +++++++++---------- .../wakatime/packages/pygments/lexer.py | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/wakatime/wakatime/packages/pygments/__init__.py b/packages/wakatime/wakatime/packages/pygments/__init__.py index 0f70768..e48c9dc 100644 --- a/packages/wakatime/wakatime/packages/pygments/__init__.py +++ b/packages/wakatime/wakatime/packages/pygments/__init__.py @@ -43,7 +43,7 @@ def lex(code, lexer): """ try: return lexer.get_tokens(code) - except (TypeError as err): + except TypeError as err: if isinstance(err.args[0], str) and \ 'unbound method get_tokens' in err.args[0]: raise TypeError('lex() argument must be a lexer instance, ' @@ -67,7 +67,7 @@ def format(tokens, formatter, outfile=None): return realoutfile.getvalue() else: formatter.format(tokens, outfile) - except (TypeError as err): + except TypeError as err: if isinstance(err.args[0], str) and \ 'unbound method format' in err.args[0]: raise TypeError('format() argument must be a formatter instance, ' diff --git a/packages/wakatime/wakatime/packages/pygments/cmdline.py b/packages/wakatime/wakatime/packages/pygments/cmdline.py index 21095fe..614668b 100644 --- a/packages/wakatime/wakatime/packages/pygments/cmdline.py +++ b/packages/wakatime/wakatime/packages/pygments/cmdline.py @@ -202,7 +202,7 @@ def main(args=sys.argv): try: 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 return 2 opts = {} @@ -279,9 +279,9 @@ def main(args=sys.argv): if infn is not None: try: lexer = get_lexer_for_filename(infn, **parsed_opts) - except (ClassNotFound as err): + except ClassNotFound as err: lexer = TextLexer() - except (OptionError as err): + except OptionError as err: print >>sys.stderr, 'Error:', err return 1 @@ -303,14 +303,14 @@ def main(args=sys.argv): try: parsed_opts['style'] = S_opt fmter = get_formatter_by_name(f_opt, **parsed_opts) - except (ClassNotFound as err): + except ClassNotFound as err: print >>sys.stderr, err return 1 arg = a_opt or '' try: print fmter.get_style_defs(arg) - except (Exception as err): + except Exception as err: print >>sys.stderr, 'Error:', err return 1 return 0 @@ -330,7 +330,7 @@ def main(args=sys.argv): if fmter: try: fmter = get_formatter_by_name(fmter, **parsed_opts) - except ((OptionError, ClassNotFound) as err): + except (OptionError, ClassNotFound) as err: print >>sys.stderr, 'Error:', err return 1 @@ -338,12 +338,12 @@ def main(args=sys.argv): if not fmter: try: fmter = get_formatter_for_filename(outfn, **parsed_opts) - except ((OptionError, ClassNotFound) as err): + except (OptionError, ClassNotFound) as err: print >>sys.stderr, 'Error:', err return 1 try: outfile = open(outfn, 'wb') - except (Exception as err): + except Exception as err: print >>sys.stderr, 'Error: cannot open outfile:', err return 1 else: @@ -356,7 +356,7 @@ def main(args=sys.argv): if lexer: try: lexer = get_lexer_by_name(lexer, **parsed_opts) - except ((OptionError, ClassNotFound) as err): + except (OptionError, ClassNotFound) as err: print >>sys.stderr, 'Error:', err return 1 @@ -368,14 +368,14 @@ def main(args=sys.argv): infn = args[0] try: code = open(infn, 'rb').read() - except (Exception as err): + except Exception as err: print >>sys.stderr, 'Error: cannot read infile:', err return 1 if not lexer: try: lexer = get_lexer_for_filename(infn, code, **parsed_opts) - except (ClassNotFound as err): + except ClassNotFound as err: if '-g' in opts: try: lexer = guess_lexer(code, **parsed_opts) @@ -384,7 +384,7 @@ def main(args=sys.argv): else: print >>sys.stderr, 'Error:', err return 1 - except (OptionError as err): + except OptionError as err: print >>sys.stderr, 'Error:', err return 1 @@ -426,7 +426,7 @@ def main(args=sys.argv): for fname, fopts in F_opts: lexer.add_filter(fname, **fopts) highlight(code, lexer, fmter, outfile) - except (Exception as err): + except Exception as err: import traceback info = traceback.format_exception(*sys.exc_info()) msg = info[-1].strip() diff --git a/packages/wakatime/wakatime/packages/pygments/lexer.py b/packages/wakatime/wakatime/packages/pygments/lexer.py index 6709d67..e8ea045 100644 --- a/packages/wakatime/wakatime/packages/pygments/lexer.py +++ b/packages/wakatime/wakatime/packages/pygments/lexer.py @@ -453,7 +453,7 @@ class RegexLexerMeta(LexerMeta): try: 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" % (tdef[0], state, cls, err))