[Zope3-checkins] CVS: Zope3/src/zope/app/traversing - __init__.py:1.20.14.1 adapters.py:1.6.12.1 configure.zcml:1.7.14.1 namespace.py:1.10.14.1
Grégoire Weber
zope@i-con.ch
Sun, 22 Jun 2003 10:24:04 -0400
Update of /cvs-repository/Zope3/src/zope/app/traversing
In directory cvs.zope.org:/tmp/cvs-serv24874/src/zope/app/traversing
Modified Files:
Tag: cw-mail-branch
__init__.py adapters.py configure.zcml namespace.py
Log Message:
Synced up with HEAD
=== Zope3/src/zope/app/traversing/__init__.py 1.20 => 1.20.14.1 ===
--- Zope3/src/zope/app/traversing/__init__.py:1.20 Sat Apr 12 06:49:09 2003
+++ Zope3/src/zope/app/traversing/__init__.py Sun Jun 22 10:23:33 2003
@@ -16,13 +16,15 @@
$Id$
"""
+
+from zope.interface import moduleProvides
from zope.component import getAdapter
-from zope.app.interfaces.traversing import IObjectName, IContainmentRoot
+from zope.app.interfaces.traversing import IContainmentRoot, ITraversalAPI
from zope.app.interfaces.traversing import ITraverser, IPhysicallyLocatable
-from zope.proxy.context import getWrapperContainer, isWrapper
+from zope.context import getWrapperContainer, isWrapper
-__all__ = ['traverse', 'traverseName', 'objectName', 'getParent',
- 'getParents', 'getPath', 'getRoot', 'canonicalPath', 'joinPath']
+moduleProvides(ITraversalAPI)
+__all__ = tuple(ITraversalAPI)
_marker = object()
@@ -117,12 +119,10 @@
else:
return obj
-def objectName(obj):
+def getName(obj):
"""Get the name an object was traversed via
-
- Raises TypeError if the object is not context-wrapped
"""
- return getAdapter(obj, IObjectName)()
+ return getAdapter(obj, IPhysicallyLocatable).getName()
def getParent(obj):
"""Returns the container the object was traversed via.
=== Zope3/src/zope/app/traversing/adapters.py 1.6 => 1.6.12.1 ===
--- Zope3/src/zope/app/traversing/adapters.py:1.6 Mon Apr 28 09:18:38 2003
+++ Zope3/src/zope/app/traversing/adapters.py Sun Jun 22 10:23:33 2003
@@ -17,19 +17,21 @@
from zope.exceptions import NotFoundError
-from zope.app.interfaces.traversing import IObjectName, IPhysicallyLocatable
+from zope.app.interfaces.traversing import IPhysicallyLocatable
from zope.app.interfaces.traversing import IContainmentRoot
from zope.app.interfaces.traversing import ITraverser, ITraversable
from zope.component import getAdapter, queryAdapter
-from zope.proxy.context import getInnerWrapperData, getWrapperContainer
-from zope.proxy.context import ContextWrapper
+from zope.context import getInnerWrapperData, getWrapperContainer
+from zope.app.context import ContextWrapper
from zope.app.traversing.namespace import namespaceLookup
from zope.app.traversing.namespace import UnexpectedParameters
from zope.app.traversing.namespace import parameterizedNameParse
-from types import StringTypes
+from zope.interface import implements
+
+from types import StringTypes, MethodType
__metaclass__ = type
_marker = object() # opaque marker that doesn't get security proxied
@@ -37,7 +39,7 @@
class DefaultTraversable:
"""Traverses objects via attribute and item lookup"""
- __implements__ = ITraversable
+ implements(ITraversable)
def __init__(self, subject):
self._subject = subject
@@ -48,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 getattr(r, '__class__', 0) == MethodType:
+ return r()
return r
if hasattr(subject, '__getitem__'):
@@ -56,40 +64,10 @@
else:
raise NotFoundError(subject, name)
-class ObjectName(object):
-
- __implements__ = IObjectName
-
- def __init__(self, context):
- self.context = context
-
- def __str__(self):
- dict = getInnerWrapperData(self.context)
- name = dict and dict.get('name') or None
- if name is None:
- raise TypeError, \
- 'Not enough context information to get an object name'
- return name
-
- __call__ = __str__
-
-
-class SiteObjectName(object):
-
- __implements__ = IObjectName
-
- def __init__(self, context):
- pass
-
- def __str__(self):
- return ''
-
- __call__ = __str__
-
class WrapperPhysicallyLocatable:
__doc__ = IPhysicallyLocatable.__doc__
- __implements__ = IPhysicallyLocatable
+ implements(IPhysicallyLocatable)
def __init__(self, context):
self.context = context
@@ -121,10 +99,14 @@
else:
return container_path + u'/' + name
+ def getName(self):
+ "See IPhysicallyLocatable"
+ return getInnerWrapperData(self.context)['name']
+
class RootPhysicallyLocatable:
__doc__ = IPhysicallyLocatable.__doc__
- __implements__ = IPhysicallyLocatable
+ implements(IPhysicallyLocatable)
__used_for__ = IContainmentRoot
@@ -139,10 +121,14 @@
"See IPhysicallyLocatable"
return self.context
+ def getName(self):
+ "See IPhysicallyLocatable"
+ return u''
+
class Traverser:
"""Provide traverse features"""
- __implements__ = ITraverser
+ implements(ITraverser)
# This adapter can be used for any object.
@@ -219,6 +205,10 @@
nm = name
if traversable is None:
+ if obj.__class__ == dict:
+ # Special-case dicts
+ return obj[name]
+
traversable = queryAdapter(obj, ITraversable, None)
if traversable is None:
raise NotFoundError('No traversable adapter found', obj)
=== Zope3/src/zope/app/traversing/configure.zcml 1.7 => 1.7.14.1 ===
--- Zope3/src/zope/app/traversing/configure.zcml:1.7 Tue Apr 15 05:37:26 2003
+++ Zope3/src/zope/app/traversing/configure.zcml Sun Jun 22 10:23:33 2003
@@ -12,20 +12,6 @@
factory="zope.app.traversing.adapters.DefaultTraversable"
provides="zope.app.interfaces.traversing.ITraversable" />
-<adapter
- for="*"
- factory="zope.app.traversing.adapters.ObjectName"
- provides="zope.app.interfaces.traversing.IObjectName"
- permission='zope.Public'
- />
-
-<adapter
- factory="zope.app.traversing.adapters.SiteObjectName"
- provides="zope.app.interfaces.traversing.IObjectName"
- for="zope.app.interfaces.content.folder.IRootFolder"
- permission='zope.Public'
- />
-
<adapter
for="*"
provides="zope.app.interfaces.traversing.IPhysicallyLocatable"
=== Zope3/src/zope/app/traversing/namespace.py 1.10 => 1.10.14.1 ===
--- Zope3/src/zope/app/traversing/namespace.py:1.10 Tue Apr 15 05:37:26 2003
+++ Zope3/src/zope/app/traversing/namespace.py Sun Jun 22 10:23:33 2003
@@ -18,8 +18,8 @@
from zope.interface import Interface
from zope.exceptions import NotFoundError
-from zope.proxy.context import ContextWrapper, getWrapperObject
-from zope.proxy.context import getWrapperContext
+from zope.app.context import ContextWrapper
+from zope.context import getWrapperContext, getWrapperData
from zope.configuration.action import Action
from zope.component import queryAdapter, getAdapter, getServiceManager
from zope.component import queryDefaultViewName, queryView, getService
@@ -74,20 +74,13 @@
# different object. We want to retain the side-effect name
# for things like URLs.
- # But wait, there's more. The object may be wrapped. If the
- # object is already wrapped and we return the object in the
- # context of itself, the containment context will be wrong,
- # because the inner wrapper will be the original object, so
- # our added layer with the name we want to preserve will be
- # ignored when searching containment.
-
- # For this reason, we'll remove a layer of wrapping from new
- # before we put it in context.
-
- new = getWrapperObject(new)
-
- new = ContextWrapper(new, object, name='.', side_effect_name=name)
+ # We'll just at the name to the side-effect names stored in
+ # the object's wrapper.
+ data = getWrapperData(new, create=True)
+ data['side_effect_names'] = (data.get('side_effect_names', ())
+ + (name, )
+ )
else:
new = ContextWrapper(new, object, name=name)