[python-bugzilla] add compatibility patch for python 2.7 (bug 621298)

dmalcolm dmalcolm at fedoraproject.org
Thu Aug 5 18:47:46 UTC 2010


commit e13b3280587f97ece2ed401ada5f65cb35fd1583
Author: David Malcolm <dmalcolm at redhat.com>
Date:   Thu Aug 5 14:50:14 2010 -0400

    add compatibility patch for python 2.7 (bug 621298)

 python-bugzilla.spec |   11 +++++-
 python27.patch       |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 108 insertions(+), 1 deletions(-)
---
diff --git a/python-bugzilla.spec b/python-bugzilla.spec
index a67013a..ab9c644 100644
--- a/python-bugzilla.spec
+++ b/python-bugzilla.spec
@@ -2,13 +2,18 @@
 
 Name:           python-bugzilla
 Version:        0.6.1
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        A python library for interacting with Bugzilla
 
 Group:          Development/Languages
 License:        GPLv2+
 URL:            https://fedorahosted.org/python-bugzilla
 Source0:        %{name}-%{version}.tar.bz2
+
+# Python 2.7 compatibility patch to handle changes in the underlying
+# xmlrpclib (rhbz#621298):
+Patch0:         python27.patch
+
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
 BuildArch:      noarch
@@ -26,6 +31,7 @@ for interacting with bugzilla from shell scripts.
 
 %prep
 %setup -q
+%patch0 -p1
 
 
 %build
@@ -52,6 +58,9 @@ rm -rf $RPM_BUILD_ROOT
 
 
 %changelog
+* Thu Aug  5 2010 David Malcolm <dmalcolm at redhat.com> - 0.6.1-3
+- add compatibility patch for python 2.7 (bug 621298)
+
 * Wed Jul 21 2010 David Malcolm <dmalcolm at redhat.com> - 0.6.1-2
 - Rebuilt for https://fedoraproject.org/wiki/Features/Python_2.7/MassRebuild
 
diff --git a/python27.patch b/python27.patch
new file mode 100644
index 0000000..ec0951b
--- /dev/null
+++ b/python27.patch
@@ -0,0 +1,98 @@
+commit 120e4196f219ad92358a279c42bb771b3a9aad9e
+Author: Will Woods <wwoods at redhat.com>
+Date:   Thu Aug 5 14:10:46 2010 -0400
+
+    Fix for httplib/xmlrpclib changes in py2.7
+
+diff --git a/bugzilla/base.py b/bugzilla/base.py
+index 7f2bb88..d1a6d61 100644
+--- a/bugzilla/base.py
++++ b/bugzilla/base.py
+@@ -936,9 +936,9 @@ class CookieTransport(xmlrpclib.Transport):
+         else:
+             log.debug("send_cookies(): cookiejar empty. Nothing to send.")
+ 
+-    # This is the same request() method from xmlrpclib.Transport,
++    # This is the same request() method from python 2.6's xmlrpclib.Transport,
+     # with a couple additions noted below
+-    def request(self, host, handler, request_body, verbose=0):
++    def request_with_cookies(self, host, handler, request_body, verbose=0):
+         h = self.make_connection(host)
+         if verbose:
+             h.set_debuglevel(1)
+@@ -985,10 +985,74 @@ class CookieTransport(xmlrpclib.Transport):
+ 
+         return self._parse_response(h.getfile(), sock)
+ 
++    # This is just python 2.7's xmlrpclib.Transport.single_request, with
++    # send additions noted below to send cookies along with the request
++    def single_request_with_cookies(self, host, handler, request_body, verbose=0):
++        h = self.make_connection(host)
++        if verbose:
++            h.set_debuglevel(1)
++
++        # ADDED: construct the URL and Request object for proper cookie handling
++        request_url = "%s://%s%s" % (self.scheme,host,handler)
++        log.debug("request_url is %s" % request_url)
++        cookie_request  = urllib2.Request(request_url)
++
++        try:
++            self.send_request(h,handler,request_body)
++            self.send_host(h,host)
++            self.send_cookies(h,cookie_request) # ADDED. creates cookiejar if None.
++            self.send_user_agent(h)
++            self.send_content(h,request_body)
++
++            response = h.getresponse(buffering=True)
++
++            # ADDED: parse headers and get cookies here
++            cookie_response = CookieResponse(response.msg)
++            # Okay, extract the cookies from the headers
++            self.cookiejar.extract_cookies(cookie_response,cookie_request)
++            log.debug("cookiejar now contains: %s" % self.cookiejar._cookies)
++            # And write back any changes
++            if hasattr(self.cookiejar,'save'):
++                try:
++                    self.cookiejar.save(self.cookiejar.filename)
++                except Exception, e:
++                    log.error("Couldn't write cookiefile %s: %s" % \
++                            (self.cookiejar.filename,str(e)))
++
++            if response.status == 200:
++                self.verbose = verbose
++                return self.parse_response(response)
++        except xmlrpclib.Fault:
++            raise
++        except Exception:
++            # All unexpected errors leave connection in
++            # a strange state, so we clear it.
++            self.close()
++            raise
++
++        #discard any response data and raise exception
++        if (response.getheader("content-length", 0)):
++            response.read()
++        raise xmlrpclib.ProtocolError(
++            host + handler,
++            response.status, response.reason,
++            response.msg,
++            )
++
++    # Override the appropriate request method
++    if hasattr(xmlrpclib.Transport, 'single_request'):
++        single_request = single_request_with_cookies # python 2.7+
++    else:
++        request = request_with_cookies # python 2.6 and earlier
++
+ class SafeCookieTransport(xmlrpclib.SafeTransport,CookieTransport):
+     '''SafeTransport subclass that supports cookies.'''
+     scheme = 'https'
+-    request = CookieTransport.request
++    # Override the appropriate request method
++    if hasattr(xmlrpclib.Transport, 'single_request'):
++        single_request = CookieTransport.single_request_with_cookies
++    else:
++        request = CookieTransport.request_with_cookies
+ 
+ class _User(object):
+     '''Container object for a bugzilla User.


More information about the scm-commits mailing list