extras-buildsys/common AuthedXMLRPCServer.py, 1.6, 1.7 SSLCommon.py, 1.11, 1.12 SSLConnection.py, 1.4, 1.5 XMLRPCServerProxy.py, 1.5, 1.6

Daniel Williams (dcbw) fedora-extras-commits at redhat.com
Fri Nov 25 04:45:09 UTC 2005


Author: dcbw

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

Modified Files:
	AuthedXMLRPCServer.py SSLCommon.py SSLConnection.py 
	XMLRPCServerProxy.py 
Log Message:
2005-11-24  Dan Williams  <dcbw at redhat.com>

    * client/client.py
      server/Builder.py
      www/template/main.psp
        - Use timeouts for XMLRPC clients

2005-11-24  Dan Williams  <dcbw at redhat.com>

    * common/AuthedXMLRPMServer.py
      common/SSLCommon.py
      common/SSLConnection.py
      common/XMLRPCServerProxy.py
        - Implement socket timeouts for XMLRPC client & server




Index: AuthedXMLRPCServer.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/common/AuthedXMLRPCServer.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AuthedXMLRPCServer.py	2 Aug 2005 00:58:16 -0000	1.6
+++ AuthedXMLRPCServer.py	25 Nov 2005 04:45:07 -0000	1.7
@@ -86,9 +86,9 @@
 class AuthedSSLXMLRPCServer(BaseAuthedXMLRPCServer, SSLCommon.PlgBaseSSLServer, SimpleXMLRPCServer.SimpleXMLRPCServer):
     """ Extension to allow more fine-tuned SSL handling """
 
-    def __init__(self, address, authinfo_callback=None, certs=None):
+    def __init__(self, address, authinfo_callback=None, certs=None, timeout=None):
         BaseAuthedXMLRPCServer.__init__(self, address, authinfo_callback)
-        SSLCommon.PlgBaseSSLServer.__init__(self, address, AuthedSimpleXMLRPCRequestHandler, certs)
+        SSLCommon.PlgBaseSSLServer.__init__(self, address, AuthedSimpleXMLRPCRequestHandler, certs, timeout=timeout)
 
 
 class AuthedXMLRPCServer(BaseAuthedXMLRPCServer, SSLCommon.PlgBaseServer, SimpleXMLRPCServer.SimpleXMLRPCServer):


Index: SSLCommon.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/common/SSLCommon.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SSLCommon.py	18 Nov 2005 15:11:27 -0000	1.11
+++ SSLCommon.py	25 Nov 2005 04:45:07 -0000	1.12
@@ -71,8 +71,8 @@
 class PlgBaseSSLServer(PlgBaseServer):
     """ SSL-enabled variant """
 
-    def __init__(self, server_address, req_handler, certs):
-        
+    def __init__(self, server_address, req_handler, certs, timeout=None):
+        self._timeout = timeout
         self.ssl_ctx = CreateSSLContext(certs)
 
         SocketServer.BaseServer.__init__(self, server_address, req_handler)
@@ -80,6 +80,8 @@
         sock = socket.socket(self.address_family, self.socket_type)
         con = SSL.Connection(self.ssl_ctx, sock)
         self.socket = SSLConnection.SSLConnection(con)
+        if sys.version_info[:3] >= (2, 3, 0):
+            self.socket.settimeout(self._timeout)
         self.server_bind()
         self.server_activate()
 


Index: SSLConnection.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/common/SSLConnection.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SSLConnection.py	18 Nov 2005 15:11:27 -0000	1.4
+++ SSLConnection.py	25 Nov 2005 04:45:07 -0000	1.5
@@ -28,12 +28,19 @@
         self.__dict__["conn"] = conn
         self.__dict__["close_refcount"] = 0
         self.__dict__["closed"] = False
+        self.__dict__["timeout"] = self.DEFAULT_TIMEOUT
     def __del__(self):
         self.__dict__["conn"].close()
     def __getattr__(self,name):
         return getattr(self.__dict__["conn"], name)
     def __setattr__(self,name, value):
         setattr(self.__dict__["conn"], name, value)
+    def settimeout(self, timeout):
+        if timeout == None:
+            self.__dict__["timeout"] = self.DEFAULT_TIMEOUT
+        else:
+            self.__dict__["timeout"] = timeout
+        self.__dict__["conn"].settimeout(timeout)
     def shutdown(self, how=1):
         """
         SimpleXMLRpcServer.doPOST calls shutdown(1),
@@ -73,7 +80,7 @@
         while True:
             # Use select() to simulate a socket timeout without setting the socket
             # to non-blocking mode
-            (read, write, error) = select.select([], [self.__dict__["conn"]], [], self.DEFAULT_TIMEOUT)
+            (read, write, error) = select.select([], [self.__dict__["conn"]], [], self.__dict__["timeout"])
             if self.__dict__["conn"] in write:
                 starttime = time.time()
                 while True:
@@ -88,7 +95,7 @@
                         time.sleep(0.1)
 
                     curtime = time.time()
-                    if curtime - starttime > self.DEFAULT_TIMEOUT:
+                    if curtime - starttime > self.__dict__["timeout"]:
                         raise socket.timeout
             else:
                 raise socket.timeout
@@ -99,7 +106,7 @@
         while True:
             # Use select() to simulate a socket timeout without setting the socket
             # to non-blocking mode
-            (read, write, error) = select.select([self.__dict__["conn"]], [], [], self.DEFAULT_TIMEOUT)
+            (read, write, error) = select.select([self.__dict__["conn"]], [], [], self.__dict__["timeout"])
             if self.__dict__["conn"] in read:
                 starttime = time.time()
                 while True:
@@ -111,7 +118,7 @@
                         time.sleep(0.1)
 
                     curtime = time.time()
-                    if curtime - starttime > self.DEFAULT_TIMEOUT:
+                    if curtime - starttime > self.__dict__["timeout"]:
                         raise socket.timeout
             else:
                 raise socket.timeout


Index: XMLRPCServerProxy.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/common/XMLRPCServerProxy.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XMLRPCServerProxy.py	11 Jul 2005 03:46:15 -0000	1.5
+++ XMLRPCServerProxy.py	25 Nov 2005 04:45:07 -0000	1.6
@@ -25,8 +25,9 @@
 
     user_agent = "pyOpenSSL_XMLRPC/%s - %s" % (__version__, xmlrpclib.Transport.user_agent)
 
-    def __init__(self, ssl_context):
+    def __init__(self, ssl_context, timeout=None):
         self.ssl_ctx=ssl_context
+        self._timeout = timeout
 
     def make_connection(self, host):
         # Handle username and password.
@@ -36,14 +37,14 @@
             # Yay for Python 2.2
             pass
         _host, _port = urllib.splitport(host)
-        return SSLCommon.PlgHTTPS(_host, int(_port), ssl_context=self.ssl_ctx)
+        return SSLCommon.PlgHTTPS(_host, int(_port), ssl_context=self.ssl_ctx, timeout=self._timeout)
 
 
 class PlgXMLRPCServerProxy(xmlrpclib.ServerProxy):
-    def __init__(self, uri, certs):
+    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))
+            xmlrpclib.ServerProxy.__init__(self, uri, PlgSSL_Transport(ssl_context=self.ctx, timeout=timeout))
         else:
             xmlrpclib.ServerProxy.__init__(self, uri)
 
@@ -64,7 +65,7 @@
 
 class TestClient(threading.Thread):
     def __init__(self, certs):
-        self.server = PlgXMLRPCServerProxy("https://127.0.0.1:8886", certs)
+        self.server = PlgXMLRPCServerProxy("https://127.0.0.1:8886", certs, timeout=20)
         threading.Thread.__init__(self)
 
     def run(self):




More information about the fedora-extras-commits mailing list