[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/HTTP - DefaultPublisher.py:1.1.2.3 HTTPRequest.py:1.1.2.26 HTTPResponse.py:1.1.2.18

Shane Hathaway shane@cvs.zope.org
Fri, 12 Apr 2002 17:31:24 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/HTTP
In directory cvs.zope.org:/tmp/cvs-serv20835/lib/python/Zope/Publisher/HTTP

Modified Files:
      Tag: Zope-3x-branch
	DefaultPublisher.py HTTPRequest.py HTTPResponse.py 
Log Message:
Merged Zope3-Server-Branch.


=== Zope3/lib/python/Zope/Publisher/HTTP/DefaultPublisher.py 1.1.2.2 => 1.1.2.3 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-from IHTTPPublisher import IHTTPPublisher
-
-
-class DefaultPublisher:
-
-    __implements__ =  IHTTPPublisher
-
-    ############################################################
-    # Implementation methods for interface
-    # Zope.Publisher.HTTP.IHTTPPublisher
-
-    def publishTraverse(self, request, name):
-        'See Zope.Publisher.HTTP.IHTTPPublisher.IHTTPPublisher'
-
-        return getattr(self, name)
-
-    #
-    ############################################################
+"""blisher.py,v 1.1.2.2 2002/04/02 02:20:33 srichter Exp $
+"""
+from IHTTPPublisher import IHTTPPublisher
+
+
+class DefaultPublisher:
+
+    __implements__ =  IHTTPPublisher
+
+    ############################################################
+    # Implementation methods for interface
+    # Zope.Publisher.HTTP.IHTTPPublisher
+
+    def publishTraverse(self, request, name):
+        'See Zope.Publisher.HTTP.IHTTPPublisher.IHTTPPublisher'
+
+        return getattr(self, name)
+
+    #
+    ############################################################


=== Zope3/lib/python/Zope/Publisher/HTTP/HTTPRequest.py 1.1.2.25 => 1.1.2.26 ===
         '_app_server',    # The server path of the application url
         '_orig_env',      # The original environment
-        '_endswithslash'  # Does the given path end with /
+        '_endswithslash', # Does the given path end with /
         )
 
     retry_max_count = 3    # How many times we're willing to retry
 
-    def __init__(self, body_instream, outstream, environ):
+    def __init__(self, body_instream, outstream, environ, response=None):
 
-        super(HTTPRequest, self).__init__(body_instream, outstream, environ)
+        super(HTTPRequest, self).__init__(
+            body_instream, outstream, environ, response)
 
         self._orig_env = environ
         environ = sane_environment(environ)
@@ -293,22 +294,27 @@
 
     def supportsRetry(self):
         'See Zope.Publisher.IPublisherRequest.IPublisherRequest'
-        if self._retry_count < self.retry_max_count:
+        count = getattr(self, '_retry_count', 0)
+        if count < self.retry_max_count:
             if STAGGER_RETRIES:
-                time.sleep(random.uniform(0, 2**(self.retry_count)))
+                time.sleep(random.uniform(0, 2**(count)))
             return 1
 
 
     def retry(self):
         'See Zope.Publisher.IPublisherRequest.IPublisherRequest'
-        self.retry_count = self.retry_count + 1
-        self.body_instream.seek(0)
+        count = getattr(self, '_retry_count', 0)
+        self._retry_count = count + 1
+        self._body_instream.seek(0)
+        new_response = self.getResponse().retry()
         request = self.__class__(
-            body_instream = self._body_instream,
-            outstream = self.getResponse().getOutputStream(),
-            environ = self._orig_env
+            body_instream=self._body_instream,
+            outstream=None,
+            environ=self._orig_env,
+            response=new_response,
             )
-        request.retry_count = self.retry_count
+        request.setPublication(self.getPublication())
+        request._retry_count = self._retry_count
         return request
 
 


=== Zope3/lib/python/Zope/Publisher/HTTP/HTTPResponse.py 1.1.2.17 => 1.1.2.18 ===
         '_wrote_headers',
         '_streaming',
-        '_status',      # The response status (usually an integer)
-        '_reason'       # The reason that goes with the status
+        '_status',              # The response status (usually an integer)
+        '_reason',              # The reason that goes with the status
+        '_status_set',          # Boolean: status explicitly set
         )
 
 
@@ -121,8 +122,9 @@
         self._accumulated_headers = []
         self._wrote_headers = 0
         self._streaming = 0
-        self._status = 200
-        self._reason = 'Ok'
+        self._status = 599
+        self._reason = 'No status set'
+        self._status_set = 0
 
 
     def setHeaderOutput(self, header_output):
@@ -143,7 +145,7 @@
             if status_codes.has_key(status):
                 status = status_codes[status]
             else:
-                status=500
+                status = 500
         self._status = status
 
         if reason is None:
@@ -154,6 +156,7 @@
             else:
                 reason = 'Unknown'
         self._reason = reason
+        self._status_set = 1
 
 
     def getStatus(self):
@@ -261,6 +264,11 @@
     ######################################
     # from: Zope.Publisher.IPublisherResponse.IPublisherResponse
 
+    def setBody(self, body):
+        self._body = body
+        if not self._status_set:
+            self.setStatus(200)
+
     def handleException(self, exc_info):
         """
         Calls self.setBody() with an error response.
@@ -283,6 +291,11 @@
         self.setBody(body)
 
 
+    def internalError(self):
+        'See Zope.Publisher.IPublisherResponse.IPublisherResponse'
+        self.setStatus(500, "The engines can't take any more, Jim!")
+
+
     def _html(self, title, content):
         t = escape(title)
         return (
@@ -292,9 +305,6 @@
             "</body></html>\n" %
             (t, t, content)
             )
-
-
-
 
 
     def retry(self):