[Zope3-checkins] CVS: Zope3/src/zope/app/publication - http.py:1.8 browser.py:1.15 xmlrpc.py:1.11 zopepublication.py:1.42

Philipp von Weitershausen philikon at philikon.de
Sat Mar 20 08:37:46 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/publication
In directory cvs.zope.org:/tmp/cvs-serv639/src/zope/app/publication

Modified Files:
	http.py browser.py xmlrpc.py zopepublication.py 
Log Message:


Annotate extra information in transactions before committing. This is
task #2 of http://dev.zope.org/Zope3/SimplifyUndoModel.




=== Zope3/src/zope/app/publication/http.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/publication/http.py:1.7	Sat Mar 13 18:34:30 2004
+++ Zope3/src/zope/app/publication/http.py	Sat Mar 20 08:37:45 2004
@@ -20,8 +20,21 @@
 from zope.publisher.publish import mapply
 from zope.app.http.interfaces import IHTTPException
 
-class HTTPPublication(ZopePublication):
-    "HTTP-specific support"
+class BaseHTTPPublication(ZopePublication):
+    """Base for HTTP-based protocol publications"""
+
+    def annotateTransaction(self, txn, request, ob):
+        txn = super(BaseHTTPPublication, self).annotateTransaction(
+            txn, request, ob)
+        txn.setExtendedInfo('url', request.getURL())
+        txn.setExtendedInfo('method', request.method)
+        # XXX note the URL path for now until we have a new UI for the
+        # undo machinery
+        txn.note(request["PATH_INFO"])
+        return txn
+
+class HTTPPublication(BaseHTTPPublication):
+    """HTTP-specific publication"""
 
     def callObject(self, request, ob):
         # Exception handling, dont try to call request.method


=== Zope3/src/zope/app/publication/browser.py 1.14 => 1.15 ===
--- Zope3/src/zope/app/publication/browser.py:1.14	Wed Mar 17 13:24:25 2004
+++ Zope3/src/zope/app/publication/browser.py	Sat Mar 20 08:37:45 2004
@@ -19,7 +19,7 @@
 
 from zope.app.publication.publicationtraverse \
      import PublicationTraverser as PublicationTraverser_
-from zope.app.publication.zopepublication import ZopePublication
+from zope.app.publication.http import BaseHTTPPublication
 from zope.component import queryViewProviding
 from zope.proxy import removeAllProxies
 from zope.publisher.interfaces.browser import IBrowserPublisher
@@ -42,7 +42,7 @@
 
             ob = self.traversePath(request, ob, path)
 
-class BrowserPublication(ZopePublication):
+class BrowserPublication(BaseHTTPPublication):
     """Web browser publication handling."""
 
     def getDefaultTraversal(self, request, ob):
@@ -59,8 +59,8 @@
                 # ob is already proxied
                 return ob, None
 
-    def afterCall(self, request):
-        super(BrowserPublication, self).afterCall(request)
+    def afterCall(self, request, ob):
+        super(BrowserPublication, self).afterCall(request, ob)
         if request.method == 'HEAD':
             request.response.setBody('')
 


=== Zope3/src/zope/app/publication/xmlrpc.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/publication/xmlrpc.py:1.10	Fri Mar 19 15:26:29 2004
+++ Zope3/src/zope/app/publication/xmlrpc.py	Sat Mar 20 08:37:45 2004
@@ -17,13 +17,13 @@
 
 $Id$
 """
-from zope.app.publication.zopepublication import ZopePublication
 from zope.component import queryView, queryDefaultViewName
 from zope.proxy import removeAllProxies
 from zope.app.publisher.interfaces.xmlrpc import IXMLRPCPresentation
 from zope.security.checker import ProxyFactory
+from zope.app.publication.http import BaseHTTPPublication
 
-class XMLRPCPublication(ZopePublication):
+class XMLRPCPublication(BaseHTTPPublication):
     """XML-RPC publication handling."""
 
     def traverseName(self, request, ob, name):
@@ -75,7 +75,6 @@
 
         # See whether we have a subobject
         return super(XMLRPCPublication, self).traverseName(request, ob, name)
-
 
 # For now, have a factory that returns a singleton
 class XMLRPCPublicationFactory:


=== Zope3/src/zope/app/publication/zopepublication.py 1.41 => 1.42 ===
--- Zope3/src/zope/app/publication/zopepublication.py:1.41	Sat Mar 13 18:55:14 2004
+++ Zope3/src/zope/app/publication/zopepublication.py	Sat Mar 20 08:37:45 2004
@@ -11,51 +11,49 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+"""Zope publication
+
+$Id$
+"""
 import sys
 import logging
 
-from zope.component import queryView, queryDefaultViewName
-from zope.component import queryService
-from zope.app.servicenames import ErrorLogging, Authentication
 from ZODB.POSException import ConflictError
 
+from zope.interface import implements, providedBy
+from zope.component import queryService
 from zope.publisher.publish import mapply
 from zope.publisher.interfaces import Retry, IExceptionSideEffects
-from zope.publisher.interfaces.http import IHTTPRequest
+from zope.publisher.interfaces import IRequest, IPublication
 
 from zope.security.management import newSecurityManager
 from zope.security.checker import ProxyFactory
-
 from zope.proxy import removeAllProxies
-
-from zope.app.site.interfaces import ISite
-
 from zope.exceptions import Unauthorized
 
+from zope.app import zapi
+from zope.app.site.interfaces import ISite
 from zope.app.applicationcontrol.applicationcontrol \
      import applicationControllerRoot
 
+from zope.app.servicenames import ErrorLogging, Authentication
 from zope.app.security.principalregistry import principalRegistry as prin_reg
-
 from zope.app.security.interfaces import IUnauthenticatedPrincipal
-
 from zope.app.publication.publicationtraverse import PublicationTraverse
-
-# XXX Should this be imported here?
-from transaction import get_transaction
-
+from zope.app.traversing.interfaces import IPhysicallyLocatable
 from zope.app.location import LocationProxy
 
 class Cleanup(object):
+
     def __init__(self, f):
         self._f = f
 
     def __del__(self):
         self._f()
 
-
-class ZopePublication(object, PublicationTraverse):
+class ZopePublication(PublicationTraverse):
     """Base Zope publication specification."""
+    implements(IPublication)
 
     version_cookie = 'Zope-Version'
     root_name = 'Application'
@@ -121,7 +119,6 @@
         pass
 
     def getApplication(self, request):
-
         # If the first name is '++etc++process', then we should
         # get it rather than look in the database!
         stack = request.getTraversalStack()
@@ -150,18 +147,40 @@
     def callObject(self, request, ob):
         return mapply(ob, request.getPositionalArguments(), request)
 
-    def afterCall(self, request):
+    def afterCall(self, request, ob):
         txn = get_transaction()
-        if IHTTPRequest.providedBy(request):
-            txn.note(request["PATH_INFO"])
-        # XXX not sure why you would use id vs title or description
+        self.annotateTransaction(txn, request, ob)
+        txn.commit()
+
+    def annotateTransaction(self, txn, request, ob):
+        """Set some useful meta-information on the transaction. This
+        information is used by the undo framework, for example.
+
+        This method is not part of the IPublication interface, since
+        it's specific to this particular implementation.
+        """
         txn.setUser(request.user.id)
-        get_transaction().commit()
 
+        # set the location path
+        path = None
+        locatable = IPhysicallyLocatable(ob, None)
+        if locatable is not None:
+            path = locatable.getPath()
+        txn.setExtendedInfo('location', path)
+
+        # set the request type
+        iface = IRequest
+        for iface in providedBy(request):
+            if iface.extends(IRequest):
+                break
+        iface_dotted = iface.__module__ + '.' + iface.getName()
+        txn.setExtendedInfo('request_type', iface_dotted)
+        return txn
 
     def _logErrorWithErrorReportingService(self, object, request, exc_info):
         # Record the error with the ErrorReportingService
-        beginErrorHandlingTransaction(request, 'error reporting service')
+        self.beginErrorHandlingTransaction(request, object,
+                                           'error reporting service')
         try:
             errService = queryService(object, ErrorLogging)
             if errService is not None:
@@ -225,8 +244,8 @@
         else:
             # We definitely have an Exception
             # Set the request body, and abort the current transaction.
-            beginErrorHandlingTransaction(
-                request, 'application error-handling')
+            self.beginErrorHandlingTransaction(
+                request, object, 'application error-handling')
             view = None
             try:
 
@@ -246,9 +265,9 @@
                     loc = ProxyFactory(loc)
                 
                 exception = LocationProxy(exc_info[1], loc)
-                name = queryDefaultViewName(exception, request, context=object)
+                name = zapi.queryDefaultViewName(exception, request, context=object)
                 if name is not None:
-                    view = queryView(exception, name, request, context=object)
+                    view = zapi.queryView(exception, name, request, context=object)
             except:
                 # Problem getting a view for this exception. Log an error.
                 tryToLogException(
@@ -287,8 +306,8 @@
                 adapter = None
 
             if adapter is not None:
-                beginErrorHandlingTransaction(
-                    request, 'application error-handling side-effect')
+                self.beginErrorHandlingTransaction(
+                    request, object, 'application error-handling side-effect')
                 try:
                     # Although request is passed in here, it should be
                     # considered read-only.
@@ -300,6 +319,13 @@
                         ' IExceptionSideEffects adapter')
                     get_transaction().abort()
 
+    def beginErrorHandlingTransaction(self, request, ob, note):
+        txn = get_transaction()
+        txn.begin()
+        txn.note(note)
+        self.annotateTransaction(txn, request, ob)
+        return txn
+
     def _parameterSetskin(self, pname, pval, request):
         request.setPresentationSkin(pval)
 
@@ -330,12 +356,3 @@
     # logging a warning.
     except:
         pass
-
-def beginErrorHandlingTransaction(request, note):
-    get_transaction().begin()
-    if IHTTPRequest.providedBy(request):
-        pathnote = '%s ' % request["PATH_INFO"]
-    else:
-        pathnote = ''
-    get_transaction().note(
-        '%s(%s)' % (pathnote, note))




More information about the Zope3-Checkins mailing list