[Zope-CVS] CVS: Packages/FunctionalTests/FunctionalTests - Request.py:1.7

Tres Seaver tseaver@zope.com
Sun, 15 Jun 2003 06:01:26 -0400


Update of /cvs-repository/Packages/FunctionalTests/FunctionalTests
In directory cvs.zope.org:/tmp/cvs-serv444/FunctionalTests

Modified Files:
	Request.py 
Log Message:


  - Record exceptions in connecting to a URL as "600" response codes
    instead of throwing a traceback which suppresses knowledge of the
    broken host / port.


=== Packages/FunctionalTests/FunctionalTests/Request.py 1.6 => 1.7 ===
--- Packages/FunctionalTests/FunctionalTests/Request.py:1.6	Fri Jun 13 23:22:55 2003
+++ Packages/FunctionalTests/FunctionalTests/Request.py	Sun Jun 15 06:01:25 2003
@@ -428,38 +428,47 @@
             invocation.beginRequest()
 
         host, port = self.getHost(), self.getPort()
-        connection = httplib.HTTP( host, port )
-        connection.putrequest( self.getMethod(), self.getURI() )
-        connection.putheader( 'Host', '%s:%d' % ( host, port ) )
-
-        token = self.getAuthenticationToken()
-        if token:
-            scrambled = base64.encodestring( token )
-            connection.putheader( 'Authorization', 'Basic %s' % scrambled )
-
-        for key, value in self.getHeaders():
-            connection.putheader( key, value )
-
-        for key, value in self.getCookies():
-            connection.putheader( 'Cookie', '%s=%s' % ( key, value ) )
-
-        for cookie in result.getCookies():
-            connection.putheader( 'Cookie'
-                                , cookie.output( header='', attrs=[] ) )
-
-        data = self.getData()
-        if data:
-            connection.putheader( 'Content-length', str( len( data ) ) )
-            connection.putheader( 'Content-type', self.getContentType() )
-
-        connection.endheaders()
-
-        if data:
-            connection.send( data )
-
-        code, message, headers = connection.getreply()
-        payload = connection.getfile().read()
-        invocation.update( code, message, headers, payload )
+        try:
+            connection = httplib.HTTP( host, port )
+            connection.putrequest( self.getMethod(), self.getURI() )
+            connection.putheader( 'Host', '%s:%d' % ( host, port ) )
+
+            token = self.getAuthenticationToken()
+            if token:
+                scrambled = base64.encodestring( token )
+                connection.putheader( 'Authorization', 'Basic %s' % scrambled )
+
+            for key, value in self.getHeaders():
+                connection.putheader( key, value )
+
+            for key, value in self.getCookies():
+                connection.putheader( 'Cookie', '%s=%s' % ( key, value ) )
+
+            for cookie in result.getCookies():
+                connection.putheader( 'Cookie'
+                                    , cookie.output( header='', attrs=[] ) )
+
+            data = self.getData()
+            if data:
+                connection.putheader( 'Content-length', str( len( data ) ) )
+                connection.putheader( 'Content-type', self.getContentType() )
+
+            connection.endheaders()
+
+            if data:
+                connection.send( data )
+
+            code, message, headers = connection.getreply()
+            payload = connection.getfile().read()
+            invocation.update( code, message, headers, payload )
+
+        except Exception, msg:
+
+            result.logError( 'Exception: %s' % msg )
+            from StringIO import StringIO
+            import rfc822
+            invocation.update( 600, 'FAILED', rfc822.Message( StringIO() ), '' )
+            
 
         if result.timeRequests():
             invocation.endRequest()