[Checkins] SVN: Sandbox/shane/republish/zope/ improved b/w compat

Shane Hathaway shane at hathawaymix.org
Tue Feb 10 16:44:23 EST 2009


Log message for revision 96424:
  improved b/w compat
  

Changed:
  A   Sandbox/shane/republish/zope/__init__.py
  A   Sandbox/shane/republish/zope/complextraversal/
  A   Sandbox/shane/republish/zope/complextraversal/browser.py
  A   Sandbox/shane/republish/zope/complextraversal/interfaces.py
  A   Sandbox/shane/republish/zope/publisher/__init__.py
  A   Sandbox/shane/republish/zope/publisher/interfaces/__init__.py
  U   Sandbox/shane/republish/zope/publisher/interfaces/base.py
  U   Sandbox/shane/republish/zope/publisher/interfaces/browser.py
  D   Sandbox/shane/republish/zope/publisher/interfaces/complextraversal.py
  U   Sandbox/shane/republish/zope/publisher/interfaces/exceptions.py
  A   Sandbox/shane/republish/zope/publisher/interfaces/ftp.py
  U   Sandbox/shane/republish/zope/publisher/interfaces/http.py
  A   Sandbox/shane/republish/zope/publisher/interfaces/xmlrpc.py

-=-
Added: Sandbox/shane/republish/zope/__init__.py
===================================================================
--- Sandbox/shane/republish/zope/__init__.py	                        (rev 0)
+++ Sandbox/shane/republish/zope/__init__.py	2009-02-10 21:44:22 UTC (rev 96424)
@@ -0,0 +1,7 @@
+# this is a namespace package
+try:
+    import pkg_resources
+    pkg_resources.declare_namespace(__name__)
+except ImportError:
+    import pkgutil
+    __path__ = pkgutil.extend_path(__path__, __name__)

Added: Sandbox/shane/republish/zope/complextraversal/browser.py
===================================================================
--- Sandbox/shane/republish/zope/complextraversal/browser.py	                        (rev 0)
+++ Sandbox/shane/republish/zope/complextraversal/browser.py	2009-02-10 21:44:22 UTC (rev 96424)
@@ -0,0 +1,100 @@
+
+
+from zope.location import Location
+
+from zope.complextraversal.interfaces import IBrowserView
+from zope.complextraversal.interfaces import IBrowserPage
+
+
+class BrowserView(Location):
+    """Browser View.
+
+    >>> view = BrowserView("context", "request")
+    >>> view.context
+    'context'
+    >>> view.request
+    'request'
+
+    >>> view.__parent__
+    'context'
+    >>> view.__parent__ = "parent"
+    >>> view.__parent__
+    'parent'
+    """
+    implements(IBrowserView)
+
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
+
+    def __getParent(self):
+        return getattr(self, '_parent', self.context)
+
+    def __setParent(self, parent):
+        self._parent = parent
+
+    __parent__ = property(__getParent, __setParent)
+
+
+class BrowserPage(BrowserView):
+    """Browser page
+
+    To create a page, which is an object that is published as a page,
+    you need to provide an object that:
+
+    - has a __call__ method and that
+
+    - provides IBrowserPublisher, and
+
+    - if ZPT is going to be used, then your object should also provide
+      request and context attributes.
+
+    The BrowserPage base class provides a standard constructor and a
+    simple implementation of IBrowserPublisher:
+
+      >>> class MyPage(BrowserPage):
+      ...     pass
+
+      >>> request = TestRequest()
+      >>> context = object()
+      >>> page = MyPage(context, request)
+
+      >>> from zope.publisher.interfaces.browser import IBrowserPublisher
+      >>> IBrowserPublisher.providedBy(page)
+      True
+
+      >>> page.browserDefault(request) == (page, ())
+      True
+
+      >>> page.publishTraverse(request, 'bob') # doctest: +ELLIPSIS
+      Traceback (most recent call last):
+      ...
+      NotFound: Object: <zope.publisher.browser.MyPage object at ...>, name: 'bob'
+
+      >>> page.request is request
+      True
+
+      >>> page.context is context
+      True
+
+    But it doesn't supply a __call__ method:
+
+      >>> page()
+      Traceback (most recent call last):
+        ...
+      NotImplementedError: Subclasses should override __call__ to provide a response body
+
+    It is the subclass' responsibility to do that.
+
+    """
+    implements(IBrowserPage)
+
+    def browserDefault(self, request):
+        return self, ()
+
+    def publishTraverse(self, request, name):
+        raise NotFound(self, name, request)
+
+    def __call__(self, *args, **kw):
+        raise NotImplementedError("Subclasses should override __call__ to "
+                                  "provide a response body")

Added: Sandbox/shane/republish/zope/complextraversal/interfaces.py
===================================================================
--- Sandbox/shane/republish/zope/complextraversal/interfaces.py	                        (rev 0)
+++ Sandbox/shane/republish/zope/complextraversal/interfaces.py	2009-02-10 21:44:22 UTC (rev 96424)
@@ -0,0 +1,60 @@
+
+from zope.interface import Interface
+
+class IPublishTraverse(Interface):
+
+    def publishTraverse(request, name):
+        """Lookup a name
+
+        The 'request' argument is the publisher request object.  The
+        'name' argument is the name that is to be looked up; it must
+        be an ASCII string or Unicode object.
+
+        If a lookup is not possible, raise a NotFound error.
+
+        This method should return an object having the specified name and
+        `self` as parent. The method can use the request to determine the
+        correct object.
+        """
+
+class IHTTPPublisher(IPublishTraverse):
+    """HTTP-specific publisher traversal"""
+
+class IBrowserPublisher(IPublishTraverse):
+
+    def browserDefault(request):
+        """Provide the default object
+
+        The default object is expressed as a (possibly different)
+        object and/or additional traversal steps.
+
+        Returns an object and a sequence of names.  If the sequence of
+        names is not empty, then a traversal step is made for each name.
+        After the publisher gets to the end of the sequence, it will
+        call browserDefault on the last traversed object.
+
+        Normal usage is to return self for object and a default view name.
+
+        The publisher calls this method at the end of each traversal path. If
+        a non-empty sequence of names is returned, the publisher will traverse
+        those names and call browserDefault again at the end.
+
+        Note that if additional traversal steps are indicated (via a
+        nonempty sequence of names), then the publisher will try to adjust
+        the base href.
+        """
+
+class IBrowserPage(IBrowserPublisher):
+    """Browser page"""
+
+    def __call__(*args, **kw):
+        """Compute a response body"""
+
+class IBrowserView(Interface):
+    """Browser View"""
+
+class IFTPPublisher(IPublishTraverse):
+    """FTP Publisher"""
+
+class IXMLRPCPublisher(IPublishTraverse):
+    """XML-RPC Publisher"""

Added: Sandbox/shane/republish/zope/publisher/__init__.py
===================================================================
--- Sandbox/shane/republish/zope/publisher/__init__.py	                        (rev 0)
+++ Sandbox/shane/republish/zope/publisher/__init__.py	2009-02-10 21:44:22 UTC (rev 96424)
@@ -0,0 +1 @@
+

Added: Sandbox/shane/republish/zope/publisher/interfaces/__init__.py
===================================================================
--- Sandbox/shane/republish/zope/publisher/interfaces/__init__.py	                        (rev 0)
+++ Sandbox/shane/republish/zope/publisher/interfaces/__init__.py	2009-02-10 21:44:22 UTC (rev 96424)
@@ -0,0 +1,14 @@
+
+
+from zope.deferredimport import deprecatedFrom as _deprecatedFrom
+
+from zope.publisher.interfaces.base import *
+from zope.publisher.interfaces.exceptions import *
+from zope.publisher.interfaces.http import IRedirect
+from zope.publisher.interfaces.http import Redirect
+
+__all__ = tuple(name for name in globals() if not name.startswith('_'))
+
+_deprecatedFrom("Moved to zope.complextraversal.interfaces",
+    "zope.complextraversal.interfaces",
+    "IPublishTraverse")

Modified: Sandbox/shane/republish/zope/publisher/interfaces/base.py
===================================================================
--- Sandbox/shane/republish/zope/publisher/interfaces/base.py	2009-02-10 21:39:20 UTC (rev 96423)
+++ Sandbox/shane/republish/zope/publisher/interfaces/base.py	2009-02-10 21:44:22 UTC (rev 96424)
@@ -5,7 +5,9 @@
 from zope.interface import Interface
 from zope.interface.common.mapping import IExtendedReadMapping
 
+__all__ = ('IRequest', 'IResponse', 'IResult', 'IHeld', 'IDebugFlags')
 
+
 class IRequest(IExtendedReadMapping):
     """Basic request data.
 
@@ -13,35 +15,59 @@
     values will be looked up in the order: [TODO].
     """
 
-    environment = Attribute(
-        """Request environment data.
-
-        This is a pointer to the WSGI or CGI environment.
+    response = Attribute(
+        """The request's IResponse object
         """)
 
-    traversal_path = Attribute(
-        """Sequence of steps to traverse, where each step is a unicode.
-        """)
+    def close():
+        """Release resources held by the request.
+        """
 
-    traversed = Attribute(
-        """List of (name, obj) steps that were traversed.
+    def hold(held):
+        """Hold a reference to an object until the request is closed.
 
-        The first object is the application root and has an empty name.
-        The last object is the object to call.
+        The object should be an IHeld.  If it is an IHeld, its
+        release method will be called when it is released.
+        """
+
+    traversal_stack = Attribute(
+        """The list of steps to traverse in reverse order.
+
+        Elements will be removed from this list as they are traversed.
+        It is possible to influence traversal by changing this list
+        during traversal.
         """)
 
-    response = Attribute(
-        """The request's IResponse object
+    def getTraversalStack():
+        """Deprecated: use the traversal_stack attribute instead.
+        """
+
+    def setTraversalStack(stack):
+        """Deprecated: use the traversal_stack attribute instead.
+        """
+
+    positional_arguments = Attribute(
+        """The positional arguments passed to the request.
         """)
 
-    positional_args = Attribute(
-        """The positional arguments given to the request.
+    def getPositionalArguments():
+        """Deprecated: use the positional_arguments attribute instead.
+        """
+
+    def setPrincipal(principal):
+        """Deprecated: use the principal attribute instead.
+        """
+
+    principal = Attribute(
+        """IPrincipal object associated with the request.
         """)
 
-    principal = Attribute("""Principal object associated with the request.
+    def retry():
+        """Returns a re-initialized request to be retried.
 
-    It should be an IPrincipal wrapped in its AuthenticationService's context.
-    """)
+        Returns a request suitable for repeating the publication attempt,
+        or raises RetryNotSupported if the response can not be retried.
+        """
 
     bodyStream = Attribute(
         """The stream that provides the data of the request.
@@ -60,6 +86,12 @@
 
     debug = Attribute("""Debug flags (see IDebugFlags).""")
 
+    environment = Attribute(
+        """Request environment data.
+
+        This is a pointer to the WSGI or CGI environment.
+        """)
+
     annotations = Attribute(
         """Stores arbitrary application data under package-unique keys.
 
@@ -75,22 +107,25 @@
           "zope.persistentadapter"
         """)
 
-    def hold(held):
-        """Hold a reference to an object until the request is closed.
+    traversed = Attribute(
+        """List of (name, obj) steps that were traversed.
 
-        The object should be an IHeld.  If it is an IHeld, its
-        release method will be called when it is released.
+        The first object is the application root and has an empty name.
+        The last object is the object to call.
+        """)
+
+    def getBasicCredentials():
+        """Return (login, password) if there are basic credentials.
+
+        Returns None if there aren't.
         """
 
-    def close():
-        """Release resources held by the request.
+    def _authUserPW():
+        """Deprecated: Use getBasicCredentials() instead.
         """
 
-    def retry():
-        """Returns a re-initialized request to be retried.
-
-        Returns a request suitable for repeating the publication attempt,
-        or raises RetryNotSupported if the response can not be retried.
+    def unauthorized(challenge):
+        """Deprecated: use response.unauthorized() instead.
         """
 
 
@@ -117,19 +152,6 @@
         status codes.
         """
 
-    def setStandardStatus(name):
-        """Sets the status of the response using a standard status name.
-
-        The name will be converted to a code appropriate for the protocol.
-        For example, the name "NotFound" when applied to an HTTP
-        request will set the response status code to 404 and the name
-        "OK" will set the status to 200.
-
-        If the provided name is not recognized, the response status will
-        be set to a generic error status code (for example,
-        500 for HTTP).
-        """
-
     def getHeaders():
         """Returns a sequence of header name, value tuples.
 
@@ -179,6 +201,12 @@
         constructed from the result.
         """
 
+    def reset():
+        """Reset the output result.
+
+        Reset the response by nullifying already set variables.
+        """
+
     def retry():
         """Returns a re-initialized response to be retried.
 
@@ -218,7 +246,7 @@
     def __iter__():
         """iterate over the values that should be returned as the result.
 
-        See IHTTPResponse.setResult.
+        See IResponse.setResult.
         """
 
 
@@ -239,4 +267,3 @@
 
     sourceAnnotations = Attribute("""Enable ZPT source annotations""")
     showTAL = Attribute("""Leave TAL markup in rendered page templates""")
-

Modified: Sandbox/shane/republish/zope/publisher/interfaces/browser.py
===================================================================
--- Sandbox/shane/republish/zope/publisher/interfaces/browser.py	2009-02-10 21:39:20 UTC (rev 96423)
+++ Sandbox/shane/republish/zope/publisher/interfaces/browser.py	2009-02-10 21:44:22 UTC (rev 96424)
@@ -1,5 +1,9 @@
 
 
+from zope.interface import Interface
+from zope.interface.interfaces import IInterface
+from zope.deferredimport import deprecatedFrom
+from zope.publisher.interfaces.http import IHTTPRequest
 
 class IBrowserRequest(IHTTPRequest):
     """Browser-specific Request functionality.
@@ -22,3 +26,10 @@
     """Event that gets triggered when the skin of a request is changed."""
 
     request = Attribute("The request for which the skin was changed.")
+
+deprecatedFrom("moved to zope.complextraversal.interfaces",
+    "zope.complextraversal.interfaces",
+    "IBrowserPublisher",
+    "IBrowserPage",
+    "IBrowserView",
+    )

Deleted: Sandbox/shane/republish/zope/publisher/interfaces/complextraversal.py
===================================================================
--- Sandbox/shane/republish/zope/publisher/interfaces/complextraversal.py	2009-02-10 21:39:20 UTC (rev 96423)
+++ Sandbox/shane/republish/zope/publisher/interfaces/complextraversal.py	2009-02-10 21:44:22 UTC (rev 96424)
@@ -1,56 +0,0 @@
-
-
-class IPublishTraverse(Interface):
-
-    def publishTraverse(request, name):
-        """Lookup a name
-
-        The 'request' argument is the publisher request object.  The
-        'name' argument is the name that is to be looked up; it must
-        be an ASCII string or Unicode object.
-
-        If a lookup is not possible, raise a NotFound error.
-
-        This method should return an object having the specified name and
-        `self` as parent. The method can use the request to determine the
-        correct object.
-        """
-
-class IHTTPPublisher(IPublishTraverse):
-    """HTTP-specific publisher traversal"""
-
-class IBrowserPublisher(IPublishTraverse):
-
-    def browserDefault(request):
-        """Provide the default object
-
-        The default object is expressed as a (possibly different)
-        object and/or additional traversal steps.
-
-        Returns an object and a sequence of names.  If the sequence of
-        names is not empty, then a traversal step is made for each name.
-        After the publisher gets to the end of the sequence, it will
-        call browserDefault on the last traversed object.
-
-        Normal usage is to return self for object and a default view name.
-
-        The publisher calls this method at the end of each traversal path. If
-        a non-empty sequence of names is returned, the publisher will traverse
-        those names and call browserDefault again at the end.
-
-        Note that if additional traversal steps are indicated (via a
-        nonempty sequence of names), then the publisher will try to adjust
-        the base href.
-        """
-
-class IBrowserPage(IBrowserPublisher):
-    """Browser page"""
-
-    def __call__(*args, **kw):
-        """Compute a response body"""
-
-class IBrowserView(IView):
-    """Browser View"""
-
-class IDefaultBrowserLayer(IBrowserRequest):
-    """The default layer."""

Modified: Sandbox/shane/republish/zope/publisher/interfaces/exceptions.py
===================================================================
--- Sandbox/shane/republish/zope/publisher/interfaces/exceptions.py	2009-02-10 21:39:20 UTC (rev 96423)
+++ Sandbox/shane/republish/zope/publisher/interfaces/exceptions.py	2009-02-10 21:44:22 UTC (rev 96424)
@@ -1,3 +1,23 @@
+
+from zope.interface import Interface
+from zope.interface.common.interfaces import IException, ILookupError
+
+__all__ = (
+    'IPublishingException',
+    'PublishingException',
+    'ITraversalException',
+    'TraversalException',
+    'INotFound',
+    'NotFound',
+    'IDebugError',
+    'DebugError',
+    'IBadRequest',
+    'BadRequest',
+    'IRetry',
+    'Retry',
+    'IExceptionSideEffects',
+    )
+
 class IPublishingException(IException):
     pass
 
@@ -73,3 +93,38 @@
 
     def __str__(self):
         return self.message
+
+class IRetry(IPublishingException):
+    def getOriginalException():
+        'Returns the original exception object.'
+
+class Retry(PublishingException):
+    """Raise this to retry a request."""
+
+    implements(IRetry)
+
+    def __init__(self, orig_exc=None):
+        """orig_exc must be a 3-tuple as returned from sys.exc_info() or None"""
+        self.orig_exc = orig_exc
+
+    def getOriginalException(self):
+        return self.orig_exc
+
+    def __str__(self):
+        if self.orig_exc is None:
+            return 'None'
+        return str(self.orig_exc[1])
+
+class IExceptionSideEffects(Interface):
+    """An exception caught by the publisher is adapted to this so that
+    it can have persistent side-effects."""
+
+    def __call__(obj, request, exc_info):
+        """Effect persistent side-effects.
+
+        Arguments are:
+          obj                 context-wrapped object that was published
+          request             the request
+          exc_info            the exception info being handled
+
+        """

Added: Sandbox/shane/republish/zope/publisher/interfaces/ftp.py
===================================================================
--- Sandbox/shane/republish/zope/publisher/interfaces/ftp.py	                        (rev 0)
+++ Sandbox/shane/republish/zope/publisher/interfaces/ftp.py	2009-02-10 21:44:22 UTC (rev 96424)
@@ -0,0 +1,11 @@
+
+from zope.deferredimport import deprecatedFrom
+from zope.publisher.interfaces.base import IRequest
+
+class IFTPRequest(IRequest):
+    """FTP Request
+    """
+
+deprecatedFrom("moved to zope.complextraversal.interfaces",
+    "zope.complextraversal.interfaces",
+    "IFTPPublisher")

Modified: Sandbox/shane/republish/zope/publisher/interfaces/http.py
===================================================================
--- Sandbox/shane/republish/zope/publisher/interfaces/http.py	2009-02-10 21:39:20 UTC (rev 96423)
+++ Sandbox/shane/republish/zope/publisher/interfaces/http.py	2009-02-10 21:44:22 UTC (rev 96424)
@@ -1,4 +1,10 @@
 
+from zope.interface import Attribute
+from zope.interface import Interface
+from zope.deferredimport import deprecatedFrom
+from zope.publisher.interfaces.base import IRequest
+from zope.publisher.interfaces.exceptions import IPublishingException
+from zope.publisher.interfaces.exceptions import PublishingException
 
 
 class IRedirect(IPublishingException):
@@ -44,13 +50,10 @@
 
     method = Attribute("Request method, normalized to upper case")
 
-    path_suffix = Attribute(
-        """Additional traversal steps to be taken after all other traversal
+    def setPathSuffix(steps):
+        """Deprecated: Add to traversal_stack instead.
+        """
 
-        This is used to handle HTTP request methods (except for GET
-        and POST in the case of browser requests) and XML-RPC methods.
-        """)
-
     locale = Attribute(
         """The locale object associated with this request.""")
 
@@ -108,7 +111,6 @@
         path expressions, like 'request/URL/-2'.
         """)
 
-
     def getURL(level=0, path_only=False):
         """Return the published URL with level names removed from the end.
 
@@ -127,7 +129,9 @@
         Return None if the request does not contain basic credentials.
         """
 
-    _authUserPw = getBasicAuth
+    def _authUserPw():
+        """Deprecated: Use getBasicAuth() instead.
+        """
 
     def unauthorized(challenge):
         """Issue a 401 Unauthorized error (asking for login/password).
@@ -205,3 +209,7 @@
     def redirect(location, status=302):
         """Causes a redirection without raising an error.
         """
+
+deprecatedFrom("moved to zope.complextraversal.interfaces",
+    "zope.complextraversal.interfaces",
+    "IHTTPPublisher")

Added: Sandbox/shane/republish/zope/publisher/interfaces/xmlrpc.py
===================================================================
--- Sandbox/shane/republish/zope/publisher/interfaces/xmlrpc.py	                        (rev 0)
+++ Sandbox/shane/republish/zope/publisher/interfaces/xmlrpc.py	2009-02-10 21:44:22 UTC (rev 96424)
@@ -0,0 +1,12 @@
+
+
+from zope.deferredimport import deprecatedFrom
+from zope.publisher.interfaces.http import IHTTPRequest
+
+class IXMLRPCRequest(IHTTPRequest):
+    """XML-RPC Request
+    """
+
+deprecatedFrom("moved to zope.complextraversal.interfaces",
+    "zope.complextraversal.interfaces",
+    "IXMLRPCPublisher")



More information about the Checkins mailing list