[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher - minitest.py:1.1.2.1 BaseRequest.py:1.1.2.4 BaseResponse.py:1.1.2.3 DefaultPublication.py:1.1.2.2 Exceptions.py:1.1.2.4 IPublication.py:1.1.2.4 Publish.py:1.1.2.4

Shane Hathaway shane@digicool.com
Thu, 15 Nov 2001 14:28:51 -0500


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

Modified Files:
      Tag: Zope-3x-branch
	BaseRequest.py BaseResponse.py DefaultPublication.py 
	Exceptions.py IPublication.py Publish.py 
Added Files:
      Tag: Zope-3x-branch
	minitest.py 
Log Message:
Added a minitest module to ensure everything works.  Bugfixes:

- Missed attributes, misspelled signatures, etc.

- Print module name instead of filename in tracebacks--this could be
  backported to Zope 2.x easily.

- publication.handleException() has to return a response object

- Include SERVER_URL in request.__str__()


=== Added File Zope3/lib/python/Zope/Publisher/minitest.py ===

# To run, use:
# PYTHONPATH=../.. python minitest.py /x/y

import sys

from Zope.Publisher.Publish import publish
from Zope.Publisher.DefaultPublication import DefaultPublication
from Zope.Publisher.HTTP.HTTPRequest import HTTPRequest
from Zope.Publisher.HTTP.HTTPResponse import HTTPResponse

class c:
    " "
    def __call__(self, URL):
        return 'You invoked URL %s\n' % URL

ob = c()
ob.x = c()
ob.x.y = c()

response = HTTPResponse(sys.stdout)
environ = {
    'SERVER_NAME': 'test',
    'PATH_INFO': sys.argv[1]
    }
request = HTTPRequest(sys.stdin, environ, response)
publication = DefaultPublication(ob)
publish(publication, request)



=== Zope3/lib/python/Zope/Publisher/BaseRequest.py 1.1.2.3 => 1.1.2.4 ===
     body_instream = None  # The body input stream
     common = {}           # Data common to all requests
+    args = ()             # Positional arguments
 
     # _held contains objects kept until the request is closed,
     # such as the database connection closer.
@@ -60,7 +61,6 @@
         self.steps = []
         self.quoted_steps = []
         self.other = {}
-        self.other.update(mapping)
         self.response = response
 
     def close(self):
@@ -81,11 +81,11 @@
         return self
     _key_handlers['REQUEST'] = getRequest
 
-    def getURL(self, default):
+    def getURL(self, default=None):
         return self.URL
     _key_handlers['URL'] = getURL
 
-    def getBody(self, default):
+    def getBody(self, default=None):
         body = self._body
         if body is None:
             s = self.body_instream
@@ -99,7 +99,7 @@
         return body
     _key_handlers['BODY'] = getBody
 
-    def getBodyFile(self, default):
+    def getBodyFile(self, default=None):
         return self.body_instream
     _key_handlers['BODYFILE'] = getBodyFile
 
@@ -163,7 +163,8 @@
 
     def __repr__(self):
         # Returns a *short* string.
-        return '<%s instance, URL=%s>' % (str(self.__class__), self.URL)
+        return '<%s instance at 0x%x, URL=%s>' % (
+            str(self.__class__), id(self), `self.URL`)
 
     def splitPath(self, path):
         # Split and clean up the path.
@@ -293,7 +294,6 @@
         self.traversed = tuple(traversed)  # No more changes allowed
         parents = traversed[:]
         parents.pop()
-        del parents[-1]
         parents.reverse()
         self.other['PARENTS'] = tuple(parents)
         self.other['PUBLISHED'] = object


=== Zope3/lib/python/Zope/Publisher/BaseResponse.py 1.1.2.2 => 1.1.2.3 ===
 __version__='$Revision$'[11:-2]
 
-from zExceptions import Unauthorized
+from Zope.zExceptions import Unauthorized
 
 class BaseResponse:
     """Base Response Class
@@ -12,6 +12,7 @@
     What should be here?
     """
     debug_mode=None
+    status = None         # The response status (usually an integer)
     #_auth=None
     #_error_format='text/plain'
     


=== Zope3/lib/python/Zope/Publisher/DefaultPublication.py 1.1.2.1 => 1.1.2.2 ===
 from IPublication import IPublication
-from Exceptions import NotFound, Unauthorized
+from Exceptions import NotFound, DebugError, Unauthorized
 from mapply import mapply
 
 class DefaultPublication:
@@ -29,7 +29,7 @@
                 subob = ob[name]
             except (KeyError, IndexError,
                     TypeError, AttributeError):
-                raise NotFound(ob, name)
+                raise NotFound(ob, name, request.getURL())
         if not getattr(subob, '__doc__', None):
             raise DebugError(subob, 'Missing or empty doc string at: %s' %
                              request.getURL())
@@ -47,7 +47,9 @@
     def postPublish(self, request):
         pass
 
-    def handleException(request, exc):
+    def handleException(self, request, exc, retry_allowed=1):
         # Let the response handle it as best it can.
-        request.response.handleException(exc)
+        response = request.response
+        response.handleException(exc)
+        return response
 


=== Zope3/lib/python/Zope/Publisher/Exceptions.py 1.1.2.3 => 1.1.2.4 ===
     """
     """
-    def __init__(self, ob, name):
+    def __init__(self, ob, name, url=None):
         self.ob = ob
         self.name = name
+        self.url = url
 
     def getObject(self):
         return self.ob
@@ -27,7 +28,10 @@
         return self.name
 
     def __str__(self):
-        return 'Object: %s, name: %s' % (`self.ob`, `self.name`)
+        if self.url:
+            return self.url
+        else:
+            return 'Object: %s, name: %s' % (`self.ob`, `self.name`)
 
 
 class DebugError (TraversalException):


=== Zope3/lib/python/Zope/Publisher/IPublication.py 1.1.2.3 => 1.1.2.4 ===
         - raises a Retry exception, or
         - throws another exception, which is a Bad Thing.
+        Returns the response object.
         """
 


=== Zope3/lib/python/Zope/Publisher/Publish.py 1.1.2.3 => 1.1.2.4 ===
         #if transactions_manager: transactions_manager.begin()
     
-        object = publication.getApplication()
+        object = publication.getApplication(request)
         path_str = request.get('PATH_INFO', '').strip()
         object = request.traverse(publication, object, path_str)
     
@@ -47,7 +47,7 @@
         try:
             exc = sys.exc_info()
             try:
-                publication.handleException(request, exc)
+                return publication.handleException(request, exc)
             except Retry:
                 # The exception handler requested a retry.
                 if not request.supports_retry():
@@ -72,12 +72,12 @@
         except SystemExit, v:
             # Output and re-raise
             to_raise = sys.exc_info()
-            publication.handleException(request, to_raise, 0)
+            response = publication.handleException(request, to_raise, 0)
         except:
             # Output but don't re-raise
             exc = sys.exc_info()
             try:
-                publication.handleException(request, exc, 0)
+                response = publication.handleException(request, exc, 0)
             finally:
                 exc = None  # Avoid circ. ref