From 97703d63f39e6086d497a6a749c9eee3293dcbeb Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 18 Jan 2014 16:44:49 +0100 Subject: Finalize single-source port for Py2.[67] and Py3.3+. --- scripts/check_sources.py | 15 +++++++++------ scripts/detect_missing_analyse_text.py | 2 +- scripts/find_codetags.py | 14 +++++++++----- scripts/find_error.py | 2 +- scripts/vim2pygments.py | 8 ++++---- 5 files changed, 24 insertions(+), 17 deletions(-) (limited to 'scripts') diff --git a/scripts/check_sources.py b/scripts/check_sources.py index 759fce72..71aff299 100755 --- a/scripts/check_sources.py +++ b/scripts/check_sources.py @@ -13,11 +13,11 @@ from __future__ import print_function +import io import os import re import sys import getopt -import cStringIO from os.path import join, splitext, abspath @@ -71,6 +71,9 @@ def check_style_and_encoding(fn, lines): encoding = co.group(1) try: line.decode(encoding) + except AttributeError: + # Python 3 - encoding was already checked + pass except UnicodeDecodeError as err: yield lno+1, "not decodable: %s\n Line: %r" % (err, line) except LookupError as err: @@ -134,7 +137,7 @@ def check_fileheader(fn, lines): yield 0, "no correct license info" ci = -3 - copyright = [s.decode('utf-8') for s in llist[ci:ci+1]] + copyright = llist[ci:ci+1] while copyright and copyright_2_re.match(copyright[0]): ci -= 1 copyright = llist[ci:ci+1] @@ -188,14 +191,14 @@ def main(argv): verbose = '-v' in opts num = 0 - out = cStringIO.StringIO() + out = io.StringIO() # TODO: replace os.walk run with iteration over output of # `svn list -R`. for root, dirs, files in os.walk(path): - if '.svn' in dirs: - dirs.remove('.svn') + if '.hg' in dirs: + dirs.remove('.hg') if '-i' in opts and abspath(root) in opts['-i']: del dirs[:] continue @@ -230,7 +233,7 @@ def main(argv): if not in_pocoo_pkg and checker.only_pkg: continue for lno, msg in checker(fn, lines): - print("%s:%d: %s" % (fn, lno, msg), file=out) + print(u"%s:%d: %s" % (fn, lno, msg), file=out) num += 1 if verbose: print() diff --git a/scripts/detect_missing_analyse_text.py b/scripts/detect_missing_analyse_text.py index ac1da06c..ab58558e 100644 --- a/scripts/detect_missing_analyse_text.py +++ b/scripts/detect_missing_analyse_text.py @@ -17,7 +17,7 @@ def main(): uses[f].append(cls) ret = 0 - for k, v in uses.iteritems(): + for k, v in uses.items(): if len(v) > 1: #print "Multiple for", k, v for i in v: diff --git a/scripts/find_codetags.py b/scripts/find_codetags.py index 7da80e15..f8204e6e 100755 --- a/scripts/find_codetags.py +++ b/scripts/find_codetags.py @@ -121,11 +121,15 @@ def main(): if '-i' in opts and abspath(root) in opts['-i']: del dirs[:] continue - if '.svn' in dirs: - dirs.remove('.svn') + if '.hg' in dirs: + dirs.remove('.hg') + if 'examplefiles' in dirs: + dirs.remove('examplefiles') + if 'dist' in dirs: + dirs.remove('dist') for fn in files: gnum += 1 - if gnum % 50 == 0 and not verbose: + if gnum % 25 == 0 and not verbose: sys.stdout.write('.') sys.stdout.flush() @@ -150,7 +154,7 @@ def main(): 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))) + num, gnum, sum(len(fitem) for fitem in store.values()), len(store))) if not store: return 0 @@ -194,7 +198,7 @@ td { padding: 2px 5px 2px 5px; '%%(tag)s' '%%(who)s%%(what)s') - f = file(output, 'w') + f = open(output, 'w') table = '\n'.join(TABLE % fname + '\n'.join(TR % (no % 2,) % entry for no, entry in enumerate(store[fname])) diff --git a/scripts/find_error.py b/scripts/find_error.py index 7a513701..7aaa9bee 100755 --- a/scripts/find_error.py +++ b/scripts/find_error.py @@ -107,7 +107,7 @@ def main(fn, lexer=None, options={}): # already debugged before debug_lexer = True lno = 1 - text = file(fn, 'U').read() + text = open(fn, 'U').read() text = text.strip('\n') + '\n' tokens = [] states = [] diff --git a/scripts/vim2pygments.py b/scripts/vim2pygments.py index 348fb852..42af0bbe 100755 --- a/scripts/vim2pygments.py +++ b/scripts/vim2pygments.py @@ -16,7 +16,7 @@ from __future__ import print_function import sys import re from os import path -from cStringIO import StringIO +from io import StringIO split_re = re.compile(r'(?