From: Arun Babu Neelicattu abn@redhat.com
--- bin/bugzilla | 46 ++++++++++++++++++++++++---------------------- bugzilla/bug.py | 2 +- setup.py | 12 +++++++----- tests/__init__.py | 6 ++++-- tests/misc.py | 6 ++++-- tests/rw_functional.py | 10 ++++++---- 6 files changed, 46 insertions(+), 36 deletions(-)
diff --git a/bin/bugzilla b/bin/bugzilla index fa5314b..980970d 100755 --- a/bin/bugzilla +++ b/bin/bugzilla @@ -11,6 +11,8 @@ # option) any later version. See http://www.gnu.org/copyleft/gpl.html for # the full text of the license.
+from __future__ import print_function + import getpass import locale import logging @@ -515,7 +517,7 @@ https://fedorahosted.org/mailman/listinfo/python-bugzilla http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html https://bugzilla.redhat.com/docs/en/html/api/Bugzilla/WebService/Bug.html'''
- print manpage + print(manpage)
def _do_query(bz, opt, parser): @@ -653,11 +655,11 @@ def _do_info(bz, opt):
if opt.products: for name in sorted([p["name"] for p in products]): - print name + print(name)
if opt.components: for name in sorted(bz.getcomponents(opt.components)): - print name + print(name)
if opt.component_owners: # Looking up this info for rhbz 'Fedora' product is sloooow @@ -672,8 +674,8 @@ def _do_info(bz, opt):
component_details = bz.getcomponentsdetails(opt.component_owners) for c in sorted(component_details): - print to_encoding(u"%s: %s" % - (c, component_details[c]['initialowner'])) + print(to_encoding(u"%s: %s" % + (c, component_details[c]['initialowner'])))
if opt.versions: for p in products: @@ -681,7 +683,7 @@ def _do_info(bz, opt): continue if "versions" in p: for v in p['versions']: - print to_encoding(v["name"]) + print(to_encoding(v["name"])) break
@@ -723,12 +725,12 @@ def _format_output(bz, opt, buglist): if opt.output == 'raw': buglist = bz.getbugs([b.bug_id for b in buglist]) for b in buglist: - print "Bugzilla %s: " % b.bug_id + print("Bugzilla %s: " % b.bug_id) for a in dir(b): if a.startswith("__") and a.endswith("__"): continue - print to_encoding(u"ATTRIBUTE[%s]: %s" % (a, getattr(b, a))) - print "\n\n" + print(to_encoding(u"ATTRIBUTE[%s]: %s" % (a, getattr(b, a)))) + print("\n\n") return
def bug_field(matchobj): @@ -779,7 +781,7 @@ def _format_output(bz, opt, buglist): return to_encoding(val)
for b in buglist: - print format_field_re.sub(bug_field, opt.outputformat) + print(format_field_re.sub(bug_field, opt.outputformat))
def _parse_triset(vallist, checkplus=True, checkminus=True, checkequal=True, @@ -969,7 +971,7 @@ def _do_get_attach(bz, opt, parser, args): while data: outfile.write(data) data = att.read(4096) - print "Wrote %s" % outfile.name + print("Wrote %s" % outfile.name)
return
@@ -1008,7 +1010,7 @@ def _do_set_attach(bz, opt, parser, args): # Upload attachments for bugid in args: attid = bz.attachfile(bugid, fileobj, desc, **kwargs) - print "Created attachment %i on bug %s" % (attid, bugid) + print("Created attachment %i on bug %s" % (attid, bugid))
################# @@ -1080,10 +1082,10 @@ def main(bzinstance=None): sys.stdout.write('Logging in... ') sys.stdout.flush() if bz.login(global_opt.user, global_opt.password): - print 'Authorization cookie received.' + print('Authorization cookie received.') sys.exit(0) else: - print 'failed.' + print('failed.') sys.exit(1)
# Set up authentication @@ -1162,32 +1164,32 @@ if __name__ == '__main__': main() except KeyboardInterrupt: log.debug("", exc_info=True) - print "\nExited at user request." + print("\nExited at user request.") sys.exit(1) except socket.error, e: log.debug("", exc_info=True) - print "\nConnection lost/failed: %s" % str(e) + print("\nConnection lost/failed: %s" % str(e)) sys.exit(2) except (xmlrpclib.Fault, urllib2.HTTPError), e: log.debug("", exc_info=True) - print "\nServer error: %s" % str(e) + print("\nServer error: %s" % str(e)) sys.exit(3) except xmlrpclib.ProtocolError, e: log.debug("", exc_info=True) - print "\nInvalid server response: %d %s" % (e.errcode, e.errmsg) + print("\nInvalid server response: %d %s" % (e.errcode, e.errmsg))
# Give SSL recommendations import pycurl sslerrcodes = [getattr(pycurl, ename) for ename in dir(pycurl) if ename.startswith("E_SSL")] if e.errcode in sslerrcodes: - print ("\nIf you trust the remote server, you can work " - "around this error with:\n" + print("\nIf you trust the remote server, you can work " + "around this error with:\n" " bugzilla --nosslverify ...")
# Detect redirect redir = (e.headers and e.headers.getheader("location", 0) or None) if redir: - print ("\nServer was attempting a redirect. Try: " - " bugzilla --bugzilla %s ..." % redir) + print("\nServer was attempting a redirect. Try: " + " bugzilla --bugzilla %s ..." % redir) sys.exit(4) diff --git a/bugzilla/bug.py b/bugzilla/bug.py index dbff5cb..4a068d3 100644 --- a/bugzilla/bug.py +++ b/bugzilla/bug.py @@ -48,7 +48,7 @@ class _Bug(object): '''Return a simple string representation of this bug
This is available only for compatibility. Using 'str(bug)' and - 'print bug' is not recommended because of potential encoding issues. + 'print(bug)' is not recommended because of potential encoding issues. Please use unicode(bug) where possible. ''' return unicode(self).encode(locale.getpreferredencoding(), 'replace') diff --git a/setup.py b/setup.py index 27761c4..415eee0 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,7 @@ #!/usr/bin/python
+from __future__ import print_function + import glob import os import sys @@ -70,7 +72,7 @@ class TestCommand(Command): try: unittest.installHandler() except: - print "installHandler hack failed" + print("installHandler hack failed")
tests = unittest.TestLoader().loadTestsFromNames(testfiles) if self.only: @@ -82,14 +84,14 @@ class TestCommand(Command): newtests.append(testcase)
if not newtests: - print "--only didn't find any tests" + print("--only didn't find any tests") sys.exit(1)
tests = unittest.TestSuite(newtests) - print "Running only:" + print("Running only:") for test in newtests: - print "%s" % test - print + print("%s" % test) + print()
t = unittest.TextTestRunner(verbosity=1) diff --git a/tests/__init__.py b/tests/__init__.py index 5122cf0..8d32b39 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,4 +1,6 @@
+from __future__ import print_function + import atexit import commands import difflib @@ -71,8 +73,8 @@ def clicomm(argv, bzinstance, returnmain=False, printcliout=False, ret = 0 mainout = None try: - print " ".join(argv) - print + print(" ".join(argv)) + print()
mainout = bugzillascript.main(bzinstance) except SystemExit, sys_e: diff --git a/tests/misc.py b/tests/misc.py index bb48bcc..865dd8e 100644 --- a/tests/misc.py +++ b/tests/misc.py @@ -9,6 +9,8 @@ Unit tests for building query strings with bin/bugzilla '''
+from __future__ import print_function + import atexit import os import shutil @@ -35,7 +37,7 @@ class MiscCLI(unittest.TestCase): from logilab.common.optik_ext import ManHelpFormatter ignore = ManHelpFormatter except Exception, e: - print "Skipping man page test: %s" % e + print("Skipping man page test: %s" % e) return
out = tests.clicomm("bugzilla --generate-man", None) @@ -68,7 +70,7 @@ class MiscAPI(unittest.TestCase): def testCookies(self): if (sys.version_info[0] < 2 or (sys.version_info[0] == 2 and sys.version_info[1] < 6)): - print "\npython too old, skipping cookie test" + print("\npython too old, skipping cookie test") return
cookiesbad = os.path.join(os.getcwd(), "tests/data/cookies-bad.txt") diff --git a/tests/rw_functional.py b/tests/rw_functional.py index 8bc9b93..a50f736 100644 --- a/tests/rw_functional.py +++ b/tests/rw_functional.py @@ -9,6 +9,8 @@ Unit tests that do permanent functional against a real bugzilla instances. '''
+from __future__ import print_function + import datetime import os import random @@ -63,13 +65,13 @@ class RHPartnerTest(BaseTest): # Check a known account that likely won't ever go away ret = bool(bz.getuser("anaconda-maint-list@redhat.com").groupnames) if not ret: - print "\nNo admin privs, skipping %s" % funcname + print("\nNo admin privs, skipping %s" % funcname) return ret
def _check_rh_privs(self, bz, funcname, quiet=False): noprivs = bool(bz.getbugs([184858]) == [None]) if noprivs and not quiet: - print "\nNo RH privs, skipping %s" % funcname + print("\nNo RH privs, skipping %s" % funcname) return not noprivs
@@ -97,7 +99,7 @@ class RHPartnerTest(BaseTest):
bugid = int(newout.splitlines()[2]) bug = bz.getbug(bugid) - print "\nCreated bugid: %s" % bugid + print("\nCreated bugid: %s" % bugid)
# Verify hasattr works self.assertTrue(hasattr(bug, "id")) @@ -142,7 +144,7 @@ class RHPartnerTest(BaseTest):
bugid = int(newout.splitlines()[2]) bug = bz.getbug(bugid) - print "\nCreated bugid: %s" % bugid + print("\nCreated bugid: %s" % bugid)
self.assertEquals(bug.summary, summary) self.assertEquals(bug.bug_file_loc, url)