diff options
author | Owen W. Taylor <otaylor@fishsoup.net> | 2010-09-22 15:54:36 -0400 |
---|---|---|
committer | Owen W. Taylor <otaylor@redhat.com> | 2010-09-22 15:59:15 -0400 |
commit | 8c82336a05df1cb2b59ef70e62c7b936a6b655d7 (patch) | |
tree | be33e9a6d4c008b401ddfc8e5494ba19f11e96ec | |
parent | 5ae24ed5f9782e21a46ac78a496186810645aad1 (diff) |
Fix python-2.7 compatibility with xmlrpclib
In Python 2.7 xmlrpclib was changed to use httplib.HTTP[S]Connection
instead of the deprecatede httplib.HTTP[S]. This broke our
xmlrpclib.Transport subclass which overrode make_connection().
For compatibility with old and new Python, switch to subclassing
Transport and SafeTransport separately, with a mixin to add cookies.
https://bugzilla.gnome.org/show_bug.cgi?id=628731
-rwxr-xr-x | git-bz | 30 |
1 files changed, 16 insertions, 14 deletions
@@ -920,7 +920,10 @@ class BugServer(object): if self._xmlrpc_proxy is None: uri = "%s://%s/xmlrpc.cgi" % ("https" if self.https else "http", self.host) - transport = BugTransport(self) + if self.https: + transport = SafeBugTransport(self) + else: + transport = BugTransport(self) self._xmlrpc_proxy = xmlrpclib.ServerProxy(uri, transport) return self._xmlrpc_proxy @@ -951,24 +954,23 @@ class BugServer(object): cache.set(self.host, 'legal_' + field, values) return values -class BugTransport(xmlrpclib.Transport): - def __init__(self, server): - xmlrpclib.Transport.__init__(self) - self.server = server - - # Overriding this allows us not to separately subclass Transport and SafeTransport - def make_connection(self, host): - if self.server.https: - return httplib.HTTPS(self.server.host) - else: - return httplib.HTTP(self.server.host) - - # This is the main point of the subclassing - to add cookies +# mixin for xmlrpclib.Transport classes to add cookies +class CookieTransportMixin(object): def send_request(self, connection, *args): xmlrpclib.Transport.send_request(self, connection, *args) connection.putheader("Cookie", self.server.get_cookie_string()) connection.putheader("Authorization", http_auth_header(self.server.auth_user, self.server.auth_password)) +class BugTransport(CookieTransportMixin, xmlrpclib.Transport): + def __init__(self, server): + xmlrpclib.Transport.__init__(self) + self.server = server + +class SafeBugTransport(CookieTransportMixin, xmlrpclib.SafeTransport): + def __init__(self, server): + xmlrpclib.SafeTransport.__init__(self) + self.server = server + servers = {} # Note that if we detect that we are redirecting, we may rewrite the |