[Zope3-checkins] CVS: Zope3/src/zope/app/component - decoratorservice.py:1.1.2.1 configure.zcml:1.3.24.2 hooks.py:1.5.8.1

Steve Alexander steve@cat-box.net
Wed, 14 May 2003 03:36:39 -0400


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

Modified Files:
      Tag: stevea-decorators-branch
	configure.zcml hooks.py 
Added Files:
      Tag: stevea-decorators-branch
	decoratorservice.py 
Log Message:
Added stubs to allow two pairs to work together on decorators.


=== Added File Zope3/src/zope/app/component/decoratorservice.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Global registry of decorators.

$Id: decoratorservice.py,v 1.1.2.1 2003/05/14 07:36:08 stevea Exp $
"""

# class -> IDecoratorSpec
_reg = {}

queryDecoratorSpec = _reg.get



=== Zope3/src/zope/app/component/configure.zcml 1.3.24.1 => 1.3.24.2 ===
--- Zope3/src/zope/app/component/configure.zcml:1.3.24.1	Tue May 13 13:41:35 2003
+++ Zope3/src/zope/app/component/configure.zcml	Wed May 14 03:36:08 2003
@@ -1,61 +1,87 @@
 <zopeConfigure
    xmlns='http://namespaces.zope.org/zope'
-   package="zope.component"
 >
 
-<serviceType id='Utilities'
-             interface='zope.component.interfaces.IUtilityService' />
-<service serviceType='Utilities'
-         permission='zope.Public'
-         component='zope.component.utility.utilityService' />
-           
-<serviceType id='Adapters'
-             interface='zope.component.interfaces.IAdapterService' />
-<service serviceType='Adapters'
-         permission='zope.Public'
-         component='zope.component.adapter.adapterService' />
-
-<serviceType id='Factories'
-             interface='zope.component.interfaces.IFactoryService' />
-<service serviceType='Factories'
-         permission='zope.Public'
-         component='zope.component.factory.factoryService' />
-
-<serviceType id='Skins'
-             interface='zope.component.interfaces.ISkinService' />
-<service serviceType='Skins'
-         permission='zope.Public'
-         component='zope.component.skin.skinService' />
-
-<serviceType id='Views' 
-             interface='zope.component.interfaces.IViewService' />
-<service serviceType='Views'
-         permission='zope.Public'
-         component='zope.component.view.viewService' />
-         
-<serviceType id='Resources'
-             interface='zope.component.interfaces.IResourceService' />
-<service serviceType='Resources'
-         permission='zope.Public'
-         component='zope.component.resource.resourceService' />
-         
-<hookable name=".getServiceManager" />
-
-<hook module="zope.component"
-      name="getServiceManager"
-      implementation="zope.app.component.hooks.getServiceManager_hook" />
+<serviceType
+    id='Utilities'
+    interface='zope.component.interfaces.IUtilityService'
+    />
+<service
+    serviceType='Utilities'
+    permission='zope.Public'
+    component='zope.component.utility.utilityService'
+    />
+<serviceType
+    id='Adapters'
+    interface='zope.component.interfaces.IAdapterService'
+    />
+<service
+    serviceType='Adapters'
+    permission='zope.Public'
+    component='zope.component.adapter.adapterService'
+    />
+<serviceType
+    id='Factories'
+    interface='zope.component.interfaces.IFactoryService'
+    />
+<service
+    serviceType='Factories'
+    permission='zope.Public'
+    component='zope.component.factory.factoryService'
+    />
+<serviceType
+    id='Skins'
+    interface='zope.component.interfaces.ISkinService'
+    />
+<service
+    serviceType='Skins'
+    permission='zope.Public'
+    component='zope.component.skin.skinService'
+    />
+<serviceType
+    id='Views'
+    interface='zope.component.interfaces.IViewService'
+    />
+<service
+    serviceType='Views'
+    permission='zope.Public'
+    component='zope.component.view.viewService'
+    />
+<serviceType
+    id='Resources'
+    interface='zope.component.interfaces.IResourceService'
+    />
+<service
+    serviceType='Resources'
+    permission='zope.Public'
+    component='zope.component.resource.resourceService'
+    />
+
+<hookable name="zope.component.getServiceManager" />
+
+<hook
+    module="zope.component"
+    name="getServiceManager"
+    implementation="zope.app.component.hooks.getServiceManager_hook"
+    />
 
 <serviceType
     id='Interfaces'
-    interface='zope.app.interfaces.component.IInterfaceService' />
-   
-<service 
+    interface='zope.app.interfaces.component.IInterfaceService'
+    />
+<service
    serviceType='Interfaces'
    permission='zope.Public'
-   component='zope.app.component.globalinterfaceservice.interfaceService' />
+   component='zope.app.component.globalinterfaceservice.interfaceService'
+   />
 
 <interface interface="zope.interface.Interface" />
 
-</zopeConfigure>
-
+<hookable name="zope.proxy.context.ContextWrapper" />
+<hook
+    module="zope.proxy.context"
+    name="ContextWrapper"
+    implementation="zope.app.component.hooks.ContextWrapper_hook"
+    />
 
+</zopeConfigure>


=== Zope3/src/zope/app/component/hooks.py 1.5 => 1.5.8.1 ===
--- Zope3/src/zope/app/component/hooks.py:1.5	Thu May  1 15:35:07 2003
+++ Zope3/src/zope/app/component/hooks.py	Wed May 14 03:36:08 2003
@@ -22,9 +22,15 @@
 from zope.proxy.introspection import removeAllProxies
 from zope.security.proxy import trustedRemoveSecurityProxy
 from zope.app.traversing import IContainmentRoot
+from zope.proxy.context.wrapper import Wrapper
+from zope.app.component.decoratorservice import queryDecoratorSpec
+from zope.security.proxy import Proxy, getChecker, getObject
+from zope.proxy.context.decorator import Decorator
+from zope.security.checker import selectChecker, BasicTypes
 
 def getServiceManager_hook(context, local=False):
-    """
+    """Get a service manager based on context.
+
     context based lookup, with fallback to component architecture
     service manager if no service manager found within context
     """
@@ -53,7 +59,62 @@
                     raise TypeError("Not enough context to get next "
                                     "service manager")
                 break
-            
+
         context = container
 
     return serviceManager
+
+def ContextWrapper_hook(_ob, _parent, **kw):
+    """
+    """
+    t = type(_ob)
+    if t in BasicTypes:
+        # Don't wrap basic objects
+        return _ob
+
+    cls = getattr(ob, '__class__', None)
+    if cls is not None:
+        decorator_spec = queryDecoratorSpec(cls)
+        if decorator_spec is not None:
+            return decorate(spec, _ob, _parent, kw)
+    if t is Proxy:
+        # insert into proxies
+        checker = getChecker(_ob)
+        _ob = getObject(_ob)
+        _ob = Proxy(Wrapper(_ob, _parent, kw), checker)
+    else:
+        _ob = Wrapper(_ob, _parent, kw)
+
+    return _ob
+
+def decorate(spec, ob, parent, kw):
+    """
+    """
+    if t is Proxy:
+        checker = getChecker(ob)
+        obj_nosecurityproxy = getObject(ob)
+    else:
+        checker = None
+        obj_nosecurityproxy = ob
+
+    if not spec.mixinIsTrusted:
+        # if t is not Proxy:
+        #     get a security checker for ob
+        #     wrap ob
+        inner = ob
+    else:
+        inner = None
+
+    # If the object is not security proxied, but we have a permission-map
+    # with the decorator specification, then we should use a special factory
+    # that adds a checker based on the permission map to the new mixin
+    # instance. Perhaps.
+    
+    # Make a composite checker from the existing checker, and the
+    # permission-map.
+    # Put this checker in the __Security_checker__ attribute of the decorator
+    # so that security checks will use this, rather than the ordinary one
+    # for the decorated object.
+    
+    # Make a composite __providedBy__ attribute from the mixinInterfaceSpec
+    # and what the decorated object provides.