From 123ad3bdf1eac82be1dca6483ac131cd5e3e99c1 Mon Sep 17 00:00:00 2001
From: Ralph Bean <rbean@redhat.com>
Date: Tue, 26 Jun 2012 12:17:06 -0400
Subject: [PATCH 2/5] Replace str(foo) with six.text_type(foo)

---
 bin/bugzilla                  |   18 +++++++++++-------
 bugzilla/base.py              |   12 ++++++------
 bugzilla/bugzilla3.py         |    3 ++-
 bugzilla/rhbugzilla.py        |    5 +++--
 tests/manualtests/selftest.py |    9 ++++++---
 5 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/bin/bugzilla b/bin/bugzilla
index d3109f9..9edc283 100755
--- a/bin/bugzilla
+++ b/bin/bugzilla
@@ -507,7 +507,8 @@ def main(bzinstance=None):
         log.info('Using Bugzilla class %s' % global_opt.bztype)
         bzclass = getattr(bugzilla,global_opt.bztype)
     else:
-        parser.error("bztype must be one of: %s" % str(bugzilla.classlist))
+        parser.error("bztype must be one of: %s" %
+                     six.text_type(bugzilla.classlist))
 
     if bzinstance:
         bz = bzinstance
@@ -732,7 +733,7 @@ def main(bzinstance=None):
                 if type(val) is list:
                     val = ','.join(val)
                 try:
-                    return str(val)
+                    return six.text_type(val)
                 except UnicodeEncodeError:
                     return to_encoding(val)
             for b in buglist:
@@ -746,8 +747,10 @@ def main(bzinstance=None):
                 print(to_encoding(six.u('#%s %s - %s - %s') %
                         (b.bug_id, b.bug_status, b.assigned_to, b.short_desc)))
                 if b.cc: print("CC: %s" % " ".join(b.cc))
-                if b.blocked: print("Blocked: %s" % " ".join([str(i) for i in b.blocked]))
-                if b.dependson: print("Depends: %s" % " ".join([str(i) for i in b.dependson]))
+                if b.blocked: print("Blocked: %s" % " ".join([
+                    six.text_type(i) for i in b.blocked]))
+                if b.dependson: print("Depends: %s" % " ".join([
+                    six.text_type(i) for i in b.dependson]))
                 for c in b.longdescs:
                     if 'email' in c:
                         email = c['email']
@@ -783,7 +786,8 @@ def main(bzinstance=None):
             for b in buglist:
                 flags=''
                 cve=''
-                flags += "".join([str(i) for i in b.flags.split(',')])
+                flags += "".join([
+                    six.text_type(i) for i in b.flags.split(',')])
                 #grab CVEs by searching the keywords and grabbing that bugzilla
                 if b.keywords.find("Security") != -1:
                     blockedby="%s" % b.blockedby
@@ -818,10 +822,10 @@ if __name__ == '__main__':
         print("\ninterrupted.")
         sys.exit(1)
     except socket.error as e:
-        print("\nConnection lost/failed: %s" % str(e))
+        print("\nConnection lost/failed: %s" % six.text_type(e))
         sys.exit(2)
     except xmlrpclib.Fault as e:
-        print("\nServer error: %s" % str(e))
+        print("\nServer error: %s" % six.text_type(e))
         sys.exit(3)
     except xmlrpclib.ProtocolError as e:
         print("\nInvalid server response: %d %s" % (e.errcode, e.errmsg))
diff --git a/bugzilla/base.py b/bugzilla/base.py
index 38136a8..b90666c 100644
--- a/bugzilla/base.py
+++ b/bugzilla/base.py
@@ -204,7 +204,7 @@ class BugzillaBase(object):
                 cj.save(self._cookiefile)
             except Exception as e:
                 log.warn("Couldn't initialize temporary cookiefile%s: %s" %
-                        (self._cookiefile, str(e)))
+                        (self._cookiefile, six.text_type(e)))
         else:
             if os.path.exists(self._cookiefile):
                 cj = self._loadcookies(cj)
@@ -215,7 +215,7 @@ class BugzillaBase(object):
                     cj.save(self._cookiefile)
                 except Exception as e:
                     log.error("Couldn't initialize cookiefile %s: %s" %
-                            (self._cookiefile, str(e)))
+                            (self._cookiefile, six.text_type(e)))
                 os.umask(old_umask)
 
         self._cookiejar = cj
@@ -547,7 +547,7 @@ class BugzillaBase(object):
     def getbug(self,id):
         '''Return a Bug object with the full complement of bug data
         already loaded.'''
-        log.debug("getbug(%s)" % str(id))
+        log.debug("getbug(%s)" % six.text_type(id))
         return _Bug(bugzilla=self,dict=self._getbug(id))
     def getbugsimple(self,id):
         '''Return a Bug object given bug id, populated with simple info'''
@@ -1031,7 +1031,7 @@ class CookieTransport(xmlrpclib.Transport):
                 self.cookiejar.save(self.cookiejar.filename)
             except Exception as e:
                 log.error("Couldn't write cookiefile %s: %s" % \
-                        (self.cookiejar.filename,str(e)))
+                        (self.cookiejar.filename, six.text_type(e)))
 
         if errcode != 200:
             raise xmlrpclib.ProtocolError(
@@ -1091,7 +1091,7 @@ class CookieTransport(xmlrpclib.Transport):
                     self.cookiejar.save(self.cookiejar.filename)
                 except Exception as e:
                     log.error("Couldn't write cookiefile %s: %s" % \
-                            (self.cookiejar.filename,str(e)))
+                            (self.cookiejar.filename, six.text_type(e)))
 
             if response.status == 200:
                 self.verbose = verbose
@@ -1333,7 +1333,7 @@ class _Bug(object):
         r = self.bugzilla._getbug(self.bug_id)
         # faking a query
         q = {}
-        q['id'] = str(self.bug_id)
+        q['id'] = six.text_type(self.bug_id)
         q['column_list'] = self.bugzilla.bugfields
 
         # running post translation
diff --git a/bugzilla/bugzilla3.py b/bugzilla/bugzilla3.py
index 33f07f0..c3ebed6 100644
--- a/bugzilla/bugzilla3.py
+++ b/bugzilla/bugzilla3.py
@@ -10,6 +10,7 @@
 # the full text of the license.
 
 import bugzilla.base
+import six
 from six.moves import map
 from six.moves import zip
 
@@ -37,7 +38,7 @@ class Bugzilla3(bugzilla.base.BugzillaBase):
     def _getuserforid(self,userid):
         '''Get the username for the given userid'''
         # STUB FIXME
-        return str(userid)
+        return six.text_type(userid)
 
     # Connect the backend methods to the XMLRPC methods
     def _getbugfields(self):
diff --git a/bugzilla/rhbugzilla.py b/bugzilla/rhbugzilla.py
index c9acf8a..b10e044 100644
--- a/bugzilla/rhbugzilla.py
+++ b/bugzilla/rhbugzilla.py
@@ -330,7 +330,8 @@ class RHBugzilla(Bugzilla4):
         elif action == 'overwrite':
             r = self._getbug(id)
             if 'cc' not in r:
-                raise AttributeError("Can't find cc list in bug %s" % str(id))
+                raise AttributeError("Can't find cc list in bug %s" %
+                                     six.text_type(id))
             self._updatecc(id,r['cc'],'delete')
             self._updatecc(id,cclist,'add')
         # XXX we don't check inputs on other backend methods, maybe this
@@ -355,7 +356,7 @@ class RHBugzilla(Bugzilla4):
             r = self._getbug(id)
             if which not in r:
                 raise ValueError("No such whiteboard %s in bug %s" % \
-                                   (which,str(id)))
+                                   (which, six.text_type(id)))
             wb = r[which]
             if action == 'prepend':
                 update[which] = text+' '+wb
diff --git a/tests/manualtests/selftest.py b/tests/manualtests/selftest.py
index 11ee187..4d07ea7 100755
--- a/tests/manualtests/selftest.py
+++ b/tests/manualtests/selftest.py
@@ -16,6 +16,7 @@ sys.path.insert(0, "..") # top dir
 from bugzilla import Bugzilla
 import os, glob
 import xmlrpclib
+import six
 
 # TODO: Rewrite with unittest! This is pretty bogus!
 
@@ -96,17 +97,19 @@ def selftest(data,user='',password=''):
         print("Failed: %s" % e)
     print()
 
-    print("Reading multiple bugs, one-at-a-time: %s" % str(data['bugidlist']))
+    print("Reading multiple bugs, one-at-a-time: %s" %
+          six.text_type(data['bugidlist']))
     for b in data['bugidlist']:
         print(bz.getbug(b))
     print()
 
-    print("Reading multiple bugs, all-at-once: %s" % str(data['bugidlist']))
+    print("Reading multiple bugs, all-at-once: %s" %
+          six.text_type(data['bugidlist']))
     for b in bz.getbugs(data['bugidlist']):
         print(b)
     print()
 
-    print("Querying: %s" % str(data['query']))
+    print("Querying: %s" % six.text_type(data['query']))
     try:
         bugs = bz.query(data['query'])
         print("%s bugs found." % len(bugs))
-- 
1.7.10.4

