[Zope3-checkins] SVN: Zope3/branches/srichter-blow-services/src/zope/app/component/ Some initial code moves. This will break pretty much everything, but I

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Dec 21 18:18:34 EST 2004


Log message for revision 28677:
  Some initial code moves. This will break pretty much everything, but I 
  need this point in order to move even more. ;-)
  

Changed:
  A   Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/
  A   Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/hooks.py
  A   Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/localservice.py
  U   Zope3/branches/srichter-blow-services/src/zope/app/component/hooks.py
  D   Zope3/branches/srichter-blow-services/src/zope/app/component/localservice.py

-=-
Copied: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/hooks.py (from rev 28644, Zope3/branches/srichter-blow-services/src/zope/app/component/hooks.py)
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/hooks.py	2004-12-17 21:36:22 UTC (rev 28644)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/hooks.py	2004-12-21 23:18:34 UTC (rev 28677)
@@ -0,0 +1,78 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Hooks for getting and setting a site in the thread global namespace.
+
+$Id$
+"""
+__docformat__ = 'restructuredtext'
+
+import zope.component
+from zope.component import getService
+from zope.component.interfaces import IServiceService
+from zope.app.site.interfaces import ISite
+from zope.component.service import serviceManager
+from zope.component.exceptions import ComponentLookupError
+from zope.security.proxy import removeSecurityProxy
+from zope.app.traversing.interfaces import IContainmentRoot
+from zope.app.location.interfaces import ILocation
+from zope.app.location import locate
+from zope.interface import Interface
+from zope.component.servicenames import Adapters
+import warnings
+import zope.thread
+
+def getServices_hook(context=None):
+
+    if context is None:
+        return siteinfo.services
+
+    # Deprecated support for a context that isn't adaptable to
+    # IServiceService.  Return the default service manager.
+    try:
+
+
+        # We remove the security proxy because there's no way for
+        # untrusted code to get at it without it being proxied again.
+
+        # We should really look look at this again though, especially
+        # once site managers do less.  There's probably no good reason why
+        # they can't be proxied.  Well, except maybe for performance.
+
+
+        return removeSecurityProxy(IServiceService(context,
+                                                   serviceManager))
+    except ComponentLookupError:
+        return serviceManager
+    
+def queryView(object, name, request, default=None,
+              providing=Interface, context=None):
+    adapters = getService(Adapters, context)
+    view = adapters.queryMultiAdapter((object, request), providing,
+                                      name, default)
+    if ILocation.providedBy(view):
+        locate(view, object, name)
+
+    return view
+
+
+def setHooks():
+    # Hook up a new implementation of looking up views.
+    zope.component.getServices.sethook(getServices_hook)
+    zope.component.queryView.sethook(queryView)
+
+def resetHooks():
+    # Reset hookable functions to original implementation.
+    zope.component.getServices.reset()
+    zope.component.queryView.reset()
+    

Copied: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/localservice.py (from rev 28644, Zope3/branches/srichter-blow-services/src/zope/app/component/localservice.py)

Modified: Zope3/branches/srichter-blow-services/src/zope/app/component/hooks.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/hooks.py	2004-12-21 22:24:53 UTC (rev 28676)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/hooks.py	2004-12-21 23:18:34 UTC (rev 28677)
@@ -18,10 +18,7 @@
 __docformat__ = 'restructuredtext'
 
 import zope.component
-from zope.component import getService
-from zope.component.interfaces import IServiceService
 from zope.app.site.interfaces import ISite
-from zope.component.service import serviceManager
 from zope.component.exceptions import ComponentLookupError
 from zope.security.proxy import removeSecurityProxy
 from zope.app.traversing.interfaces import IContainmentRoot
@@ -81,56 +78,19 @@
     
 def getSite():
     return siteinfo.site
-    
-def getServices_hook(context=None):
 
-    if context is None:
-        return siteinfo.services
-
-    # Deprecated support for a context that isn't adaptable to
-    # IServiceService.  Return the default service manager.
-    try:
-
-
-        # We remove the security proxy because there's no way for
-        # untrusted code to get at it without it being proxied again.
-
-        # We should really look look at this again though, especially
-        # once site managers do less.  There's probably no good reason why
-        # they can't be proxied.  Well, except maybe for performance.
-
-
-        return removeSecurityProxy(IServiceService(context,
-                                                   serviceManager))
-    except ComponentLookupError:
-        return serviceManager
-
 def adapter_hook(interface, object, name='', default=None):
     try:
         return siteinfo.adapter_hook(interface, object, name, default)
     except ComponentLookupError:
         return default
-    
-def queryView(object, name, request, default=None,
-              providing=Interface, context=None):
-    adapters = getService(Adapters, context)
-    view = adapters.queryMultiAdapter((object, request), providing,
-                                      name, default)
-    if ILocation.providedBy(view):
-        locate(view, object, name)
 
-    return view
 
-
 def setHooks():
     # Hook up a new implementation of looking up views.
-    zope.component.getServices.sethook(getServices_hook)
     zope.component.adapter_hook.sethook(adapter_hook)
-    zope.component.queryView.sethook(queryView)
 
 def resetHooks():
     # Reset hookable functions to original implementation.
-    zope.component.getServices.reset()
     zope.component.adapter_hook.reset()
-    zope.component.queryView.reset()
     

Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/localservice.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/localservice.py	2004-12-21 22:24:53 UTC (rev 28676)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/localservice.py	2004-12-21 23:18:34 UTC (rev 28677)
@@ -1,183 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Support for delegation among service managers
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-from zope.interface import implements
-from zope.component.exceptions import ComponentLookupError
-from zope.component.service import serviceManager
-from zope.component.interfaces import IServiceService
-from zope.app.site.interfaces import ISite, ISiteManager
-from zope.testing.cleanup import addCleanUp
-from zope.app.component.hooks import setSite
-from zope.component.service import IGlobalServiceManager
-from zope.security.proxy import removeSecurityProxy
-
-# placeful service manager convenience tools
-
-# TODO: <SteveA> What we really want here is
-#
-# getLocalServices(context)
-# # if context is contained in a service manager, returns the service manager
-# # if context is a service manager, returns context
-# # otherwise, raises ComponentLookupError('Services')
-#
-# getLocalService(context, name):
-# # Returns the local service with that name
-# # This is the same as getService, so why bother? parity.
-# 
-# getNextServices(context, name):
-# # looks up the local service manager, then gets the next higher one
-# # and returns it
-#
-# getNextService(context, name):
-# # Returns the next service manager's service with that name.
-
-
-
-##def getLocalService(context, name):
-##    service = queryLocalService(context, name)
-##    if service is None:
-##        raise ComponentLookupError('service', name)
-##    return service
-##
-##def queryLocalService(context, name, default=None):
-##    try:
-##        sm = getLocalServices(context)
-##        return sm.getService(name)
-##    except ComponentLookupError:
-##        return default
-
-def queryNextService(context, name, default=None):
-    try:
-        return getNextService(context, name)
-    except ComponentLookupError:
-        return default
-
-def getNextService(context, name):
-    """Returns the service with the given name from the next service manager.
-    """
-    return getNextServices(context).getService(name)
-
-def getNextServices(context):
-    """Returns the next service manager to the one that contains `context`.
-    """
-    services = getLocalServices(context).next
-    if IGlobalServiceManager.providedBy(services):
-        services = removeSecurityProxy(services)
-    return services
-
-def queryNextServices(context, default=None):
-    try:
-        return getNextServices(context)
-    except ComponentLookupError:
-        return default
-
-def queryLocalServices(context, default=None):
-    try:
-        return getLocalServices(context)
-    except ComponentLookupError:
-        return default
-
-def getLocalServices(context):
-    """Returns the service manager that contains `context`.
-
-    If `context` is a local service, returns the service manager that
-    contains that service. If `context` is a service manager, returns `context`.
-
-    Otherwise, raises ``ComponentLookupError('Services')``
-    """
-
-    # IMPORTANT
-    #
-    # This is not allowed to use any services to get its job done!
-
-    while not (context is None or
-               ISiteManager.providedBy(context)):
-        context = getattr(context, '__parent__', None)
-    if context is None:
-        raise ComponentLookupError('Services')
-    else:
-        return context
-
-def serviceServiceAdapter(ob):
-    """An adapter ILocation -> IServiceService.
-
-    The ILocation is interpreted flexibly, we just check for
-    ``__parent__``.
-    """
-    current = ob
-    while True:
-        if ISite.providedBy(current):
-            return current.getSiteManager()
-        current = getattr(current, '__parent__', None)
-        if current is None:
-            raise ComponentLookupError("Could not adapt %r to"
-                                       " IServiceService" % (ob, ))
-
-
-def threadSiteSubscriber(event):
-    """A subscriber to BeforeTraverseEvent
-
-    Sets the 'site' thread global if the object traversed is a site.
-    """
-    if ISite.providedBy(event.object):
-        setSite(event.object)
-
-
-def clearThreadSiteSubscriber(event):
-    """A subscriber to EndRequestEvent
-
-    Cleans up the site thread global after the request is processed.
-    """
-    clearSite()
-
-# Clear the site thread global
-clearSite = setSite
-
-addCleanUp(clearSite)
-
-
-class FakeServices:
-    implements(ISiteManager)
-    
-    def __init__(self):
-        self.data = {}
-    
-    def getService(self, name):
-        return self.data[name]
-        
-
-def testingNextService(service, nextservice, servicename):
-    """A helper function that sets up next services for testing
-
-    >>> class MyService:
-    ...     __parent__ = None
-
-    >>> myfakeservice = object()
-    >>> service = MyService()
-    >>> testingNextService(service, myfakeservice, 'foo')
-    >>> getNextService(service, 'foo') is myfakeservice
-    True
-    """
-
-    if service.__parent__ is None:
-        service.__parent__ = FakeServices()
-        service.__parent__.next = FakeServices()
-
-    service.__parent__.next.data[servicename] = nextservice
-        



More information about the Zope3-Checkins mailing list