From 8c82336a05df1cb2b59ef70e62c7b936a6b655d7 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Wed, 22 Sep 2010 15:54:36 -0400 Subject: 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 --- git-bz | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/git-bz b/git-bz index ebfc09f..dc27532 100755 --- a/git-bz +++ b/git-bz @@ -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 -- cgit v1.2.3