[Checkins] SVN: Products.Five/trunk/ Move nolonger needed stuff to Five.bbb and deprecate it properly.

Philipp von Weitershausen philikon at philikon.de
Tue May 2 14:57:20 EDT 2006


Log message for revision 67848:
  Move nolonger needed stuff to Five.bbb and deprecate it properly.
  IBrowserDefault should be part of this, but apparently lots of machinery
  still needs it for some reason... will investigate
  

Changed:
  A   Products.Five/trunk/bbb.py
  U   Products.Five/trunk/tests/test_viewable.py
  U   Products.Five/trunk/traversable.py
  U   Products.Five/trunk/traversing.zcml
  U   Products.Five/trunk/viewable.py

-=-
Added: Products.Five/trunk/bbb.py
===================================================================
--- Products.Five/trunk/bbb.py	2006-05-02 18:54:18 UTC (rev 67847)
+++ Products.Five/trunk/bbb.py	2006-05-02 18:57:19 UTC (rev 67848)
@@ -0,0 +1,62 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Things needed for backward compatibility
+
+$Id
+"""
+from zope.interface import Interface, implements
+from zope.component.interfaces import ComponentLookupError
+from zope.app.publisher.browser import getDefaultViewName
+
+import zExceptions
+import Products.Five.security
+from Products.Five import fivemethod
+from Products.Five.interfaces import IBrowserDefault
+
+class BrowserDefault(object):
+    implements(IBrowserDefault)
+
+    def __init__(self, context):
+        self.context = context
+
+    def defaultView(self, request):
+        context = self.context
+        try:
+            name = getDefaultViewName(context, request)
+            return context, [name,]
+        except ComponentLookupError:
+            return context, None
+
+class Traversable:
+    """A mixin to make an object traversable"""
+    __five_traversable__ = True
+
+    def __bobo_traverse__(self, REQUEST, name):
+        """Hook for Zope 2 traversal
+
+        This method is called by Zope 2's ZPublisher upon traversal.
+        It allows us to trick it into faking the Zope 3 traversal system
+        by using an ITraverser adapter.
+        """
+        try:
+            return getattr(self, name)
+        except AttributeError:
+            pass
+
+        try:
+            return self[name]
+        except (KeyError, IndexError, TypeError, AttributeError):
+            pass
+
+        raise AttributeError(name)


Property changes on: Products.Five/trunk/bbb.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: Products.Five/trunk/tests/test_viewable.py
===================================================================
--- Products.Five/trunk/tests/test_viewable.py	2006-05-02 18:54:18 UTC (rev 67847)
+++ Products.Five/trunk/tests/test_viewable.py	2006-05-02 18:57:19 UTC (rev 67848)
@@ -42,7 +42,7 @@
     and default view names for everything and IFoo objects in particular:
 
       >>> from zope.app.component.metaconfigure import adapter
-      >>> from Products.Five.viewable import BrowserDefault
+      >>> from Products.Five.bbb import BrowserDefault
       >>> from Products.Five.interfaces import IBrowserDefault
       >>> from zope.interface import Interface
       >>> provideAdapter(BrowserDefault, (Interface,), IBrowserDefault)
@@ -51,12 +51,8 @@
 
     Now take a BrowserDefault for an instance of Foo::
 
-      >>> import zope.deprecation
       >>> foo = Foo()
-      >>> from Products.Five.viewable import BrowserDefault
-      >>> zope.deprecation.__show__.off()
       >>> bd = BrowserDefault(foo)
-      >>> zope.deprecation.__show__.on()
 
     For now the default view name is index.html, like we set above:
 

Modified: Products.Five/trunk/traversable.py
===================================================================
--- Products.Five/trunk/traversable.py	2006-05-02 18:54:18 UTC (rev 67847)
+++ Products.Five/trunk/traversable.py	2006-05-02 18:57:19 UTC (rev 67848)
@@ -15,21 +15,9 @@
 
 $Id$
 """
-import warnings
-import zope.deprecation
-
-import zope.publisher.interfaces
-from zope.interface import implements, Interface
-from zope.security.proxy import removeSecurityProxy
+from zope.interface import implements
 from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.publisher.browser import setDefaultSkin
-from zope.app.interface import queryType
-from zope.app.publication.publicationtraverse import PublicationTraverse
 
-import zExceptions
-import Products.Five.security
-from Products.Five import fivemethod
-
 class FakeRequest(dict):
     implements(IBrowserRequest)
 
@@ -39,101 +27,12 @@
     def getURL(self):
         return "http://codespeak.net/z3/five"
 
-class Traversable:
-    """A mixin to make an object traversable using an ITraverser adapter.
-    """
-    __five_traversable__ = True
-
-    @fivemethod
-    def __bobo_traverse__(self, REQUEST, name):
-        """Hook for Zope 2 traversal
-
-        This method is called by Zope 2's ZPublisher upon traversal.
-        It allows us to trick it into faking the Zope 3 traversal system
-        by using an ITraverser adapter.
-        """
-        # We are trying to be compatible with Zope 2 and 3 traversal
-        # behaviour as much as possible.  Therefore the first part of
-        # this method is based on BaseRequest.traverse's behaviour:
-        # 1. If an object has __bobo_traverse__, use it.
-        # 2. Otherwise do attribute look-up or, if that doesn't work,
-        #    key item lookup.
-
-        if zope.deprecation.__show__():
-            warnings.warn("The view lookup done by Traversable." \
-                          "__bobo_traverse__ is now done by the standard " \
-                          "traversal. This class is no longer needed and "
-                          "will be removed in Zope 2.12.",
-                          DeprecationWarning, 2)
-
-        if hasattr(self, '__fallback_traverse__'):
-            try:
-                return self.__fallback_traverse__(REQUEST, name)
-            except (AttributeError, KeyError):
-                pass
-            except zExceptions.NotFound:
-                # OFS.Application.__bobo_traverse__ calls
-                # REQUEST.RESPONSE.notFoundError which sets the HTTP
-                # status code to 404
-                try:
-                    REQUEST.RESPONSE.setStatus(200)
-                except AttributeError:
-                    pass
-        else:
-            try:
-                return getattr(self, name)
-            except AttributeError:
-                pass
-
-            try:
-                return self[name]
-            except (KeyError, IndexError, TypeError, AttributeError):
-                pass
-
-        # This is the part Five adds:
-        # 3. If neither __bobo_traverse__ nor attribute/key look-up
-        # work, we try to find a Zope 3-style view.
-
-        # For that we need to make sure we have a good request
-        # (sometimes __bobo_traverse__ gets a stub request)
-        if not IBrowserRequest.providedBy(REQUEST):
-            # Try to get the REQUEST by acquisition
-            REQUEST = getattr(self, 'REQUEST', None)
-            if not IBrowserRequest.providedBy(REQUEST):
-                REQUEST = FakeRequest()
-                setDefaultSkin(REQUEST)
-
-        # Con Zope 3 into using Zope 2's checkPermission
-        Products.Five.security.newInteraction()
-
-        try:
-            ob = PublicationTraverse().traverseName(REQUEST, self, name)
-            return removeSecurityProxy(ob).__of__(self)
-        except zope.publisher.interfaces.NotFound:
-            pass
-
-        raise AttributeError(name)
-
-class FiveTraversable(object):
-
-    def __init__(self, subject):
-        if zope.deprecation.__show__():
-            warnings.warn("The FiveTraversable class is no longer needed, " \
-                          "and will be removed in Zope 2.12.",
-                  DeprecationWarning, 2)
-        
-        self._subject = subject
-
-    def traverse(self, name, furtherPath):
-        context = self._subject
-        __traceback_info__ = (context, name, furtherPath)
-        # Find the REQUEST
-        REQUEST = getattr(context, 'REQUEST', None)
-        if not IBrowserRequest.providedBy(REQUEST):
-            REQUEST = FakeRequest()
-            setDefaultSkin(REQUEST)
-        # Try to lookup a view
-        try:
-            return getMultiAdapter((context, REQUEST), Interface, name)
-        except ComponentLookupError:
-            pass
+# BBB 2006/05/01 -- to be removed after 12 months
+import zope.deferredimport
+zope.deferredimport.deprecated(
+    "__bobo_traverse__ and ITraverser/ITraversable for controlling "
+    "URL traversal has become obsolete. Use an IPublishTraverse "
+    "adapter instead.",
+    Traversable = "Products.Five.bbb.Traversable",
+    FiveTraversable = "zope.traversing.adapters.DefaultTraversable",
+    )

Modified: Products.Five/trunk/traversing.zcml
===================================================================
--- Products.Five/trunk/traversing.zcml	2006-05-02 18:54:18 UTC (rev 67847)
+++ Products.Five/trunk/traversing.zcml	2006-05-02 18:57:19 UTC (rev 67848)
@@ -4,9 +4,10 @@
   <!-- define default namespace adapters, etc. -->
   <include package="zope.traversing" />
 
+  <!-- BBB 2006/05/01 - to be removed after 12 months -->
   <adapter
       for="*"
-      factory=".viewable.BrowserDefault"
+      factory=".bbb.BrowserDefault"
       provides=".interfaces.IBrowserDefault"
       />
 

Modified: Products.Five/trunk/viewable.py
===================================================================
--- Products.Five/trunk/viewable.py	2006-05-02 18:54:18 UTC (rev 67847)
+++ Products.Five/trunk/viewable.py	2006-05-02 18:57:19 UTC (rev 67848)
@@ -13,31 +13,13 @@
 ##############################################################################
 """Machinery for making things viewable
 
+BBB 2006/05/01 -- to be removed after 12 months
+
 $Id$
 """
-import warnings
-import zope.deprecation
-from zope.interface import implements
-from zope.component.interfaces import ComponentLookupError
-from zope.app.publisher.browser import getDefaultViewName
-from Products.Five.interfaces import IBrowserDefault
-
-class BrowserDefault(object):
-    implements(IBrowserDefault)
-
-    def __init__(self, context):
-        if zope.deprecation.__show__():
-            warnings.warn("The BrowserDefault class is no longer needed and "  \
-                          "will be removed in Zope 2.12. \n If you rely on "   \
-                          "it to get the default view, replace the call with " \
-                          "zope.app.publisher.browser.queryDefaultViewName",
-                          DeprecationWarning, 2)
-        self.context = context
-
-    def defaultView(self, request):
-        context = self.context
-        try:
-            name = getDefaultViewName(context, request)
-            return context, [name,]
-        except ComponentLookupError:
-            return context, None
+import zope.deferredimport
+zope.deferredimport.deprecated(
+    "To get the default browser view of an object, use "
+    "zope.app.publisher.browser.queryDefaultViewName.",
+    BrowserDefault = "Products.Five.bbb:BrowserDefault",
+    )



More information about the Checkins mailing list