summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-01-18 16:44:49 +0100
committerGeorg Brandl <georg@python.org>2014-01-18 16:44:49 +0100
commit97703d63f39e6086d497a6a749c9eee3293dcbeb (patch)
treec970bf2a7bc17aa7053f3621e299a01fb9695342 /scripts
parent5500fd3a6d0c5ece01826606fcf2d684407b9cc6 (diff)
downloadpygments-97703d63f39e6086d497a6a749c9eee3293dcbeb.tar.gz
Finalize single-source port for Py2.[67] and Py3.3+.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/check_sources.py15
-rw-r--r--scripts/detect_missing_analyse_text.py2
-rwxr-xr-xscripts/find_codetags.py14
-rwxr-xr-xscripts/find_error.py2
-rwxr-xr-xscripts/vim2pygments.py8
5 files changed, 24 insertions, 17 deletions
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;
'<td class="tag %%(tag)s">%%(tag)s</td>'
'<td class="who">%%(who)s</td><td class="what">%%(what)s</td></tr>')
- 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'(?<!\\)\s+')
@@ -767,7 +767,7 @@ TOKENS = {
}
TOKEN_TYPES = set()
-for token in TOKENS.itervalues():
+for token in TOKENS.values():
if not isinstance(token, tuple):
token = (token,)
for token in token:
@@ -838,7 +838,7 @@ def find_colors(code):
colors['Normal']['bgcolor'] = bg_color
color_map = {}
- for token, styles in colors.iteritems():
+ for token, styles in colors.items():
if token in TOKENS:
tmp = []
if styles.get('noinherit'):
@@ -881,7 +881,7 @@ class StyleWriter(object):
def write(self, out):
self.write_header(out)
default_token, tokens = find_colors(self.code)
- tokens = tokens.items()
+ tokens = list(tokens.items())
tokens.sort(lambda a, b: cmp(len(a[0]), len(a[1])))
bg_color = [x[3:] for x in default_token.split() if x.startswith('bg:')]
if bg_color: