Skip to content

Commit 9fb22e2

Browse files
abncrobinso
authored andcommitted
Make print statements forward compatibile with python3
1 parent 3b8a7f8 commit 9fb22e2

6 files changed

Lines changed: 46 additions & 36 deletions

File tree

bin/bugzilla

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
1212
# the full text of the license.
1313

14+
from __future__ import print_function
15+
1416
import getpass
1517
import locale
1618
import logging
@@ -515,7 +517,7 @@ https://fedorahosted.org/mailman/listinfo/python-bugzilla
515517
http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html
516518
https://bugzilla.redhat.com/docs/en/html/api/Bugzilla/WebService/Bug.html'''
517519

518-
print manpage
520+
print(manpage)
519521

520522

521523
def _do_query(bz, opt, parser):
@@ -653,11 +655,11 @@ def _do_info(bz, opt):
653655

654656
if opt.products:
655657
for name in sorted([p["name"] for p in products]):
656-
print name
658+
print(name)
657659

658660
if opt.components:
659661
for name in sorted(bz.getcomponents(opt.components)):
660-
print name
662+
print(name)
661663

662664
if opt.component_owners:
663665
# Looking up this info for rhbz 'Fedora' product is sloooow
@@ -672,16 +674,16 @@ def _do_info(bz, opt):
672674

673675
component_details = bz.getcomponentsdetails(opt.component_owners)
674676
for c in sorted(component_details):
675-
print to_encoding(u"%s: %s" %
676-
(c, component_details[c]['initialowner']))
677+
print(to_encoding(u"%s: %s" %
678+
(c, component_details[c]['initialowner'])))
677679

678680
if opt.versions:
679681
for p in products:
680682
if p['name'] != opt.versions:
681683
continue
682684
if "versions" in p:
683685
for v in p['versions']:
684-
print to_encoding(v["name"])
686+
print(to_encoding(v["name"]))
685687
break
686688

687689

@@ -723,12 +725,12 @@ def _format_output(bz, opt, buglist):
723725
if opt.output == 'raw':
724726
buglist = bz.getbugs([b.bug_id for b in buglist])
725727
for b in buglist:
726-
print "Bugzilla %s: " % b.bug_id
728+
print("Bugzilla %s: " % b.bug_id)
727729
for a in dir(b):
728730
if a.startswith("__") and a.endswith("__"):
729731
continue
730-
print to_encoding(u"ATTRIBUTE[%s]: %s" % (a, getattr(b, a)))
731-
print "\n\n"
732+
print(to_encoding(u"ATTRIBUTE[%s]: %s" % (a, getattr(b, a))))
733+
print("\n\n")
732734
return
733735

734736
def bug_field(matchobj):
@@ -779,7 +781,7 @@ def _format_output(bz, opt, buglist):
779781
return to_encoding(val)
780782

781783
for b in buglist:
782-
print format_field_re.sub(bug_field, opt.outputformat)
784+
print(format_field_re.sub(bug_field, opt.outputformat))
783785

784786

785787
def _parse_triset(vallist, checkplus=True, checkminus=True, checkequal=True,
@@ -969,7 +971,7 @@ def _do_get_attach(bz, opt, parser, args):
969971
while data:
970972
outfile.write(data)
971973
data = att.read(4096)
972-
print "Wrote %s" % outfile.name
974+
print("Wrote %s" % outfile.name)
973975

974976
return
975977

@@ -1008,7 +1010,7 @@ def _do_set_attach(bz, opt, parser, args):
10081010
# Upload attachments
10091011
for bugid in args:
10101012
attid = bz.attachfile(bugid, fileobj, desc, **kwargs)
1011-
print "Created attachment %i on bug %s" % (attid, bugid)
1013+
print("Created attachment %i on bug %s" % (attid, bugid))
10121014

10131015

10141016
#################
@@ -1080,10 +1082,10 @@ def main(bzinstance=None):
10801082
sys.stdout.write('Logging in... ')
10811083
sys.stdout.flush()
10821084
if bz.login(global_opt.user, global_opt.password):
1083-
print 'Authorization cookie received.'
1085+
print('Authorization cookie received.')
10841086
sys.exit(0)
10851087
else:
1086-
print 'failed.'
1088+
print('failed.')
10871089
sys.exit(1)
10881090

10891091
# Set up authentication
@@ -1162,32 +1164,32 @@ if __name__ == '__main__':
11621164
main()
11631165
except KeyboardInterrupt:
11641166
log.debug("", exc_info=True)
1165-
print "\nExited at user request."
1167+
print("\nExited at user request.")
11661168
sys.exit(1)
11671169
except socket.error, e:
11681170
log.debug("", exc_info=True)
1169-
print "\nConnection lost/failed: %s" % str(e)
1171+
print("\nConnection lost/failed: %s" % str(e))
11701172
sys.exit(2)
11711173
except (xmlrpclib.Fault, urllib2.HTTPError), e:
11721174
log.debug("", exc_info=True)
1173-
print "\nServer error: %s" % str(e)
1175+
print("\nServer error: %s" % str(e))
11741176
sys.exit(3)
11751177
except xmlrpclib.ProtocolError, e:
11761178
log.debug("", exc_info=True)
1177-
print "\nInvalid server response: %d %s" % (e.errcode, e.errmsg)
1179+
print("\nInvalid server response: %d %s" % (e.errcode, e.errmsg))
11781180

11791181
# Give SSL recommendations
11801182
import pycurl
11811183
sslerrcodes = [getattr(pycurl, ename) for ename in dir(pycurl) if
11821184
ename.startswith("E_SSL")]
11831185
if e.errcode in sslerrcodes:
1184-
print ("\nIf you trust the remote server, you can work "
1185-
"around this error with:\n"
1186+
print("\nIf you trust the remote server, you can work "
1187+
"around this error with:\n"
11861188
" bugzilla --nosslverify ...")
11871189

11881190
# Detect redirect
11891191
redir = (e.headers and e.headers.getheader("location", 0) or None)
11901192
if redir:
1191-
print ("\nServer was attempting a redirect. Try: "
1192-
" bugzilla --bugzilla %s ..." % redir)
1193+
print("\nServer was attempting a redirect. Try: "
1194+
" bugzilla --bugzilla %s ..." % redir)
11931195
sys.exit(4)

bugzilla/bug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __str__(self):
4848
'''Return a simple string representation of this bug
4949
5050
This is available only for compatibility. Using 'str(bug)' and
51-
'print bug' is not recommended because of potential encoding issues.
51+
'print(bug)' is not recommended because of potential encoding issues.
5252
Please use unicode(bug) where possible.
5353
'''
5454
return unicode(self).encode(locale.getpreferredencoding(), 'replace')

setup.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/python
22

3+
from __future__ import print_function
4+
35
import glob
46
import os
57
import sys
@@ -70,7 +72,7 @@ def run(self):
7072
try:
7173
unittest.installHandler()
7274
except:
73-
print "installHandler hack failed"
75+
print("installHandler hack failed")
7476

7577
tests = unittest.TestLoader().loadTestsFromNames(testfiles)
7678
if self.only:
@@ -82,14 +84,14 @@ def run(self):
8284
newtests.append(testcase)
8385

8486
if not newtests:
85-
print "--only didn't find any tests"
87+
print("--only didn't find any tests")
8688
sys.exit(1)
8789

8890
tests = unittest.TestSuite(newtests)
89-
print "Running only:"
91+
print("Running only:")
9092
for test in newtests:
91-
print "%s" % test
92-
print
93+
print("%s" % test)
94+
print()
9395

9496

9597
t = unittest.TextTestRunner(verbosity=1)

tests/__init__.py

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

2+
from __future__ import print_function
3+
24
import atexit
35
import commands
46
import difflib
@@ -71,8 +73,8 @@ def clicomm(argv, bzinstance, returnmain=False, printcliout=False,
7173
ret = 0
7274
mainout = None
7375
try:
74-
print " ".join(argv)
75-
print
76+
print(" ".join(argv))
77+
print()
7678

7779
mainout = bugzillascript.main(bzinstance)
7880
except SystemExit, sys_e:

tests/misc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
Unit tests for building query strings with bin/bugzilla
1010
'''
1111

12+
from __future__ import print_function
13+
1214
import atexit
1315
import os
1416
import shutil
@@ -35,7 +37,7 @@ def testManPageGeneration(self):
3537
from logilab.common.optik_ext import ManHelpFormatter
3638
ignore = ManHelpFormatter
3739
except Exception, e:
38-
print "Skipping man page test: %s" % e
40+
print("Skipping man page test: %s" % e)
3941
return
4042

4143
out = tests.clicomm("bugzilla --generate-man", None)
@@ -68,7 +70,7 @@ def testUserAgent(self):
6870
def testCookies(self):
6971
if (sys.version_info[0] < 2 or
7072
(sys.version_info[0] == 2 and sys.version_info[1] < 6)):
71-
print "\npython too old, skipping cookie test"
73+
print("\npython too old, skipping cookie test")
7274
return
7375

7476
cookiesbad = os.path.join(os.getcwd(), "tests/data/cookies-bad.txt")

tests/rw_functional.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
Unit tests that do permanent functional against a real bugzilla instances.
1010
'''
1111

12+
from __future__ import print_function
13+
1214
import datetime
1315
import os
1416
import random
@@ -63,13 +65,13 @@ def _check_have_admin(self, bz, funcname):
6365
# Check a known account that likely won't ever go away
6466
ret = bool(bz.getuser("[email protected]").groupnames)
6567
if not ret:
66-
print "\nNo admin privs, skipping %s" % funcname
68+
print("\nNo admin privs, skipping %s" % funcname)
6769
return ret
6870

6971
def _check_rh_privs(self, bz, funcname, quiet=False):
7072
noprivs = bool(bz.getbugs([184858]) == [None])
7173
if noprivs and not quiet:
72-
print "\nNo RH privs, skipping %s" % funcname
74+
print("\nNo RH privs, skipping %s" % funcname)
7375
return not noprivs
7476

7577

@@ -97,7 +99,7 @@ def test3NewBugBasic(self):
9799

98100
bugid = int(newout.splitlines()[2])
99101
bug = bz.getbug(bugid)
100-
print "\nCreated bugid: %s" % bugid
102+
print("\nCreated bugid: %s" % bugid)
101103

102104
# Verify hasattr works
103105
self.assertTrue(hasattr(bug, "id"))
@@ -142,7 +144,7 @@ def test4NewBugAllFields(self):
142144

143145
bugid = int(newout.splitlines()[2])
144146
bug = bz.getbug(bugid)
145-
print "\nCreated bugid: %s" % bugid
147+
print("\nCreated bugid: %s" % bugid)
146148

147149
self.assertEquals(bug.summary, summary)
148150
self.assertEquals(bug.bug_file_loc, url)

0 commit comments

Comments
 (0)