Source

CherryPy / cherrypy / test / test_xmlrpc.py

Diff from to

cherrypy/test/test_xmlrpc.py

 from cherrypy.test import test
 test.prefer_parent_path()
 import xmlrpclib
+import sys
 
 import cherrypy
 
     root.xmlrpc = XmlRpc()
     cherrypy.tree.mount(root, config={'/': {
         'request.dispatch': cherrypy.dispatch.XMLRPCDispatcher(),
+        'tools.xmlrpc.allow_none': 0,
         }})
     cherrypy.config.update({'environment': 'test_suite'})
 
 
-class HTTPSTransport(xmlrpclib.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)
-        
-        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())
+if sys.version_info <= (2, 6):
+    class HTTPSTransport(xmlrpclib.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)
+
+            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())
+else:
+    class HTTPSTransport(xmlrpclib.SafeTransport):
+        pass
 
 from cherrypy.test import helper
 
         except AttributeError:
             pass
         
-        host = self.HOST
-        if host == '0.0.0.0':
-            # INADDR_ANY, which should respond on localhost.
-            host = "127.0.0.1"
-        if host == '::':
-            # IN6ADDR_ANY, which should respond on localhost.
-            host = "::1"
-        
         if scheme == "https":
-            url = 'https://%s:%s/xmlrpc/' % (host, self.PORT)
+            url = 'https://%s:%s/xmlrpc/' % (self.interface(), self.PORT)
             proxy = xmlrpclib.ServerProxy(url, transport=HTTPSTransport())
         else:
-            url = 'http://%s:%s/xmlrpc/' % (host, self.PORT)
+            url = 'http://%s:%s/xmlrpc/' % (self.interface(), self.PORT)
             proxy = xmlrpclib.ServerProxy(url)
         
         # begin the tests ...