From a5d83e7816a32c3c64c0b0736693183fc8e90846 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 4 Jan 2011 10:21:30 +0100 Subject: [PATCH] this fix should work on any version of python --- sfa/util/xmlrpcprotocol.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sfa/util/xmlrpcprotocol.py b/sfa/util/xmlrpcprotocol.py index 2d2586e8..b39ab0e3 100644 --- a/sfa/util/xmlrpcprotocol.py +++ b/sfa/util/xmlrpcprotocol.py @@ -26,6 +26,14 @@ class ExceptionUnmarshaller(xmlrpclib.Unmarshaller): # # A transport for XMLRPC that works on top of HTTPS +# python 2.7 xmlrpclib has changed its internal code +# it now calls 'getresponse' on the obj returned by make_connection +# while it used to call 'getreply' +# regardless of the version, httplib.HTTPS does implement getreply, +# while httplib.HTTPSConnection has getresponse +# so we create a dummy instance to check what's expected +need_HTTPSConnection=hasattr(xmlrpclib.Transport().make_connection('localhost'),'getresponse') + class XMLRPCTransport(xmlrpclib.Transport): key_file = None cert_file = None @@ -33,11 +41,10 @@ class XMLRPCTransport(xmlrpclib.Transport): # create a HTTPS connection object from a host descriptor # host may be a string, or a (host, x509-dict) tuple host, extra_headers, x509 = self.get_host_info(host) - try: -# return httplib.HTTPS(host, None, key_file=self.key_file, cert_file=self.cert_file) #**(x509 or {})) + if need_HTTPSConnection: return httplib.HTTPSConnection(host, None, key_file=self.key_file, cert_file=self.cert_file) #**(x509 or {})) - except AttributeError: - raise NotImplementedError("your version of httplib doesn't support HTTPSConnection") + else: + return httplib.HTTPS(host, None, key_file=self.key_file, cert_file=self.cert_file) #**(x509 or {})) def getparser(self): unmarshaller = ExceptionUnmarshaller() -- 2.43.0