diff options
author | Georg Brandl <georg@python.org> | 2014-01-18 13:25:15 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-01-18 13:25:15 +0100 |
commit | a9169c157a05c82a1b8a7ffb92e7f159fb4ca0f8 (patch) | |
tree | face5db25ebef227315a0ae1080d4b2262f6fe23 /scripts | |
parent | e921fe0b430608cb7e0c89f7fada9260cb4822eb (diff) | |
download | pygments-a9169c157a05c82a1b8a7ffb92e7f159fb4ca0f8.tar.gz |
futurizing: move to print_function and "except X as Y" syntax
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/check_sources.py | 27 | ||||
-rw-r--r-- | scripts/detect_missing_analyse_text.py | 7 | ||||
-rwxr-xr-x | scripts/find_codetags.py | 27 | ||||
-rwxr-xr-x | scripts/find_error.py | 21 | ||||
-rw-r--r-- | scripts/get_vimkw.py | 3 | ||||
-rw-r--r-- | scripts/vim2pygments.py | 7 |
6 files changed, 49 insertions, 43 deletions
diff --git a/scripts/check_sources.py b/scripts/check_sources.py index a0bebe27..70013dcf 100755 --- a/scripts/check_sources.py +++ b/scripts/check_sources.py @@ -10,6 +10,7 @@ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import print_function import sys, os, re import getopt @@ -46,7 +47,7 @@ misspellings = ["developement", "adress", "verificate", # ALLOW-MISSPELLING def check_syntax(fn, lines): try: compile(''.join(lines), fn, "exec") - except SyntaxError, err: + except SyntaxError as err: yield 0, "not compilable: %s" % err @@ -67,9 +68,9 @@ def check_style_and_encoding(fn, lines): encoding = co.group(1) try: line.decode(encoding) - except UnicodeDecodeError, err: + except UnicodeDecodeError as err: yield lno+1, "not decodable: %s\n Line: %r" % (err, line) - except LookupError, err: + except LookupError as err: yield 0, "unknown encoding: %s" % encoding encoding = 'latin1' @@ -165,7 +166,7 @@ def main(argv): try: gopts, args = getopt.getopt(argv[1:], "vi:") except getopt.GetoptError: - print "Usage: %s [-v] [-i ignorepath]* [path]" % argv[0] + print("Usage: %s [-v] [-i ignorepath]* [path]" % argv[0]) return 2 opts = {} for opt, val in gopts: @@ -178,7 +179,7 @@ def main(argv): elif len(args) == 1: path = args[0] else: - print "Usage: %s [-v] [-i ignorepath]* [path]" % argv[0] + print("Usage: %s [-v] [-i ignorepath]* [path]" % argv[0]) return 2 verbose = '-v' in opts @@ -212,13 +213,13 @@ def main(argv): continue if verbose: - print "Checking %s..." % fn + print("Checking %s..." % fn) try: f = open(fn, 'r') lines = list(f) - except (IOError, OSError), err: - print "%s: cannot open: %s" % (fn, err) + except (IOError, OSError) as err: + print("%s: cannot open: %s" % (fn, err)) num += 1 continue @@ -226,15 +227,15 @@ def main(argv): if not in_pocoo_pkg and checker.only_pkg: continue for lno, msg in checker(fn, lines): - print >>out, "%s:%d: %s" % (fn, lno, msg) + print("%s:%d: %s" % (fn, lno, msg), file=out) num += 1 if verbose: - print + print() if num == 0: - print "No errors found." + print("No errors found.") else: - print out.getvalue().rstrip('\n') - print "%d error%s found." % (num, num > 1 and "s" or "") + print(out.getvalue().rstrip('\n')) + print("%d error%s found." % (num, num > 1 and "s" or "")) return int(num > 0) diff --git a/scripts/detect_missing_analyse_text.py b/scripts/detect_missing_analyse_text.py index 1312648f..ac1da06c 100644 --- a/scripts/detect_missing_analyse_text.py +++ b/scripts/detect_missing_analyse_text.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys from pygments.lexers import get_all_lexers, find_lexer_class @@ -9,7 +10,7 @@ def main(): for name, aliases, filenames, mimetypes in get_all_lexers(): cls = find_lexer_class(name) if not cls.aliases: - print cls, "has no aliases" + print(cls, "has no aliases") for f in filenames: if f not in uses: uses[f] = [] @@ -21,10 +22,10 @@ def main(): #print "Multiple for", k, v for i in v: if i.analyse_text is None: - print i, "has a None analyse_text" + print(i, "has a None analyse_text") ret |= 1 elif Lexer.analyse_text.__doc__ == i.analyse_text.__doc__: - print i, "needs analyse_text, multiple lexers for", k + print(i, "needs analyse_text, multiple lexers for", k) ret |= 2 return ret diff --git a/scripts/find_codetags.py b/scripts/find_codetags.py index 44c30a41..a939c495 100755 --- a/scripts/find_codetags.py +++ b/scripts/find_codetags.py @@ -10,6 +10,7 @@ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import print_function import sys, os, re import getopt @@ -73,8 +74,8 @@ def main(): try: gopts, args = getopt.getopt(sys.argv[1:], "vo:i:") except getopt.GetoptError: - print ("Usage: %s [-v] [-i ignoredir]* [-o reportfile.html] " - "path ..." % sys.argv[0]) + print(("Usage: %s [-v] [-i ignoredir]* [-o reportfile.html] " + "path ..." % sys.argv[0])) return 2 opts = {} for opt, val in gopts: @@ -97,18 +98,18 @@ def main(): num = 0 for path in args: - print "Searching for code tags in %s, please wait." % path + print("Searching for code tags in %s, please wait." % path) if isfile(path): gnum += 1 if process_file(store, path): if verbose: - print path + ": found %d tags" % \ - (path in store and len(store[path]) or 0) + print(path + ": found %d tags" % \ + (path in store and len(store[path]) or 0)) num += 1 else: if verbose: - print path + ": binary or not readable" + print(path + ": binary or not readable") continue elif not isdir(path): continue @@ -137,16 +138,16 @@ def main(): if fn[:2] == './': fn = fn[2:] if process_file(store, fn): if verbose: - print fn + ": found %d tags" % \ - (fn in store and len(store[fn]) or 0) + print(fn + ": found %d tags" % \ + (fn in store and len(store[fn]) or 0)) num += 1 else: if verbose: - print fn + ": binary or not readable" - print + print(fn + ": binary or not readable") + print() - print "Processed %d of %d files. Found %d tags in %d files." % ( - num, gnum, sum(len(fitem) for fitem in store.itervalues()), len(store)) + print("Processed %d of %d files. Found %d tags in %d files." % ( + num, gnum, sum(len(fitem) for fitem in store.itervalues()), len(store))) if not store: return 0 @@ -198,7 +199,7 @@ td { padding: 2px 5px 2px 5px; f.write(HTML % (', '.join(map(abspath, args)), table)) f.close() - print "Report written to %s." % output + print("Report written to %s." % output) return 0 if __name__ == '__main__': diff --git a/scripts/find_error.py b/scripts/find_error.py index 75f4b0ff..3ee77d7d 100755 --- a/scripts/find_error.py +++ b/scripts/find_error.py @@ -11,6 +11,7 @@ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import print_function import sys, os @@ -111,29 +112,29 @@ def main(fn, lexer=None, options={}): def show_token(tok, state): reprs = map(repr, tok) - print ' ' + reprs[1] + ' ' + ' ' * (29-len(reprs[1])) + reprs[0], + print(' ' + reprs[1] + ' ' + ' ' * (29-len(reprs[1])) + reprs[0], end=' ') if debug_lexer: - print ' ' + ' ' * (29-len(reprs[0])) + repr(state), - print + print(' ' + ' ' * (29-len(reprs[0])) + repr(state), end=' ') + print() for type, val in lx.get_tokens(text): lno += val.count('\n') if type == Error: - print 'Error parsing', fn, 'on line', lno - print 'Previous tokens' + (debug_lexer and ' and states' or '') + ':' + print('Error parsing', fn, 'on line', lno) + print('Previous tokens' + (debug_lexer and ' and states' or '') + ':') if showall: for tok, state in map(None, tokens, states): show_token(tok, state) else: for i in range(max(len(tokens) - num, 0), len(tokens)): show_token(tokens[i], states[i]) - print 'Error token:' + print('Error token:') l = len(repr(val)) - print ' ' + repr(val), + print(' ' + repr(val), end=' ') if debug_lexer and hasattr(lx, 'statestack'): - print ' ' * (60-l) + repr(lx.statestack), - print - print + print(' ' * (60-l) + repr(lx.statestack), end=' ') + print() + print() return 1 tokens.append((type, val)) if debug_lexer: diff --git a/scripts/get_vimkw.py b/scripts/get_vimkw.py index 153c88c3..bfb26e64 100644 --- a/scripts/get_vimkw.py +++ b/scripts/get_vimkw.py @@ -1,3 +1,4 @@ +from __future__ import print_function import re from pprint import pprint @@ -31,7 +32,7 @@ def getkw(input, output): for a, b in output_info.items(): b.sort() - print >>out, '%s=[%s]' % (a, ','.join(b)) + print('%s=[%s]' % (a, ','.join(b)), file=out) def is_keyword(w, keywords): for i in range(len(w), 0, -1): diff --git a/scripts/vim2pygments.py b/scripts/vim2pygments.py index 80f0ada2..6c33a36c 100644 --- a/scripts/vim2pygments.py +++ b/scripts/vim2pygments.py @@ -10,6 +10,7 @@ :copyright 2006 by Armin Ronacher. :license: BSD, see LICENSE for details. """ +from __future__ import print_function import sys import re @@ -916,14 +917,14 @@ def convert(filename, stream=None): def main(): if len(sys.argv) != 2 or sys.argv[1] in ('-h', '--help'): - print 'Usage: %s <filename.vim>' % sys.argv[0] + print('Usage: %s <filename.vim>' % sys.argv[0]) return 2 if sys.argv[1] in ('-v', '--version'): - print '%s %s' % (SCRIPT_NAME, SCRIPT_VERSION) + print('%s %s' % (SCRIPT_NAME, SCRIPT_VERSION)) return filename = sys.argv[1] if not (path.exists(filename) and path.isfile(filename)): - print 'Error: %s not found' % filename + print('Error: %s not found' % filename) return 1 convert(filename, sys.stdout) sys.stdout.write('\n') |