[Zope-Checkins] SVN: Products.Five/trunk/ Merge of traversal
refactoring. five:traversable and five:defaultViewable are no
Lennart Regebro
regebro at gmail.com
Fri Apr 28 13:57:48 EDT 2006
Log message for revision 67728:
Merge of traversal refactoring. five:traversable and five:defaultViewable are no
longer needed.
Changed:
U Products.Five/trunk/CHANGES.txt
U Products.Five/trunk/browser/TrustedExpression.py
U Products.Five/trunk/browser/adding.py
U Products.Five/trunk/browser/configure.zcml
U Products.Five/trunk/browser/tests/cps_test_localizer.txt
U Products.Five/trunk/browser/tests/defaultview.zcml
U Products.Five/trunk/browser/tests/test_defaultview.py
U Products.Five/trunk/browser/tests/test_recurse.py
U Products.Five/trunk/browser/tests/test_traversable.py
U Products.Five/trunk/configure.zcml
U Products.Five/trunk/doc/directives.txt
U Products.Five/trunk/doc/localsite.txt
U Products.Five/trunk/doc/manual.txt
U Products.Five/trunk/doc/products/FiveMiscTutorial/configure.zcml
U Products.Five/trunk/doc/products/ViewsTutorial/configure.zcml
U Products.Five/trunk/fiveconfigure.py
U Products.Five/trunk/form/tests/configure.zcml
U Products.Five/trunk/formlib/tests/configure.zcml
U Products.Five/trunk/tests/directives.zcml
U Products.Five/trunk/tests/test_viewable.py
U Products.Five/trunk/tests/testing/folder.py
U Products.Five/trunk/tests/testing/simplecontent.py
U Products.Five/trunk/tests/viewable.txt
U Products.Five/trunk/traversable.py
U Products.Five/trunk/viewable.py
-=-
Modified: Products.Five/trunk/CHANGES.txt
===================================================================
--- Products.Five/trunk/CHANGES.txt 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/CHANGES.txt 2006-04-28 17:57:47 UTC (rev 67728)
@@ -16,6 +16,9 @@
* fiveconfigure.py: replaced zLOG with logging module
+* five:defaultViewable and five:traversable are now unessecary, as the
+ functionality exists in the Zope core publisher from Zope 2.10 and up.
+
Five 1.4b (2006-03-31)
======================
Modified: Products.Five/trunk/browser/TrustedExpression.py
===================================================================
--- Products.Five/trunk/browser/TrustedExpression.py 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/browser/TrustedExpression.py 2006-04-28 17:57:47 UTC (rev 67728)
@@ -29,6 +29,19 @@
ModuleImporter = SecureModuleImporter
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.interface import implements, Interface
+from zope.app.publication.browser import setDefaultSkin
+from zope.app.traversing.namespace import nsParse
+from zope.app.traversing.namespace import namespaceLookup
+from zope.component import queryMultiAdapter
+
+class FakeRequest(dict):
+ implements(IBrowserRequest)
+
+ def getURL(self):
+ return "http://codespeak.net/z3/five"
+
def trustedTraverse(ob, path, ignored,):
if not path: return self
@@ -40,7 +53,11 @@
if isinstance(path, str): path = path.split('/')
else: path=list(path)
- REQUEST={'TraversalRequestNameStack': path}
+ REQUEST = get(ob, 'REQUEST', None)
+ if REQUEST is None:
+ REQUEST=FakeRequest()
+ setDefaultSkin(REQUEST)
+ REQUEST['TraversalRequestNameStack'] = path
path.reverse()
pop=path.pop
@@ -64,6 +81,17 @@
object=o
continue
+ if name and name[:1] in '@+':
+ # Process URI segment parameters.
+ ns, nm = nsParse(name)
+ if ns:
+ try:
+ o = namespaceLookup(ns, nm, object, REQUEST).__of__(object)
+ except TraversalError:
+ raise KeyError(name)
+ object = o
+ continue
+
t=get(object, '__bobo_traverse__', M)
if t is not M: o=t(REQUEST, name)
else:
@@ -71,7 +99,11 @@
if o is M:
try: o = object[name]
except (AttributeError, TypeError): # better exception
- raise AttributeError(name)
+ o = queryMultiAdapter((object, REQUEST), Interface, name)
+ if o is not None:
+ o = o.__of__(object)
+ else:
+ raise AttributeError(name)
object = o
return object
Modified: Products.Five/trunk/browser/adding.py
===================================================================
--- Products.Five/trunk/browser/adding.py 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/browser/adding.py 2006-04-28 17:57:47 UTC (rev 67728)
@@ -37,7 +37,7 @@
from zExceptions import BadRequest
from Products.Five import BrowserView
-from Products.Five.traversable import Traversable
+
from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile
from Acquisition import Implicit
@@ -202,7 +202,7 @@
return True
return False
-class ContentAdding(Adding, Traversable, SimpleItem):
+class ContentAdding(Adding, SimpleItem):
menu_id = "add_content"
Modified: Products.Five/trunk/browser/configure.zcml
===================================================================
--- Products.Five/trunk/browser/configure.zcml 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/browser/configure.zcml 2006-04-28 17:57:47 UTC (rev 67728)
@@ -1,7 +1,8 @@
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
- <browser:defaultView name="index.html" />
+ <browser:defaultView for="Products.Five.interfaces.IBrowserDefault"
+ name="index.html" />
<interface
interface="zope.publisher.interfaces.browser.ILayer"
Modified: Products.Five/trunk/browser/tests/cps_test_localizer.txt
===================================================================
--- Products.Five/trunk/browser/tests/cps_test_localizer.txt 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/browser/tests/cps_test_localizer.txt 2006-04-28 17:57:47 UTC (rev 67728)
@@ -22,8 +22,6 @@
... <i18n:registerTranslations directory="locales" />
... </configure>
...
- ... <five:traversable class="Products.CPSDefault.Portal.CPSDefaultSite" />
- ...
... <adapter
... for="zope.publisher.interfaces.http.IHTTPRequest"
... provides="zope.i18n.interfaces.IUserPreferredLanguages"
Modified: Products.Five/trunk/browser/tests/defaultview.zcml
===================================================================
--- Products.Five/trunk/browser/tests/defaultview.zcml 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/browser/tests/defaultview.zcml 2006-04-28 17:57:47 UTC (rev 67728)
@@ -2,34 +2,22 @@
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:five="http://namespaces.zope.org/five">
- <five:defaultViewable
- class="Products.Five.tests.testing.simplecontent.SimpleContent" />
-
- <browser:defaultView
+ <browser:page
for="Products.Five.tests.testing.simplecontent.ISimpleContent"
name="eagledefaultview.txt"
+ class=".pages.SimpleView"
+ attribute="mouse"
+ permission="zope2.Public"
/>
<browser:page
for="Products.Five.tests.testing.simplecontent.ISimpleContent"
- name="eagledefaultview.txt"
+ name="index.html"
class=".pages.SimpleView"
attribute="eagle"
permission="zope2.Public"
/>
- <!-- this tests whether five:defaultViewable can be called on a class that
- already provides __call__, such as our CallableSimpleContent -->
-
- <five:defaultViewable
- class="Products.Five.tests.testing.simplecontent.CallableSimpleContent" />
-
- <!-- this tests whether five:defaultViewable can be called on a class that
- already provides index_html, such as our IndexSimpleContent -->
-
- <five:defaultViewable
- class="Products.Five.tests.testing.simplecontent.IndexSimpleContent" />
-
<browser:defaultView
for="Products.Five.tests.testing.simplecontent.IIndexSimpleContent"
name="index_html"
Modified: Products.Five/trunk/browser/tests/test_defaultview.py
===================================================================
--- Products.Five/trunk/browser/tests/test_defaultview.py 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/browser/tests/test_defaultview.py 2006-04-28 17:57:47 UTC (rev 67728)
@@ -46,8 +46,18 @@
>>> uf = self.folder.acl_users
>>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
- Test a simple default view:
-
+ BBB This is a test of backwards comaptibility with Five 1.3/Zope2.9.
+ The deprecated directive five:defaultViewable would before make
+ index.html the default view. Test that this is still the case.
+ five:defaultViewable goes away in Zope 2.12, and this test goes then too:
+ >>> import zope.deprecation
+ >>> zope.deprecation.__show__.off()
+ >>> zcml.load_string('''
+ ... <configure xmlns:five="http://namespaces.zope.org/five">
+ ... <five:defaultViewable
+ ... class="Products.Five.tests.testing.simplecontent.SimpleContent" />
+ ... </configure>''')
+ >>> zope.deprecation.__show__.on()
>>> print http(r'''
... GET /test_folder_1_/testoid HTTP/1.1
... Authorization: Basic manager:r00t
@@ -56,6 +66,23 @@
...
The eagle has landed
+
+ But if we want to, we can specify another default view with
+ browser:defaultView:
+ >>> zcml.load_string('''
+ ... <configure xmlns:browser="http://namespaces.zope.org/browser">
+ ... <browser:defaultView
+ ... for="Products.Five.tests.testing.simplecontent.ISimpleContent"
+ ... name="eagledefaultview.txt" />
+ ... </configure>''')
+ >>> print http(r'''
+ ... GET /test_folder_1_/testoid HTTP/1.1
+ ... Authorization: Basic manager:r00t
+ ... ''')
+ HTTP/1.1 200 OK
+ ...
+ The mouse has been eaten by the eagle
+
This tests whether an existing ``index_html`` method is still
supported and called:
Modified: Products.Five/trunk/browser/tests/test_recurse.py
===================================================================
--- Products.Five/trunk/browser/tests/test_recurse.py 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/browser/tests/test_recurse.py 2006-04-28 17:57:47 UTC (rev 67728)
@@ -42,12 +42,8 @@
... return 'foo'
...
- Now we make the class default viewable and register a default view
- name for it:
+ Now we register a default view name for the class:
- >>> from Products.Five.fiveconfigure import classDefaultViewable
- >>> classDefaultViewable(Recurse)
-
>>> from zope.component import provideAdapter
>>> from zope.publisher.interfaces.browser import IBrowserRequest
>>> from zope.component.interfaces import IDefaultViewName
Modified: Products.Five/trunk/browser/tests/test_traversable.py
===================================================================
--- Products.Five/trunk/browser/tests/test_traversable.py 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/browser/tests/test_traversable.py 2006-04-28 17:57:47 UTC (rev 67728)
@@ -57,16 +57,6 @@
...
... <!-- make the zope2.Public permission work -->
... <meta:redefinePermission from="zope2.Public" to="zope.Public" />
- ...
- ... <five:traversable
- ... class="Products.Five.tests.testing.fancycontent.FancyContent"
- ... />
- ... <five:traversable
- ... class="Products.Five.browser.tests.test_traversable.SimpleClass"
- ... />
- ... <five:traversable
- ... class="Products.Five.tests.testing.FiveTraversableFolder"
- ... />
...
... <!-- this view will never be found -->
... <browser:page
@@ -216,7 +206,6 @@
... attribute="eagle"
... permission="zope2.Public"
... />
- ... <five:traversable class="OFS.Application.Application"/>
... </configure>'''
>>> import Products.Five
>>> from Products.Five import zcml
Modified: Products.Five/trunk/configure.zcml
===================================================================
--- Products.Five/trunk/configure.zcml 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/configure.zcml 2006-04-28 17:57:47 UTC (rev 67728)
@@ -29,12 +29,6 @@
provides="zope.app.traversing.interfaces.ITraverser"
/>
- <adapter
- for="*"
- factory=".viewable.BrowserDefault"
- provides=".interfaces.IBrowserDefault"
- />
-
<!-- this is really lying, but it's to please checkContainer -->
<five:implements class="OFS.ObjectManager.ObjectManager"
interface="zope.app.container.interfaces.IContainer" />
Modified: Products.Five/trunk/doc/directives.txt
===================================================================
--- Products.Five/trunk/doc/directives.txt 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/doc/directives.txt 2006-04-28 17:57:47 UTC (rev 67728)
@@ -137,6 +137,8 @@
traversable
-----------
+This statement is now deprecated, since the functionality now is on Zope Core.
+
Make a Zope 2 content class traversable in the Zope 3 manner using
Five. This is used to attached views, resources and other things to
Zope 2 objects.
@@ -144,6 +146,8 @@
defaultViewable
---------------
+This statement is now deprecated, since the functionality now is on Zope Core.
+
Make a Zope 2 content class use a Zope 3 default view when looking at
it without any paths appended to it. This works then instead of
``index_html`` in Zope 2.
Modified: Products.Five/trunk/doc/localsite.txt
===================================================================
--- Products.Five/trunk/doc/localsite.txt 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/doc/localsite.txt 2006-04-28 17:57:47 UTC (rev 67728)
@@ -42,12 +42,7 @@
the site manager to site; it is assumed that the site already knows
how to get its site manager.
-Also note that in order for the view to work, the object's class needs
-to be Five-traversable, e.g. with the following ZCML statement:
- <five:traversable class=".module.MyClass" />
-
-
Custom site implementations
---------------------------
Modified: Products.Five/trunk/doc/manual.txt
===================================================================
--- Products.Five/trunk/doc/manual.txt 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/doc/manual.txt 2006-04-28 17:57:47 UTC (rev 67728)
@@ -260,28 +260,7 @@
``five`` in this case refers to the XML namespace for Five,
``http://namespace.zope.org/five``.
-We've provided another ZCML directive to make an object
-traversable. To make your MyClass traversable, let's assume it is in
-``mymodule``, in the same package as the zcml file we are editing::
- <five:traversable class=".mymodule.MyClass" />
-
-To continue our example, to make Zope's ``Folder`` traversable through
-Five, you need to declare this in ZCML as well:
-
- <five:traversable class="OFS.Folder.Folder"/>
-
-This makes Folder traverse in the Zope 3 way first, looking up views
-and other things, and then if they cannot be found, fall back on the
-regular Zope 2 traversal. It does this by overriding the
-``__bobo_traverse__`` hook. Old hooks that are already in place in an
-object will be stored and become the secondary fallback. This allows
-the ZMI to work still, but new views can be added on the fly.
-
-Note that at the point of writing it is only possible to make an object
-viewable through ZCML if this object does not already provide its own
-``__bobo_traverse__`` method.
-
Views in Five are simple classes. The only requirements for a Five
view class are:
Modified: Products.Five/trunk/doc/products/FiveMiscTutorial/configure.zcml
===================================================================
--- Products.Five/trunk/doc/products/FiveMiscTutorial/configure.zcml 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/doc/products/FiveMiscTutorial/configure.zcml 2006-04-28 17:57:47 UTC (rev 67728)
@@ -4,8 +4,6 @@
xmlns:five="http://namespaces.zope.org/five"
>
-<five:traversable class="OFS.Folder.Folder" />
-
<browser:resource
image="z3base.png"
name="z3base.png"
Modified: Products.Five/trunk/doc/products/ViewsTutorial/configure.zcml
===================================================================
--- Products.Five/trunk/doc/products/ViewsTutorial/configure.zcml 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/doc/products/ViewsTutorial/configure.zcml 2006-04-28 17:57:47 UTC (rev 67728)
@@ -3,12 +3,8 @@
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:five="http://namespaces.zope.org/five">
- <five:traversable class="OFS.Application.Application"/>
-
<!-- OFS.Folder.Folder views -->
- <five:traversable class="OFS.Folder.Folder"/>
-
<browser:page
for="OFS.interfaces.IFolder"
name="overview.html"
@@ -49,8 +45,6 @@
<!-- .democontent.IDemoContent views -->
- <five:traversable class=".democontent.DemoContent"/>
-
<browser:page
for="zope.app.container.interfaces.IAdding"
name="addDemoContent.html"
@@ -79,8 +73,6 @@
permission="zope2.ViewManagementScreens"
/>
- <five:defaultViewable class=".democontent.DemoContent"/>
-
<browser:defaultView
for=".democontent.IDemoContent"
name="someview.html"
Modified: Products.Five/trunk/fiveconfigure.py
===================================================================
--- Products.Five/trunk/fiveconfigure.py 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/fiveconfigure.py 2006-04-28 17:57:47 UTC (rev 67728)
@@ -26,6 +26,7 @@
import App.config
import Products
+import zope.deprecation
from zope.interface import classImplements, classImplementsOnly, implementedBy
from zope.interface.interface import InterfaceClass
from zope.configuration import xmlconfig
@@ -37,10 +38,9 @@
from zope.app.component.metaconfigure import adapter
from zope.app.security.interfaces import IPermission
-from Products.Five.viewable import Viewable
-from Products.Five.traversable import Traversable
from Products.Five.bridge import fromZ2Interface
from Products.Five.browser.metaconfigure import page
+from Products.Five.interfaces import IBrowserDefault
debug_mode = App.config.getConfiguration().debug_mode
LOG = logging.getLogger('Five')
@@ -111,74 +111,21 @@
def isFiveMethod(m):
return hasattr(m, '__five_method__')
-_traversable_monkies = []
-def classTraversable(class_):
- # If a class already has this attribute, it means it is either a
- # subclass of Traversable or was already processed with this
- # directive; in either case, do nothing... except in the case were
- # the class overrides __bobo_traverse__ instead of getting it from
- # a base class. In this case, we suppose that the class probably
- # didn't bother with the base classes __bobo_traverse__ anyway and
- # we step __fallback_traverse__.
- if hasattr(class_, '__five_traversable__'):
- if (hasattr(class_, '__bobo_traverse__') and
- isFiveMethod(class_.__bobo_traverse__)):
- return
-
- if (hasattr(class_, '__bobo_traverse__') and
- not isFiveMethod(class_.__bobo_traverse__)):
- # if there's an existing bobo_traverse hook already, use that
- # as the traversal fallback method
- setattr(class_, '__fallback_traverse__', class_.__bobo_traverse__)
-
- setattr(class_, '__bobo_traverse__',
- Traversable.__bobo_traverse__.im_func)
- setattr(class_, '__five_traversable__', True)
- # remember class for clean up
- _traversable_monkies.append(class_)
-
def traversable(_context, class_):
- _context.action(
- discriminator = None,
- callable = classTraversable,
- args = (class_,)
- )
-
-_defaultviewable_monkies = []
-def classDefaultViewable(class_):
- # If a class already has this attribute, it means it is either a
- # subclass of DefaultViewable or was already processed with this
- # directive; in either case, do nothing... except in the case were
- # the class overrides the attribute instead of getting it from
- # a base class. In this case, we suppose that the class probably
- # didn't bother with the base classes attribute anyway.
- if hasattr(class_, '__five_viewable__'):
- if (hasattr(class_, '__browser_default__') and
- isFiveMethod(class_.__browser_default__)):
- return
-
- if hasattr(class_, '__browser_default__'):
- # if there's an existing __browser_default__ hook already, use that
- # as the fallback
- if not isFiveMethod(class_.__browser_default__):
- setattr(class_, '__fallback_default__', class_.__browser_default__)
- if not hasattr(class_, '__fallback_default__'):
- setattr(class_, '__fallback_default__',
- Viewable.__fallback_default__.im_func)
-
- setattr(class_, '__browser_default__',
- Viewable.__browser_default__.im_func)
- setattr(class_, '__five_viewable__', True)
- # remember class for clean up
- _defaultviewable_monkies.append(class_)
-
+ warnings.warn("The five:traversable statement is no longer needed " \
+ "and will be removed in Zope 2.12",
+ DeprecationWarning)
+
def defaultViewable(_context, class_):
- _context.action(
- discriminator = None,
- callable = classDefaultViewable,
- args = (class_,)
- )
+ if zope.deprecation.__show__():
+ warnings.warn("The five:defaultViewable statement is no longer " \
+ "needed and will be removed in Zope 2.12. \n If you rely " \
+ "on it to make 'index.html' the default view, replace it " \
+ "with <browser:defaultView name='index.html' />",
+ DeprecationWarning, 2)
+ implements(_context, class_, (IBrowserDefault,))
+
def createZope2Bridge(zope2, package, name):
# Map a Zope 2 interface into a Zope3 interface, seated within 'package'
# as 'name'.
@@ -279,17 +226,6 @@
except (AttributeError, KeyError):
pass
-def untraversable(class_):
- """Restore class's initial state with respect to traversability"""
- killMonkey(class_, '__bobo_traverse__', '__fallback_traverse__',
- '__five_traversable__')
-
-def undefaultViewable(class_):
- """Restore class's initial state with respect to being default
- viewable."""
- killMonkey(class_, '__browser_default__', '__fallback_default__',
- '__five_viewable__')
-
def unregisterClass(class_):
delattr(class_, 'meta_type')
try:
@@ -298,16 +234,7 @@
pass
def cleanUp():
- global _traversable_monkies
- for class_ in _traversable_monkies:
- untraversable(class_)
- _traversable_monkies = []
- global _defaultviewable_monkies
- for class_ in _defaultviewable_monkies:
- undefaultViewable(class_)
- _defaultviewable_monkies = []
-
global _register_monkies
for class_ in _register_monkies:
unregisterClass(class_)
Modified: Products.Five/trunk/form/tests/configure.zcml
===================================================================
--- Products.Five/trunk/form/tests/configure.zcml 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/form/tests/configure.zcml 2006-04-28 17:57:47 UTC (rev 67728)
@@ -10,7 +10,6 @@
<meta:redefinePermission from="zope2.Public" to="zope.Public" />
<!-- browser forms -->
- <five:traversable class=".schemacontent.FieldContent" />
<browser:editform
schema=".schemacontent.IFieldContent"
@@ -20,8 +19,6 @@
permission="zope2.Public"
/>
- <five:traversable class=".schemacontent.ComplexSchemaContent" />
-
<browser:editform
schema=".schemacontent.IComplexSchemaContent"
for=".schemacontent.IComplexSchemaContent"
Modified: Products.Five/trunk/formlib/tests/configure.zcml
===================================================================
--- Products.Five/trunk/formlib/tests/configure.zcml 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/formlib/tests/configure.zcml 2006-04-28 17:57:47 UTC (rev 67728)
@@ -6,11 +6,7 @@
xmlns:i18n="http://namespaces.zope.org/i18n"
i18n_domain="formtest"
>
-
- <five:traversable class="OFS.Folder.Folder" />
- <five:traversable class=".content.Content" />
-
<browser:page
name="add_content"
for="*"
Modified: Products.Five/trunk/tests/directives.zcml
===================================================================
--- Products.Five/trunk/tests/directives.zcml 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/tests/directives.zcml 2006-04-28 17:57:47 UTC (rev 67728)
@@ -7,22 +7,6 @@
factory=".adapters.Adapter"
/>
- <!-- this is a test whether five:traversable can be called more than
- once on a class; SimpleContent inherits from Traversable, so
- one directive suffices here -->
-
- <five:traversable class="Products.Five.tests.testing.simplecontent.SimpleContent" />
-
- <!-- this is a test whether the *directive* can be called more than
- once without raising a conflicting configuration exception -->
-
- <five:traversable class="Products.Five.tests.testing.simplecontent.SimpleContent" />
-
- <!-- this tests whether five:traversable can be called on a class that
- already provides __bobo_traverse__, such as our FancyContent -->
-
- <five:traversable class="Products.Five.tests.testing.fancycontent.FancyContent" />
-
<!-- Testing the vocabulary directive -->
<vocabulary
Modified: Products.Five/trunk/tests/test_viewable.py
===================================================================
--- Products.Five/trunk/tests/test_viewable.py 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/tests/test_viewable.py 2006-04-28 17:57:47 UTC (rev 67728)
@@ -21,7 +21,8 @@
def test_defaultView():
"""
- Testing default view functionality
+ This tests the default view functionality. It also tests the deprecated
+ BrowserDefault class. References to BrowserDefault can be removed in 2.12.
Take a class Foo and an interface IFoo:
@@ -40,20 +41,31 @@
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.interfaces import IBrowserDefault
+ >>> from zope.interface import Interface
+ >>> provideAdapter(BrowserDefault, (Interface,), IBrowserDefault)
>>> provideAdapter(u'index.html', (None, IBrowserRequest), IDefaultViewName)
>>> provideAdapter(u'foo.html', (IFoo, IBrowserRequest), IDefaultViewName)
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:
>>> from Products.Five.traversable import FakeRequest
>>> request = FakeRequest()
-
+ >>> from zope.app.publisher.browser import queryDefaultViewName
+
+ >>> queryDefaultViewName(foo, request)
+ u'index.html'
>>> obj, path = bd.defaultView(request)
>>> obj is foo
True
@@ -64,6 +76,9 @@
>>> from zope.interface import directlyProvides
>>> directlyProvides(foo, IFoo)
+ >>> queryDefaultViewName(foo, request)
+ u'foo.html'
+
>>> obj, path = bd.defaultView(request)
>>> obj is foo
True
Modified: Products.Five/trunk/tests/testing/folder.py
===================================================================
--- Products.Five/trunk/tests/testing/folder.py 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/tests/testing/folder.py 2006-04-28 17:57:47 UTC (rev 67728)
@@ -18,7 +18,6 @@
from OFS.Folder import Folder
from OFS.interfaces import IFolder
from zope.interface import implements
-from Products.Five.traversable import Traversable
class NoVerifyPasteFolder(Folder):
"""Folder that does not perform paste verification.
@@ -33,7 +32,7 @@
folder.id = id
folder.title = title
-class FiveTraversableFolder(Traversable, Folder):
+class FiveTraversableFolder(Folder):
"""Folder that is five-traversable
"""
implements(IFolder)
Modified: Products.Five/trunk/tests/testing/simplecontent.py
===================================================================
--- Products.Five/trunk/tests/testing/simplecontent.py 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/tests/testing/simplecontent.py 2006-04-28 17:57:47 UTC (rev 67728)
@@ -20,7 +20,6 @@
from AccessControl import ClassSecurityInfo
from zope.interface import Interface, implements
-from Products.Five.traversable import Traversable
class ISimpleContent(Interface):
pass
@@ -31,7 +30,7 @@
class IIndexSimpleContent(ISimpleContent):
pass
-class SimpleContent(Traversable, SimpleItem):
+class SimpleContent(SimpleItem):
implements(ISimpleContent)
meta_type = 'Five SimpleContent'
Modified: Products.Five/trunk/tests/viewable.txt
===================================================================
--- Products.Five/trunk/tests/viewable.txt 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/tests/viewable.txt 2006-04-28 17:57:47 UTC (rev 67728)
@@ -66,9 +66,9 @@
Now make the class default viewable:
- >>> from Products.Five.fiveconfigure import classDefaultViewable
- >>> from OFS.Folder import Folder
- >>> classDefaultViewable(Folder)
+ >>> #from Products.Five.fiveconfigure import classDefaultViewable
+ >>> #from OFS.Folder import Folder
+ >>> #classDefaultViewable(Folder)
And try it again:
Modified: Products.Five/trunk/traversable.py
===================================================================
--- Products.Five/trunk/traversable.py 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/traversable.py 2006-04-28 17:57:47 UTC (rev 67728)
@@ -15,6 +15,10 @@
$Id$
"""
+
+import warnings
+import zope.deprecation
+
from zope.component import getMultiAdapter, ComponentLookupError
from zope.interface import implements, Interface
from zope.publisher.interfaces import ILayer
@@ -58,6 +62,13 @@
# 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)
@@ -119,6 +130,14 @@
class FiveTraversable(DefaultTraversable):
+ 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)
Modified: Products.Five/trunk/viewable.py
===================================================================
--- Products.Five/trunk/viewable.py 2006-04-28 17:11:47 UTC (rev 67727)
+++ Products.Five/trunk/viewable.py 2006-04-28 17:57:47 UTC (rev 67728)
@@ -27,81 +27,19 @@
_marker = object
-class Viewable:
- """A mixin to make an object viewable.
- """
- __five_viewable__ = True
+import warnings
+import zope.deprecation
- def __fallback_default__(self, request):
- """Try to dispatch to existing index_html or __call__"""
- if getattr(self, 'index_html', None):
- return self, ('index_html',)
- if getattr(self, 'fallback_call__', None):
- return self, ('fallback_call__',)
- # XXX Should never get this far. But if it does?
-
- # def fallback_call__(self, *args, **kw):
- # """By default, return self"""
- # return self
-
- # we have a default view, tell zpublisher to go there
- def __browser_default__(self, request):
- obj = self
- path = None
- if request['REQUEST_METHOD'] not in ('GET', 'POST'):
- return obj, [request['REQUEST_METHOD']]
- try:
- obj, path = IBrowserDefault(self).defaultView(request)
- except ComponentLookupError:
- pass
- if path:
- if len(path) == 1 and path[0] == '__call__':
- return obj, ('fallback_call__',)
- return obj, path
- return self.__fallback_default__(request)
- __browser_default__.__five_method__ = True
-
- # this is technically not needed because ZPublisher finds our
- # attribute through __browser_default__; but we also want to be
- # able to call pages from python modules, PythonScripts or ZPT
- # def __call__(self, *args, **kw):
- # """ """
- # request = kw.get('REQUEST')
- # if not IBrowserRequest.providedBy(request):
- # request = getattr(self, 'REQUEST', None)
- # if not IBrowserRequest.providedBy(request):
- # request = FakeRequest()
- # obj, path = self.__browser_default__(request)
- # if path and not simpleRecursion():
- # meth = obj.unrestrictedTraverse(path)
- # if meth is not None:
- # return meth(*args, **kw)
- # return self.fallback_call__(*args, **kw)
- # __call__.__five_method__ = True
-
-# def simpleRecursion():
-# # This tests for simple recursion, which can easily happen
-# # in CMF, like the following:
-# # - Object has a method named 'view'
-# # - 'view' method calls '__call__'
-# # - five:viewable overrides call to use '__browser_default__'
-# # to find a default view and call it
-# # - defaultView is set to 'view'
-# # Bang. Infinite recursion.
-# stack = inspect.stack()
-# try:
-# if len(stack) < 4:
-# return False
-# if stack[2][1:4] == stack[4][1:4]:
-# return True
-# finally:
-# del stack
-# return False
-
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):
More information about the Zope-Checkins
mailing list