Skip to content

Commit a3ce8f9

Browse files
committed
Python 3 preparation: convert print to a function.
Tool-assisted patch. It is possible that some "from __future__ import print_function" are not in fact needed, if a file only uses print() with a single string as an argument and so would work fine in Python 2 without that import.
1 parent 7765153 commit a3ce8f9

32 files changed

+218
-186
lines changed

detectors/irker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# channels = irc://chat.freenode.net/channelname
1515
#
1616

17+
from __future__ import print_function
1718
import re
1819
import json
1920
import socket
@@ -94,7 +95,7 @@ def notify_irker(db, cl, nodeid, oldvalues):
9495
# Ignore any errors in sending the irker;
9596
# if the server is down, that's just bad luck
9697
# XXX might want to do some logging here
97-
print '* Sending message to irker failed', str(e)
98+
print('* Sending message to irker failed', str(e))
9899

99100
def init(db):
100101
db.issue.react('create', notify_irker)

roundup/backends/portalocker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
- Added return result
4848
"""
4949

50+
from __future__ import print_function
5051
__docformat__ = 'restructuredtext'
5152

5253
import os
@@ -151,7 +152,7 @@ def unlock(file):
151152
timestamp = strftime("%m/%d/%Y %H:%M:%S\n", localtime(time()))
152153
log.write( timestamp )
153154

154-
print "Wrote lines. Hit enter to release lock."
155+
print("Wrote lines. Hit enter to release lock.")
155156
dummy = sys.stdin.readline()
156157

157158
log.close()

roundup/cgi/TAL/talgettext.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
found.
3434
"""
3535

36+
from __future__ import print_function
3637
import sys
3738
import time
3839
import getopt
@@ -73,9 +74,9 @@
7374

7475
def usage(code, msg=''):
7576
# Python 2.1 required
76-
print >> sys.stderr, __doc__
77+
print(__doc__, file=sys.stderr)
7778
if msg:
78-
print >> sys.stderr, msg
79+
print(msg, file=sys.stderr)
7980
sys.exit(code)
8081

8182

@@ -163,7 +164,7 @@ def _loadFile(self):
163164
try:
164165
lines = open(self._filename).readlines()
165166
except IOError as msg:
166-
print >> sys.stderr, msg
167+
print(msg, file=sys.stderr)
167168
sys.exit(1)
168169

169170
section = None
@@ -205,9 +206,9 @@ def _loadFile(self):
205206
elif section == STR:
206207
msgstr += '%s\n' % l
207208
else:
208-
print >> sys.stderr, 'Syntax error on %s:%d' % (infile, lno), \
209-
'before:'
210-
print >> sys.stderr, l
209+
print('Syntax error on %s:%d' % (infile, lno),
210+
'before:', file=sys.stderr)
211+
print(l, file=sys.stderr)
211212
sys.exit(1)
212213
# Add last entry
213214
if section == STR:
@@ -253,7 +254,7 @@ def main():
253254
engine = UpdatePOEngine(filename=arg)
254255

255256
if not args:
256-
print 'nothing to do'
257+
print('nothing to do')
257258
return
258259

259260
# We don't care about the rendered output of the .pt file
@@ -276,7 +277,7 @@ def write(self, s):
276277
POTALInterpreter(program, macros, engine, stream=Devnull(),
277278
metal=False)()
278279
except: # Hee hee, I love bare excepts!
279-
print 'There was an error processing', filename
280+
print('There was an error processing', filename)
280281
traceback.print_exc()
281282

282283
# Now output the keys in the engine. Write them to a file if --output or
@@ -296,8 +297,8 @@ def write(self, s):
296297
except AttributeError:
297298
pass
298299
if '' not in messages:
299-
print >> outfile, pot_header % {'time': time.ctime(),
300-
'version': __version__}
300+
print(pot_header % {'time': time.ctime(),
301+
'version': __version__}, file=outfile)
301302

302303
msgids = catalog.keys()
303304
# XXX: You should not sort by msgid, but by filename and position. (SR)

roundup/cgi/cgitb.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
"""Extended CGI traceback handler by Ka-Ping Yee, <[email protected]>.
66
"""
7+
from __future__ import print_function
78
__docformat__ = 'restructuredtext'
89

910
import sys, os, types, string, keyword, linecache, tokenize, inspect, cgi
@@ -213,7 +214,7 @@ def linereader(file=file, lnum=[lnum]):
213214
return head + string.join(attribs) + string.join(traceback) + '<p>&nbsp;</p>'
214215

215216
def handler():
216-
print breaker()
217-
print html()
217+
print(breaker())
218+
print(html())
218219

219220
# vim: set filetype=python ts=4 sw=4 et si :

roundup/cgi/engine_jinja2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
https://github.com/mitsuhiko/jinja2/issues/174
3232
"""
3333

34+
from __future__ import print_function
3435
import jinja2
3536
import gettext
3637

@@ -45,8 +46,8 @@ def __init__(self, dir):
4546
extensions = [
4647
'jinja2.ext.autoescape',
4748
]
48-
print "Jinja2 templates: ", dir
49-
print "Extensions: ", extensions
49+
print("Jinja2 templates: ", dir)
50+
print("Extensions: ", extensions)
5051
self._env = jinja2.Environment(
5152
loader=jinja2.FileSystemLoader(dir),
5253
extensions=extensions

roundup/date.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
"""Date, time and time interval handling.
1919
"""
20+
from __future__ import print_function
2021
__docformat__ = 'restructuredtext'
2122

2223
import calendar
@@ -1204,30 +1205,30 @@ def test_range():
12041205
"2002-11-10; 2002-12-12", "; 20:00 +1d", '2002-10-12')
12051206
rispecs = ('from -1w 2d 4:32 to 4d', '-2w 1d')
12061207
for rspec in rspecs:
1207-
print '>>> Range("%s")' % rspec
1208-
print `Range(rspec, Date)`
1209-
print
1208+
print('>>> Range("%s")' % rspec)
1209+
print(`Range(rspec, Date)`)
1210+
print()
12101211
for rspec in rispecs:
1211-
print '>>> Range("%s")' % rspec
1212-
print `Range(rspec, Interval)`
1213-
print
1212+
print('>>> Range("%s")' % rspec)
1213+
print(`Range(rspec, Interval)`)
1214+
print()
12141215

12151216
def test():
12161217
intervals = (" 3w 1 d 2:00", " + 2d", "3w")
12171218
for interval in intervals:
1218-
print '>>> Interval("%s")'%interval
1219-
print `Interval(interval)`
1219+
print('>>> Interval("%s")'%interval)
1220+
print(`Interval(interval)`)
12201221

12211222
dates = (".", "2000-06-25.19:34:02", ". + 2d", "1997-04-17", "01-25",
12221223
"08-13.22:13", "14:25", '2002-12')
12231224
for date in dates:
1224-
print '>>> Date("%s")'%date
1225-
print `Date(date)`
1225+
print('>>> Date("%s")'%date)
1226+
print(`Date(date)`)
12261227

12271228
sums = ((". + 2d", "3w"), (".", " 3w 1 d 2:00"))
12281229
for date, interval in sums:
1229-
print '>>> Date("%s") + Interval("%s")'%(date, interval)
1230-
print `Date(date) + Interval(interval)`
1230+
print('>>> Date("%s") + Interval("%s")'%(date, interval))
1231+
print(`Date(date) + Interval(interval)`)
12311232

12321233
if __name__ == '__main__':
12331234
test()

roundup/dehtml.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
from __future__ import print_function
23
class dehtml:
34
def __init__(self, converter):
45
if converter == "none":
@@ -128,20 +129,20 @@ def html2text(html):
128129

129130
html2text = dehtml("dehtml").html2text
130131
if html2text:
131-
print html2text(html)
132+
print(html2text(html))
132133

133134
try:
134135
# trap error seen if N_TOKENS not defined when run.
135136
html2text = dehtml("beautifulsoup").html2text
136137
if html2text:
137-
print html2text(html)
138+
print(html2text(html))
138139
except NameError as e:
139-
print "captured error %s"%e
140+
print("captured error %s"%e)
140141

141142
html2text = dehtml("none").html2text
142143
if html2text:
143-
print "FAIL: Error, dehtml(none) is returning a function"
144+
print("FAIL: Error, dehtml(none) is returning a function")
144145
else:
145-
print "PASS: dehtml(none) is returning None"
146+
print("PASS: dehtml(none) is returning None")
146147

147148

roundup/dist/command/build.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# All rights reserved.
44
# For license terms see the file COPYING.txt.
55
#
6+
from __future__ import print_function
67
from roundup import msgfmt
78
from distutils.command.build import build as base
89
import os
@@ -26,7 +27,7 @@ def check_manifest():
2627
try:
2728
f = open('MANIFEST')
2829
except:
29-
print '\n*** SOURCE WARNING: The MANIFEST file is missing!'
30+
print('\n*** SOURCE WARNING: The MANIFEST file is missing!')
3031
return
3132
try:
3233
manifest = [l.strip() for l in f.readlines()]
@@ -38,9 +39,9 @@ def check_manifest():
3839
'roundup-mailgw', 'roundup-server', 'roundup-xmlrpc-server'])
3940
if err:
4041
n = len(manifest)
41-
print '\n*** SOURCE WARNING: There are files missing (%d/%d found)!'%(
42-
n-len(err), n)
43-
print 'Missing:', '\nMissing: '.join(err)
42+
print('\n*** SOURCE WARNING: There are files missing (%d/%d found)!'%(
43+
n-len(err), n))
44+
print('Missing:', '\nMissing: '.join(err))
4445

4546
def build_message_files(command):
4647
"""For each locale/*.po, build .mo file in target locale directory"""

roundup/init.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#
1818
"""Init (create) a roundup instance.
1919
"""
20+
from __future__ import print_function
2021
__docformat__ = 'restructuredtext'
2122

2223
import os, errno, email.parser
@@ -132,9 +133,9 @@ def loadTemplateInfo(path):
132133
return None
133134

134135
if os.path.exists(os.path.join(path, 'config.py')):
135-
print _("WARNING: directory '%s'\n"
136+
print(_("WARNING: directory '%s'\n"
136137
"\tcontains old-style template - ignored"
137-
) % os.path.abspath(path)
138+
) % os.path.abspath(path))
138139
return None
139140

140141
# load up the template's information

roundup/mailgw.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class node. Any parts of other types are each stored in separate files
9292
an exception, the original message is bounced back to the sender with the
9393
explanatory message given in the exception.
9494
"""
95+
from __future__ import print_function
9596
__docformat__ = 'restructuredtext'
9697

9798
import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
@@ -1379,7 +1380,7 @@ def do_imap(self, server, user='', password='', mailbox='', ssl=0,
13791380
password = getpass.getpass()
13801381
except (KeyboardInterrupt, EOFError):
13811382
# Ctrl C or D maybe also Ctrl Z under Windows.
1382-
print "\nAborted by user."
1383+
print("\nAborted by user.")
13831384
return 1
13841385
# open a connection to the server and retrieve all messages
13851386
try:
@@ -1468,7 +1469,7 @@ def _do_pop(self, server, user, password, apop, ssl):
14681469
password = getpass.getpass()
14691470
except (KeyboardInterrupt, EOFError):
14701471
# Ctrl C or D maybe also Ctrl Z under Windows.
1471-
print "\nAborted by user."
1472+
print("\nAborted by user.")
14721473
return 1
14731474

14741475
# open a connection to the server and retrieve all messages

0 commit comments

Comments
 (0)