[Zope3-checkins] CVS: Zope3/src/zope/app/component -
configure.zcml:1.9 hooks.py:1.12
Jim Fulton
jim at zope.com
Sun Sep 21 13:31:23 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/component
In directory cvs.zope.org:/tmp/cvs-serv13090/src/zope/app/component
Modified Files:
configure.zcml hooks.py
Log Message:
Got rid of the specialized hook methods for getting adapters.
Added a special queryView method that sets __name__ for views that are
locations.
=== Zope3/src/zope/app/component/configure.zcml 1.8 => 1.9 ===
--- Zope3/src/zope/app/component/configure.zcml:1.8 Sun Aug 3 15:08:16 2003
+++ Zope3/src/zope/app/component/configure.zcml Sun Sep 21 13:31:23 2003
@@ -45,8 +45,8 @@
implementation="zope.app.component.hooks.getServiceManager_hook" />
<hook module="zope.component"
- name="queryNamedAdapter"
- implementation="zope.app.component.hooks.queryNamedAdapter" />
+ name="queryView"
+ implementation="zope.app.component.hooks.queryView" />
<serviceType
id='Interfaces'
=== Zope3/src/zope/app/component/hooks.py 1.11 => 1.12 ===
--- Zope3/src/zope/app/component/hooks.py:1.11 Tue Sep 2 16:46:45 2003
+++ Zope3/src/zope/app/component/hooks.py Sun Sep 21 13:31:23 2003
@@ -21,90 +21,28 @@
from zope.component.exceptions import ComponentLookupError
from zope.component.servicenames import Adapters
from zope.app.interfaces.services.service import ISite
-from zope.app.context import ContextWrapper
-from zope.context import getWrapperContainer, isWrapper, getWrapperData
from zope.component.service import serviceManager
from zope.proxy import removeAllProxies
from zope.security.proxy import trustedRemoveSecurityProxy
from zope.app.traversing import IContainmentRoot
-
-## alog=open('alog','w')
-## slog=open('slog','w')
-## swlog=open('swlog','w')
-## sulog=open('sulog','w')
-## sutblog=open('sutblog','w')
-## nlog=open('nlog','w')
-
-## import sys, traceback
-
-
-
+from zope.app.interfaces.location import ILocation
+from zope.app.location import locate
def getServiceManager_hook(context, local=False, recurse=False):
-
- # XXX Uh, there's this special case for context being none. :(
if context is None:
-## if not recurse:
-## slog.write('n')
-## nlog.write('\n')
-## f = sys._getframe(1)
-## nlog.write("%s\n" % context.__class__)
-## nlog.write(''.join(traceback.format_stack(sys._getframe(1),
-## 5)))
-## nlog.write("\n")
-
return serviceManager
-
- data = None
- wrapped = isWrapper(context)
- if wrapped:
- data = getWrapperData(context, create=True)
-## unwrapped = removeAllProxies(context)
-## oid = id(unwrapped)
-## did = id(data)
-## if not recurse:
-## swlog.write("%s %s %s\n" %
-## (context.__class__.__name__, oid, did))
- cached = data.get('zope.app.component.hooks.sm')
- if cached is not None:
-## if not recurse:
-## slog.write('h')
- return cached
-## else:
-## if not recurse:
-## slog.write('m')
-## else:
-## if not recurse:
-## sulog.write("%s.%s\n" %
-## (context.__class__.__module__,
-## context.__class__.__name__))
-## f = sys._getframe(1)
-## avoid = "src/zope/app/component/hooks.py"
-## if (1 or f.f_back.f_code.co_filename != avoid
-## ):
-## sutblog.write("%s\n" % context.__class__)
-## sutblog.write(''.join(traceback.format_stack(sys._getframe(1),
-## 5)))
-## sutblog.write("\n")
-## slog.write('u')
-
-
clean_context = removeAllProxies(context)
# if the context is actually a service or service manager...
if IServiceService.isImplementedBy(clean_context):
- sm = trustedRemoveSecurityProxy(context)
+ return trustedRemoveSecurityProxy(context)
elif (ISite.isImplementedBy(clean_context)):
- sm = ContextWrapper(
- trustedRemoveSecurityProxy(context.getSiteManager()),
- context,
- name="++etc++site",
- )
+ return trustedRemoveSecurityProxy(context.getSiteManager())
else:
- container = getWrapperContainer(context)
+ container = getattr(context, '__parent__', None)
if container is None:
if local:
# Check to make sure that when we run out of context, we
@@ -120,40 +58,15 @@
# don't have a service manager, so try again, recursively:
sm = getServiceManager_hook(container, local, True)
- # Now cache what we found, cause we might look for it again:
- if wrapped:
- data['zope.app.component.hooks.sm'] = sm
-
return sm
-def queryNamedAdapter(object, interface, name, default=None, context=None):
+
+def queryView(object, name, request, default=None, context=None):
if context is None:
context = object
+ views = getService(context, 'Views')
+ view = views.queryView(object, name, request, default)
+ if ILocation.isImplementedBy(view):
+ locate(view, object, name)
- wrapped = isWrapper(context)
-## alog.write("%s %s.%s %s.%s\n" % (wrapped,
-## context.__class__.__module__,
-## context.__class__.__name__,
-## interface.__module__,
-## interface.getName(),
-## ))
- if wrapped:
- data = getWrapperData(context, create=True)
- adapters = data.get('zope.app.component.hooks.adapters')
- if adapters is None:
- try:
- adapters = getService(context, Adapters)
- except ComponentLookupError:
- # Oh blast, no adapter service. We're probably just
- # running from a test
- return default
- data['zope.app.component.hooks.adapters'] = adapters
- else:
- try:
- adapters = getService(context, Adapters)
- except ComponentLookupError:
- # Oh blast, no adapter service. We're probably just
- # running from a test
- return default
-
- return adapters.queryNamedAdapter(object, interface, name, default)
+ return view
More information about the Zope3-Checkins
mailing list