[z3-checkins] r23633 - in z3/Five/trunk: . browser/tests
tests/testing
alecm at codespeak.net
alecm at codespeak.net
Fri Feb 24 00:49:00 CET 2006
Author: alecm
Date: Fri Feb 24 00:48:56 2006
New Revision: 23633
Modified:
z3/Five/trunk/browser/tests/test_traversable.py
z3/Five/trunk/tests/testing/fancycontent.py
z3/Five/trunk/traversable.py
Log:
Copy traversal fixes to trunk
Modified: z3/Five/trunk/browser/tests/test_traversable.py
==============================================================================
--- z3/Five/trunk/browser/tests/test_traversable.py (original)
+++ z3/Five/trunk/browser/tests/test_traversable.py Fri Feb 24 00:48:56 2006
@@ -64,6 +64,9 @@
... <five:traversable
... class="Products.Five.browser.tests.test_traversable.SimpleClass"
... />
+ ... <five:traversable
+ ... class="Products.Five.tests.testing.FiveTraversableFolder"
+ ... />
...
... <browser:page
... for="Products.Five.tests.testing.fancycontent.IFancyContent"
@@ -98,6 +101,35 @@
HTTP/1.1 200 OK
...
Fancy, fancy
+
+ Five's traversable monkeypatches the __bobo_traverse__ method to do view
+ lookup and then delegates back to the original __bobo_traverse__ or direct
+ attribute/item lookup to do normal lookup. In the Zope 2 ZPublisher, an
+ object with a __bobo_traverse__ will not do attribute lookup unless the
+ __bobo_traverse__ method itself does it (i.e. the __bobo_traverse__ is the
+ only element used for traversal lookup). Let's demonstrate:
+
+ >>> from Products.Five.tests.testing.fancycontent import manage_addNonTraversableFancyContent
+ >>> info = manage_addNonTraversableFancyContent(self.folder, 'fancy_zope2', '')
+ >>> self.folder.fancy_zope2.an_attribute = 'This is an attribute'
+ >>> print http(r'''
+ ... GET /test_folder_1_/fancy_zope2/an_attribute HTTP/1.1
+ ... ''')
+ HTTP/1.1 200 OK
+ ...
+ an_attribute
+
+ Without a __bobo_traverse__ method this would have returned the attribute
+ value 'This is an attribute'. Let's make sure the same thing happens for
+ an object that has been marked traversable by Five:
+
+ >>> self.folder.fancy.an_attribute = 'This is an attribute'
+ >>> print http(r'''
+ ... GET /test_folder_1_/fancy/an_attribute HTTP/1.1
+ ... ''')
+ HTTP/1.1 200 OK
+ ...
+ an_attribute
Clean up:
Modified: z3/Five/trunk/tests/testing/fancycontent.py
==============================================================================
--- z3/Five/trunk/tests/testing/fancycontent.py (original)
+++ z3/Five/trunk/tests/testing/fancycontent.py Fri Feb 24 00:48:56 2006
@@ -57,9 +57,32 @@
def get_size(self):
return 43
+# A copy of the above class used to demonstrate some baseline behavior
+class NonTraversableFancyContent(SimpleItem):
+ """A class that already comes with its own __bobo_traverse__ handler.
+ Quite fancy indeed.
+
+ It also comes with its own get_size method.
+ """
+ implements(IFancyContent)
+
+ meta_type = "Fancy Content"
+ security = ClassSecurityInfo()
+
+ def __bobo_traverse__(self, REQUEST, name):
+ return FancyAttribute(name).__of__(self)
+
+ def get_size(self):
+ return 43
+
InitializeClass(FancyContent)
def manage_addFancyContent(self, id, REQUEST=None):
"""Add the fancy fancy content."""
id = self._setObject(id, FancyContent(id))
return ''
+
+def manage_addNonTraversableFancyContent(self, id, REQUEST=None):
+ """Add the fancy fancy content."""
+ id = self._setObject(id, NonTraversableFancyContent(id))
+ return ''
Modified: z3/Five/trunk/traversable.py
==============================================================================
--- z3/Five/trunk/traversable.py (original)
+++ z3/Five/trunk/traversable.py Fri Feb 24 00:48:56 2006
@@ -56,7 +56,7 @@
Just raise a AttributeError to indicate traversal has failed
and let Zope do it's job.
"""
- raise AttributeError, name
+ raise NotImplementedError
__fallback_traverse__.__five_method__ = True
def __bobo_traverse__(self, REQUEST, name):
@@ -86,6 +86,14 @@
AttributeError, KeyError, NotFound):
pass
try:
+ return self.__fallback_traverse__(REQUEST, name)
+ except NotImplementedError:
+ pass
+ # TODO: This should at least make an attempt to deal with
+ # potential WebDAV issues, in particular we should not perform
+ # acquisition for webdav requests. See BaseRequest.traverse for
+ # details.
+ try:
return getattr(self, name)
except AttributeError:
pass
@@ -93,7 +101,8 @@
return self[name]
except (AttributeError, KeyError):
pass
- return self.__fallback_traverse__(REQUEST, name)
+ raise AttributeError, name
+
__bobo_traverse__.__five_method__ = True
More information about the z3-checkins
mailing list