extras-buildsys/common FileDownloader.py, 1.15, 1.15.2.1 HTTPSURLopener.py, 1.4, 1.4.4.1 SSLCommon.py, 1.10, 1.10.4.1 SSLConnection.py, 1.3, 1.3.4.1

Daniel Williams (dcbw) fedora-extras-commits at redhat.com
Fri Nov 18 15:13:17 UTC 2005


Author: dcbw

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

Modified Files:
      Tag: STABLE_0_4
	FileDownloader.py HTTPSURLopener.py SSLCommon.py 
	SSLConnection.py 
Log Message:
2005-11-18  Dan Williams  <dcbw at redhat.com>

    * common/SSLConnection.py
        - Fix behavior when socket timeout is set
        - Increase default socket timeout
        - Fix position of refcount decrease in close() so we
            actually close the socket now

    * common/SSLCommon.py
        - Add optional socket timeout parameter for PlgHTTPSConnection

    * common/HTTPSURLopener.py
        - Pass along a socket timeout, if specified

    * common/FileDownloader.py
        - Specify a socket timeout for download connections




Index: FileDownloader.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/common/FileDownloader.py,v
retrieving revision 1.15
retrieving revision 1.15.2.1
diff -u -r1.15 -r1.15.2.1
--- FileDownloader.py	16 Sep 2005 18:11:19 -0000	1.15
+++ FileDownloader.py	18 Nov 2005 15:13:15 -0000	1.15.2.1
@@ -87,7 +87,7 @@
         self._filename = get_base_filename_from_url(self._url, legal_exts)
 
         if certs and len(certs) > 0:
-            self._opener = HTTPSURLopener.HTTPSURLopener(certs)
+            self._opener = HTTPSURLopener.HTTPSURLopener(certs, 20)
         else:
             self._opener = urllib.URLopener()
         threading.Thread.__init__(self)


Index: HTTPSURLopener.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/common/HTTPSURLopener.py,v
retrieving revision 1.4
retrieving revision 1.4.4.1
diff -u -r1.4 -r1.4.4.1
--- HTTPSURLopener.py	6 Jul 2005 21:20:55 -0000	1.4
+++ HTTPSURLopener.py	18 Nov 2005 15:13:15 -0000	1.4.4.1
@@ -24,8 +24,9 @@
 
 
 class HTTPSURLopener(urllib.URLopener):
-    def __init__(self, certs):
+    def __init__(self, certs, timeout=None):
         self.ctx = SSLCommon.CreateSSLContext(certs)
+        self._timeout = timeout
         urllib.URLopener.__init__(self)
 
     def open_https(self, url, data=None):
@@ -43,7 +44,8 @@
         if not host:
             raise IOError, ('http error', 'no host given')
 
-        h = SSLCommon.PlgHTTPS(host=host, ssl_context=self.ctx)
+        h = SSLCommon.PlgHTTPS(host=host, ssl_context=self.ctx,
+                timeout=self._timeout)
 
         h.putrequest('GET', selector)
         for args in self.addheaders:


Index: SSLCommon.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/common/SSLCommon.py,v
retrieving revision 1.10
retrieving revision 1.10.4.1
diff -u -r1.10 -r1.10.4.1
--- SSLCommon.py	13 Jul 2005 15:21:05 -0000	1.10
+++ SSLCommon.py	18 Nov 2005 15:13:15 -0000	1.10.4.1
@@ -14,7 +14,7 @@
 #
 # Copyright 2005 Dan Williams <dcbw at redhat.com> and Red Hat, Inc.
 
-import os
+import os, sys
 import CommonErrors
 from OpenSSL import SSL
 import SSLConnection
@@ -93,14 +93,17 @@
 
     response_class = httplib.HTTPResponse
 
-    def __init__(self, host, port=None, ssl_context=None, strict=None):
+    def __init__(self, host, port=None, ssl_context=None, strict=None, timeout=None):
         httplib.HTTPConnection.__init__(self, host, port, strict)
         self.ssl_ctx = ssl_context
+        self._timeout = timeout
 
     def connect(self):
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         con = SSL.Connection(self.ssl_ctx, sock)
         self.sock = SSLConnection.SSLConnection(con)
+        if sys.version_info[:3] >= (2, 3, 0):
+            self.sock.settimeout(self._timeout)
         self.sock.connect((self.host, self.port))
 
 
@@ -114,6 +117,6 @@
 
     _connection_class = PlgHTTPSConnection
 
-    def __init__(self, host='', port=None, ssl_context=None, strict=None):
-        self._setup(self._connection_class(host, port, ssl_context, strict))
+    def __init__(self, host='', port=None, ssl_context=None, strict=None, timeout=None):
+        self._setup(self._connection_class(host, port, ssl_context, strict, timeout))
 


Index: SSLConnection.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/common/SSLConnection.py,v
retrieving revision 1.3
retrieving revision 1.3.4.1
diff -u -r1.3 -r1.3.4.1
--- SSLConnection.py	2 Aug 2005 00:58:16 -0000	1.3
+++ SSLConnection.py	18 Nov 2005 15:13:15 -0000	1.3.4.1
@@ -18,7 +18,7 @@
     passed in to the shutdown() method in SimpleXMLRPC.doPOST()
     """
 
-    DEFAULT_TIMEOUT = 10
+    DEFAULT_TIMEOUT = 20
 
     def __init__(self, conn):
         """
@@ -64,24 +64,32 @@
     def close(self):
         if self.__dict__["closed"]:
             return
+        self.__dict__["close_refcount"] = self.__dict__["close_refcount"] - 1
         if self.__dict__["close_refcount"] == 0:
             self.shutdown()
             self.__dict__["conn"].close()
             self.__dict__["closed"] = True
-        self.__dict__["close_refcount"] = self.__dict__["close_refcount"] - 1
     def sendall(self, data, flags=0):
         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)
             if self.__dict__["conn"] in write:
-                try:
-                    return self.__dict__["conn"].sendall(data, flags)
-                except SSL.SysCallError, e:
-                    if e[0] == 32:      # Broken Pipe
-                        self.close()
-                    else:
-                        raise socket.error(e)
+                starttime = time.time()
+                while True:
+                    try:
+                        return self.__dict__["conn"].sendall(data, flags)
+                    except SSL.SysCallError, e:
+                        if e[0] == 32:      # Broken Pipe
+                            self.close()
+                        else:
+                            raise socket.error(e)
+                    except SSL.WantWriteError:
+                        time.sleep(0.1)
+
+                    curtime = time.time()
+                    if curtime - starttime > self.DEFAULT_TIMEOUT:
+                        raise socket.timeout
             else:
                 raise socket.timeout
             if self.__dict__["conn"] in error:
@@ -93,10 +101,18 @@
             # to non-blocking mode
             (read, write, error) = select.select([self.__dict__["conn"]], [], [], self.DEFAULT_TIMEOUT)
             if self.__dict__["conn"] in read:
-                try:
-                    return self.__dict__["conn"].recv(bufsize, flags)
-                except SSL.ZeroReturnError:
-                    return None
+                starttime = time.time()
+                while True:
+                    try:
+                        return self.__dict__["conn"].recv(bufsize, flags)
+                    except SSL.ZeroReturnError:
+                        return None
+                    except SSL.WantReadError:
+                        time.sleep(0.1)
+
+                    curtime = time.time()
+                    if curtime - starttime > self.DEFAULT_TIMEOUT:
+                        raise socket.timeout
             else:
                 raise socket.timeout
             if self.__dict__["conn"] in error:




More information about the fedora-extras-commits mailing list