[Zope3-checkins] CVS: Zope3/src/zope/app/traversing - adapters.py:1.12

Steve Alexander steve@cat-box.net
Fri, 20 Jun 2003 02:53:56 -0400


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

Modified Files:
	adapters.py 
Log Message:
Add a nasty hack to make traversing methods work from page templates.

Right now, there's very unintuitive behaviour when traversing methods
in a page template. If a path ends in a method, it gets called, as it
has a __call__ attribute.
However, if you want to do something to the result of calling that
method, you can't just append a name to your existing path.
So, in general, callables aren't called when traversing.
I think a special case should be made for things like methods.

I'll discuss this with Jim later today, and hopefully remove the nasty
hack and replace it with a good hack ;-)


=== Zope3/src/zope/app/traversing/adapters.py 1.11 => 1.12 ===
--- Zope3/src/zope/app/traversing/adapters.py:1.11	Fri Jun 13 13:41:20 2003
+++ Zope3/src/zope/app/traversing/adapters.py	Fri Jun 20 02:53:56 2003
@@ -31,7 +31,7 @@
 
 from zope.interface import implements
 
-from types import StringTypes
+from types import StringTypes, MethodType
 
 __metaclass__ = type
 _marker = object()  # opaque marker that doesn't get security proxied
@@ -50,6 +50,12 @@
         subject = self._subject
         r = getattr(subject, name, _marker)
         if r is not _marker:
+            # XXX It is pretty obvious that we should call methods.
+            #     That much is expected from page templates.
+            #     What about classmethods / staticmethods / other descriptors?
+            #     What about methods that take several arguments?
+            if r.__class__ == MethodType:
+                return r()
             return r
 
         if hasattr(subject, '__getitem__'):