extras-buildsys/common XMLRPCServerProxy.py,1.9,1.10

Daniel Williams (dcbw) fedora-extras-commits at redhat.com
Tue May 16 15:47:21 UTC 2006


Author: dcbw

Update of /cvs/fedora/extras-buildsys/common
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv26503/common

Modified Files:
	XMLRPCServerProxy.py 
Log Message:
2006-05-16  Dan Williams  <dcbw at redhat.com>

    * common/XMLRPCServerProxy.py
        - Add cancellation ability to requests




Index: XMLRPCServerProxy.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/common/XMLRPCServerProxy.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- XMLRPCServerProxy.py	15 Feb 2006 17:07:07 -0000	1.9
+++ XMLRPCServerProxy.py	16 May 2006 15:47:13 -0000	1.10
@@ -28,6 +28,7 @@
     def __init__(self, ssl_context, timeout=None):
         self.ssl_ctx=ssl_context
         self._timeout = timeout
+        self._https = None
 
     def make_connection(self, host):
         # Handle username and password.
@@ -37,17 +38,44 @@
             # Yay for Python 2.2
             pass
         _host, _port = urllib.splitport(host)
-        return SSLCommon.PlgHTTPS(_host, int(_port), ssl_context=self.ssl_ctx, timeout=self._timeout)
+        self._https = SSLCommon.PlgHTTPS(_host, int(_port), ssl_context=self.ssl_ctx, timeout=self._timeout)
+        return self._https
+
+    def close(self):
+        if self._https:
+            self._https.close()
+            self._https = None
+
+
+class Plg_ClosableTransport(xmlrpclib.Transport):
+    """Override make_connection so we can close it."""
+    def __init__(self):
+        self._http = None
+
+    def make_connection(self, host):
+        # create a HTTP connection object from a host descriptor
+        import httplib
+        host, extra_headers, x509 = self.get_host_info(host)
+        self._http = httplib.HTTP(host)
+        return self._http
+
+    def close(self):
+        if self._http:
+            self._http.close()
+            self._http = None
 
 
 class PlgXMLRPCServerProxy(xmlrpclib.ServerProxy):
     def __init__(self, uri, certs, timeout=None):
         if certs and len(certs) > 0:
             self.ctx = SSLCommon.CreateSSLContext(certs)
-            xmlrpclib.ServerProxy.__init__(self, uri, PlgSSL_Transport(ssl_context=self.ctx, timeout=timeout))
+            self._transport = PlgSSL_Transport(ssl_context=self.ctx, timeout=timeout)
         else:
-            xmlrpclib.ServerProxy.__init__(self, uri)
+            self._transport = Plg_ClosableTransport()
+        xmlrpclib.ServerProxy.__init__(self, uri, transport=self._transport)
 
+    def cancel(self):
+        self._transport.close()
 
 
 ###########################################################




More information about the fedora-extras-commits mailing list