1. Jędrzej Nowak
  2. CherryPy

Source

CherryPy / cherrypy / test / test_xmlrpc.py

Diff from to

File cherrypy/test/test_xmlrpc.py

 import sys
-from xmlrpclib import DateTime, Fault, ServerProxy, SafeTransport
+from cherrypy._cpcompat import py3k
 
-class HTTPSTransport(SafeTransport):
-    """Subclass of SafeTransport to fix sock.recv errors (by using file)."""
-    
-    def request(self, host, handler, request_body, verbose=0):
-        # issue XML-RPC request
-        h = self.make_connection(host)
-        if verbose:
-            h.set_debuglevel(1)
+try:
+    from xmlrpclib import DateTime, Fault, ProtocolError, ServerProxy, SafeTransport
+except ImportError:
+    from xmlrpc.client import DateTime, Fault, ProtocolError, ServerProxy, SafeTransport
+
+if py3k:
+    HTTPSTransport = SafeTransport
+
+    # Python 3.0's SafeTransport still mistakenly checks for socket.ssl
+    import socket
+    if not hasattr(socket, "ssl"):
+        socket.ssl = True
+else:
+    class HTTPSTransport(SafeTransport):
+        """Subclass of SafeTransport to fix sock.recv errors (by using file)."""
         
-        self.send_request(h, handler, request_body)
-        self.send_host(h, host)
-        self.send_user_agent(h)
-        self.send_content(h, request_body)
-        
-        errcode, errmsg, headers = h.getreply()
-        if errcode != 200:
-            raise xmlrpclib.ProtocolError(host + handler, errcode, errmsg,
-                                          headers)
-        
-        self.verbose = verbose
-        
-        # Here's where we differ from the superclass. It says:
-        # try:
-        #     sock = h._conn.sock
-        # except AttributeError:
-        #     sock = None
-        # return self._parse_response(h.getfile(), sock)
-        
-        return self.parse_response(h.getfile())
+        def request(self, host, handler, request_body, verbose=0):
+            # issue XML-RPC request
+            h = self.make_connection(host)
+            if verbose:
+                h.set_debuglevel(1)
+            
+            self.send_request(h, handler, request_body)
+            self.send_host(h, host)
+            self.send_user_agent(h)
+            self.send_content(h, request_body)
+            
+            errcode, errmsg, headers = h.getreply()
+            if errcode != 200:
+                raise ProtocolError(host + handler, errcode, errmsg, headers)
+            
+            self.verbose = verbose
+            
+            # Here's where we differ from the superclass. It says:
+            # try:
+            #     sock = h._conn.sock
+            # except AttributeError:
+            #     sock = None
+            # return self._parse_response(h.getfile(), sock)
+            
+            return self.parse_response(h.getfile())
 
 import cherrypy
 
     setup_server = staticmethod(setup_server)
     def testXmlRpc(self):
         
-        scheme = "http"
-        try:
-            scheme = self.harness.scheme
-        except AttributeError:
-            pass
-        
+        scheme = self.scheme
         if scheme == "https":
             url = 'https://%s:%s/xmlrpc/' % (self.interface(), self.PORT)
             proxy = ServerProxy(url, transport=HTTPSTransport())