summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Gedminas <marius@gedmin.as>2013-02-07 20:35:41 +0000
committerMarius Gedminas <marius@gedmin.as>2013-02-07 20:35:41 +0000
commit7f4185b1cd7478218c133c7b0a15de37e2719cf1 (patch)
treed360ad0eb86d706efbb1e9d1cf68158c57713195
parent6d1e2a84abe57ce784d647adbb89e6267de29f2f (diff)
downloadzope-tal-7f4185b1cd7478218c133c7b0a15de37e2719cf1.tar.gz
Towards Py3K: print() function
-rw-r--r--src/zope/tal/driver.py6
-rw-r--r--src/zope/tal/ndiff.py30
-rw-r--r--src/zope/tal/runtest.py25
-rw-r--r--src/zope/tal/talgettext.py31
-rw-r--r--src/zope/tal/tests/markbench.py10
-rw-r--r--src/zope/tal/tests/utils.py4
-rw-r--r--src/zope/tal/timer.py4
7 files changed, 61 insertions, 49 deletions
diff --git a/src/zope/tal/driver.py b/src/zope/tal/driver.py
index bf0af38..61d0061 100644
--- a/src/zope/tal/driver.py
+++ b/src/zope/tal/driver.py
@@ -37,6 +37,8 @@ Options:
Enable source annotations
"""
+from __future__ import print_function
+
import os
import sys
@@ -104,9 +106,9 @@ ENGINES = {'test23.html': TestEngine,
}
def usage(code, msg=''):
- print >> sys.stderr, __doc__
+ print(__doc__, file=sys.stderr)
if msg:
- print >> sys.stderr, msg
+ print(msg, file=sys.stderr)
sys.exit(code)
def main():
diff --git a/src/zope/tal/ndiff.py b/src/zope/tal/ndiff.py
index 02294b3..306b057 100644
--- a/src/zope/tal/ndiff.py
+++ b/src/zope/tal/ndiff.py
@@ -56,6 +56,8 @@ recovered by piping the output through
See module comments for details and programmatic interface.
"""
+from __future__ import print_function
+
__version__ = 1, 5, 0
# SequenceMatcher tries to compute a "human-friendly diff" between
@@ -314,8 +316,8 @@ class SequenceMatcher(object):
bestsize = bestsize + 1
if TRACE:
- print "get_matching_blocks", alo, ahi, blo, bhi
- print " returns", besti, bestj, bestsize
+ print("get_matching_blocks", alo, ahi, blo, bhi)
+ print(" returns", besti, bestj, bestsize)
return besti, bestj, bestsize
def get_matching_blocks(self):
@@ -326,7 +328,7 @@ class SequenceMatcher(object):
self.__helper(0, la, 0, lb, self.matching_blocks)
self.matching_blocks.append((la, lb, 0))
if TRACE:
- print '*** matching blocks', self.matching_blocks
+ print('*** matching blocks', self.matching_blocks)
return self.matching_blocks
# builds list of matching blocks covering a[alo:ahi] and
@@ -418,7 +420,7 @@ class SequenceMatcher(object):
# meant for dumping lines
def dump(tag, x, lo, hi):
for i in xrange(lo, hi):
- print tag, x[i],
+ print(tag, x[i], end=' ')
def plain_replace(a, alo, ahi, b, blo, bhi):
assert alo < ahi and blo < bhi
@@ -438,7 +440,7 @@ def plain_replace(a, alo, ahi, b, blo, bhi):
def fancy_replace(a, alo, ahi, b, blo, bhi):
if TRACE:
- print '*** fancy_replace', alo, ahi, blo, bhi
+ print('*** fancy_replace', alo, ahi, blo, bhi)
dump('>', a, alo, ahi)
dump('<', b, blo, bhi)
@@ -486,7 +488,7 @@ def fancy_replace(a, alo, ahi, b, blo, bhi):
# a[best_i] very similar to b[best_j]; eqi is None iff they're not
# identical
if TRACE:
- print '*** best_ratio', best_ratio, best_i, best_j
+ print('*** best_ratio', best_ratio, best_i, best_j)
dump('>', a, best_i, best_i+1)
dump('<', b, best_j, best_j+1)
@@ -516,7 +518,7 @@ def fancy_replace(a, alo, ahi, b, blo, bhi):
printq(aelt, belt, atags, btags)
else:
# the synch pair is identical
- print ' ', aelt,
+ print(' ', aelt, end=' ')
# pump out diffs from after the synch point
fancy_helper(a, best_i+1, ahi, b, best_j+1, bhi)
@@ -537,12 +539,12 @@ def printq(aline, bline, atags, btags):
common = min(count_leading(aline, "\t"),
count_leading(bline, "\t"))
common = min(common, count_leading(atags[:common], " "))
- print "-", aline,
+ print("-", aline, end=' ')
if count_leading(atags, " ") < len(atags):
- print "?", "\t" * common + atags[common:]
- print "+", bline,
+ print("?", "\t" * common + atags[common:])
+ print("+", bline, end=' ')
if count_leading(btags, " ") < len(btags):
- print "?", "\t" * common + btags[common:]
+ print("?", "\t" * common + btags[common:])
def count_leading(line, ch):
i, n = 0, len(line)
@@ -621,8 +623,8 @@ def main(args):
return fail("need 2 filename args")
f1name, f2name = args
if noisy:
- print '-:', f1name
- print '+:', f2name
+ print('-:', f1name)
+ print('+:', f2name)
return fcompare(f1name, f2name)
def restore(which):
@@ -631,7 +633,7 @@ def restore(which):
prefixes = (" ", tag)
for line in sys.stdin.readlines():
if line[:2] in prefixes:
- print line[2:],
+ print(line[2:], end=' ')
if __name__ == '__main__':
import sys
diff --git a/src/zope/tal/runtest.py b/src/zope/tal/runtest.py
index c1d6d06..abb23d9 100644
--- a/src/zope/tal/runtest.py
+++ b/src/zope/tal/runtest.py
@@ -14,6 +14,9 @@
##############################################################################
"""Driver program to run METAL and TAL regression tests.
"""
+
+from __future__ import print_function
+
import glob
import os
import sys
@@ -33,10 +36,10 @@ def showdiff(a, b):
for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
if tag == "equal":
continue
- print nicerange(alo, ahi) + tag[0] + nicerange(blo, bhi)
+ print(nicerange(alo, ahi) + tag[0] + nicerange(blo, bhi))
ndiff.dump('<', a, alo, ahi)
if a and b:
- print '---'
+ print('---')
ndiff.dump('>', b, blo, bhi)
def nicerange(lo, hi):
@@ -80,10 +83,10 @@ def main():
if arg.find("_sa") >= 0 and "-a" not in opts:
locopts.append("-a")
if not unittesting:
- print arg,
+ print(arg, end=' ')
sys.stdout.flush()
if zope.tal.tests.utils.skipxml and arg.endswith(".xml"):
- print "SKIPPED (XML parser not available)"
+ print("SKIPPED (XML parser not available)")
continue
save = sys.stdout, sys.argv
try:
@@ -98,13 +101,13 @@ def main():
except:
errors = 1
if quiet:
- print sys.exc_type
+ print(sys.exc_info()[0])
sys.stdout.flush()
else:
if unittesting:
- print
+ print()
else:
- print "Failed:"
+ print("Failed:")
sys.stdout.flush()
traceback.print_exc()
continue
@@ -116,7 +119,7 @@ def main():
f = open(outfile)
except IOError:
expected = None
- print "(missing file %s)" % outfile,
+ print("(missing file %s)" % outfile, end=' ')
else:
expected = f.readlines()
f.close()
@@ -127,12 +130,12 @@ def main():
actual = readlines(stdout)
if actual == expected:
if not unittesting:
- print "OK"
+ print("OK")
else:
if unittesting:
- print
+ print()
else:
- print "not OK"
+ print("not OK")
errors = 1
if not quiet and expected is not None:
showdiff(expected, actual)
diff --git a/src/zope/tal/talgettext.py b/src/zope/tal/talgettext.py
index 6f0ea73..77172ed 100644
--- a/src/zope/tal/talgettext.py
+++ b/src/zope/tal/talgettext.py
@@ -27,6 +27,9 @@ Options:
Update the existing translation <file> with any new translation strings
found.
"""
+
+from __future__ import print_function
+
import sys
import time
import getopt
@@ -62,9 +65,9 @@ NLSTR = '"\n"'
def usage(code, msg=''):
# Python 2.1 required
- print >> sys.stderr, __doc__
+ print(__doc__, file=sys.stderr)
if msg:
- print >> sys.stderr, msg
+ print(msg, file=sys.stderr)
sys.exit(code)
@@ -131,10 +134,10 @@ class POEngine(DummyEngine):
existing_msgid = msgids[idx]
if msgid.default != existing_msgid.default:
references = '\n'.join([location[0]+':'+str(location[1]) for location in domain[msgid]])
- print >> sys.stderr, (u"Warning: msgid '%s' in %s already exists " \
- "with a different default (bad: %s, should be: %s)\n" \
- "The references for the existent value are:\n%s\n" % \
- (msgid, self.file+':'+str(position), msgid.default.encode('utf-8'), existing_msgid.default.encode('utf-8'), references)).encode('utf-8')
+ print(("Warning: msgid '%s' in %s already exists "
+ "with a different default (bad: %s, should be: %s)\n"
+ "The references for the existent value are:\n%s\n" %
+ (msgid, self.file+':'+str(position), msgid.default.encode('utf-8'), existing_msgid.default.encode('utf-8'), references)).encode('utf-8'), file=sys.stderr)
domain[msgid].append((self.file, position))
return 'x'
@@ -171,7 +174,7 @@ class UpdatePOEngine(POEngine):
try:
lines = open(self._filename).readlines()
except IOError as msg:
- print >> sys.stderr, msg
+ print(msg, file=sys.stderr)
sys.exit(1)
section = None
@@ -213,9 +216,9 @@ class UpdatePOEngine(POEngine):
elif section == STR:
msgstr += '%s\n' % l
else:
- print >> sys.stderr, 'Syntax error on %s:%d' % (infile, lno), \
- 'before:'
- print >> sys.stderr, l
+ print('Syntax error on %s:%d' % (infile, lno),
+ 'before:', file=sys.stderr)
+ print(l, file=sys.stderr)
sys.exit(1)
# Add last entry
if section == STR:
@@ -261,7 +264,7 @@ def main():
engine = UpdatePOEngine(filename=arg)
if not args:
- print 'nothing to do'
+ print('nothing to do')
return
# We don't care about the rendered output of the .pt file
@@ -284,7 +287,7 @@ def main():
POTALInterpreter(program, macros, engine, stream=Devnull(),
metal=False)()
except: # Hee hee, I love bare excepts!
- print 'There was an error processing', filename
+ print('There was an error processing', filename)
traceback.print_exc()
# Now output the keys in the engine. Write them to a file if --output or
@@ -304,8 +307,8 @@ def main():
except AttributeError:
pass
if '' not in messages:
- print >> outfile, pot_header % {'time': time.ctime(),
- 'version': __version__}
+ print(pot_header % {'time': time.ctime(), 'version': __version__},
+ file=outfile)
msgids = catalog.keys()
# TODO: You should not sort by msgid, but by filename and position. (SR)
diff --git a/src/zope/tal/tests/markbench.py b/src/zope/tal/tests/markbench.py
index 14ac26a..76667b3 100644
--- a/src/zope/tal/tests/markbench.py
+++ b/src/zope/tal/tests/markbench.py
@@ -15,6 +15,8 @@
"""Run benchmarks of TAL vs. DTML
"""
+from __future__ import print_function
+
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
@@ -108,14 +110,14 @@ def compare(n, count, profiler=None, verbose=1):
t1 = int(time_zpt(tal_fn % n, count) * 1000 + 0.5)
t2 = int(time_tal(tal_fn % n, count) * 1000 + 0.5)
t3 = 'n/a' # int(time_dtml(dtml_fn % n, count) * 1000 + 0.5)
- print '%.2d: %10s %10s %10s' % (n, t1, t2, t3)
+ print('%.2d: %10s %10s %10s' % (n, t1, t2, t3))
if profiler:
profile_tal(tal_fn % n, count, profiler)
def main(count, profiler=None, verbose=1):
n = 1
if verbose:
- print '##: %10s %10s %10s' % ('ZPT', 'TAL', 'DTML')
+ print('##: %10s %10s %10s' % ('ZPT', 'TAL', 'DTML'))
while os.path.isfile(tal_fn % n) and os.path.isfile(dtml_fn % n):
compare(n, count, profiler, verbose)
n = n + 1
@@ -160,9 +162,9 @@ if __name__ == "__main__":
sys.exit(rc)
elif rc < 0:
sig = -rc
- print >>sys.stderr, (
+ print((
"Process exited, signal %d (%s)."
- % (sig, get_signal_name(sig) or "<unknown signal>"))
+ % (sig, get_signal_name(sig) or "<unknown signal>")), file=sys.stderr)
sys.exit(1)
os.chdir(pwd)
diff --git a/src/zope/tal/tests/utils.py b/src/zope/tal/tests/utils.py
index d2463a6..384a756 100644
--- a/src/zope/tal/tests/utils.py
+++ b/src/zope/tal/tests/utils.py
@@ -50,8 +50,8 @@ def run_suite(suite, outf=None, errf=None):
## print
newerrs = len(result.errors) + len(result.failures)
if newerrs:
- print "'Errors' indicate exceptions other than AssertionError."
- print "'Failures' indicate AssertionError"
+ print("'Errors' indicate exceptions other than AssertionError.")
+ print("'Failures' indicate AssertionError")
if errf is None:
errf = sys.stderr
errf.write("%d errors, %d failures\n"
diff --git a/src/zope/tal/timer.py b/src/zope/tal/timer.py
index 3b75bc2..5162baf 100644
--- a/src/zope/tal/timer.py
+++ b/src/zope/tal/timer.py
@@ -28,7 +28,7 @@ def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "n:")
except getopt.error as msg:
- print msg
+ print(msg)
sys.exit(2)
for o, a in opts:
if o == "-n":
@@ -36,7 +36,7 @@ def main():
if not args:
args = [FILE]
for file in args:
- print file
+ print(file)
dummyfile = StringIO()
it = timefunc(count, compilefile, file)
timefunc(count, interpretit, it, None, dummyfile)