[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture - __init__.py:1.1.2.1 component-meta.zcml:1.1.2.1 component.zcml:1.1.2.1 metaConfigure.py:1.1.2.1
Jim Fulton
jim@zope.com
Thu, 30 May 2002 14:26:58 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv20275/lib/python/Zope/App/ComponentArchitecture
Added Files:
Tag: Zope3InWonderland-branch
__init__.py component-meta.zcml component.zcml
metaConfigure.py
Log Message:
Implemented browser:page directives for browser:view, browser:resource.
Implemented security assertions in view and resource directives.
Changed defaultView so you can omit a factory, which just sets the
default view name without defining a view.
Moved Browser and ComponentArchitecture directive support to App,
because of all of the dependencies on other packages.
=== Added File Zope3/lib/python/Zope/App/ComponentArchitecture/__init__.py ===
##############################################################################
#
# Copyright (c) 2002 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.
#
##############################################################################
"""Component Architecture Configuration
This package provides configuration of the component architecture for
use in Zope.
"""
=== Added File Zope3/lib/python/Zope/App/ComponentArchitecture/component-meta.zcml ===
<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
<directives namespace="http://namespaces.zope.org/zope">
<directive name="adapter" attributes="factory, provides, for"
handler="Zope.App.ComponentArchitecture.metaConfigure.adapter" />
<directive name="utility" attributes="component, provides"
handler="Zope.App.ComponentArchitecture.metaConfigure.utility" />
<directive name="factory" attributes="component, factory_id"
handler="Zope.App.ComponentArchitecture.metaConfigure.factory" />
<directive
name="view"
attributes="component, type, name, for, layer,
permission_id, allowed_interface, allowed_attributes"
handler="Zope.App.ComponentArchitecture.metaConfigure.view" />
<directive name="defaultView"
attributes="component, type, name, for, layer"
handler="Zope.App.ComponentArchitecture.metaConfigure.defaultView" />
<directive
name="resource"
attributes="component, type, name, layer,
permission_id, allowed_interface, allowed_attributes"
handler="Zope.App.ComponentArchitecture.metaConfigure.resource" />
<directive name="skin" attributes="name, type, layers"
handler="Zope.App.ComponentArchitecture.metaConfigure.skin" />
<directive name="serviceType" attributes="name, interface"
handler="Zope.App.ComponentArchitecture.metaConfigure.serviceType" />
<directive name="service" attributes="name, component"
handler="Zope.App.ComponentArchitecture.metaConfigure.service" />
</directives>
</zopeConfigure>
=== Added File Zope3/lib/python/Zope/App/ComponentArchitecture/component.zcml ===
<zopeConfigure
xmlns='http://namespaces.zope.org/zope'
xmlns:security='http://namespaces.zope.org/security'
xmlns:zmi='http://namespaces.zope.org/zmi'
xmlns:browser='http://namespaces.zope.org/browser'
>
<serviceType name='Utilities'
interface='.IUtilityService+' />
<service name='Utilities'
component='.GlobalUtilityService.utilityService' />
<security:protectClass class=".GlobalUtilityService+"
permission_id="Zope.Public">
<security:protect interface=".IUtilityService+"
permission_id="Zope.Public" />
<security:protect names="provideUtility"
permission_id="Zope.ManageServices" />
</security:protectClass>
<serviceType name='Adapters'
interface='.IAdapterService+' />
<service name='Adapters'
component='.GlobalAdapterService.adapterService' />
<security:protectClass class=".GlobalAdapterService+"
permission_id="Zope.Public">
<security:protect interface=".IAdapterService+"
permission_id="Zope.Public" />
<security:protect names="provideAdapter"
permission_id="Zope.ManageServices" />
</security:protectClass>
<serviceType name='Factories'
interface='.IFactoryService+' />
<service name='Factories'
component='.GlobalFactoryService.factoryService' />
<security:protectClass class=".GlobalFactoryService+"
permission_id="Zope.Public">
<security:protect interface=".IFactoryService+"
permission_id="Zope.Public" />
<security:protect names="provideFactory"
permission_id="Zope.ManageServices" />
</security:protectClass>
<serviceType name='Skins'
interface='.ISkinService+' />
<service name='Skins'
component='.GlobalSkinService.skinService' />
<security:protectClass class=".GlobalSkinService+"
permission_id="Zope.Public">
<security:protect interface=".ISkinService+"
permission_id="Zope.Public" />
<security:protect names="defineSkin"
permission_id="Zope.ManageServices" />
</security:protectClass>
<serviceType name='Views'
interface='.IViewService+' />
<service name='Views'
component='.GlobalViewService.viewService' />
<security:protectClass class=".GlobalViewService+"
permission_id="Zope.Public">
<security:protect interface=".IViewService+"
permission_id="Zope.Public" />
<security:protect names="provideView, setDefaultViewName"
permission_id="Zope.ManageServices" />
</security:protectClass>
<serviceType name='Resources'
interface='.IResourceService+' />
<service name='Resources'
component='.GlobalResourceService.resourceService' />
<security:protectClass class=".GlobalResourceService+"
permission_id="Zope.Public">
<security:protect interface=".IResourceService+"
permission_id="Zope.Public" />
<security:protect names="provideResource"
permission_id="Zope.ManageServices" />
</security:protectClass>
<hookable name=".getServiceManager" />
<hookable name=".getNextServiceManager" />
</zopeConfigure>
=== Added File Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py ===
##############################################################################
#
# 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.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.
#
##############################################################################
from Zope.Configuration.Exceptions import ConfigurationError
from Zope.Security.Proxy import Proxy
from Zope.ComponentArchitecture import getService, getServiceManager
from Zope.Configuration import namespace
from Interface import Interface
from Zope.Configuration.Action import Action
from Zope.Security.Proxy import Proxy
from Zope.Security.Checker \
import InterfaceChecker, CheckerPublic, NamesChecker, Checker
# I prefer the indirection (using getService and getServiceManager vs.
# directly importing the various services) not only because it makes
# unit tests easier, but also because it reinforces that the services
# should always be obtained through the
# IPlacefulComponentArchitecture interface methods
def handler(serviceName, methodName, *args, **kwargs):
method=getattr(getService(None, serviceName), methodName)
method(*args, **kwargs)
def managerHandler(methodName, *args, **kwargs):
method=getattr(getServiceManager(None), methodName)
method(*args, **kwargs)
def adapter(_context, factory, provides, for_=None, permission_id=None):
if for_ is not None: for_ = _context.resolve(for_)
provides = _context.resolve(provides)
factory = map(_context.resolve, factory.split())
if permission_id is not None:
if permission_id == 'Zope.Public':
permission_id = CheckerPublic
checker = InterfaceChecker(provides, permission_id)
factory.append(lambda c: Proxy(c, checker))
return [
Action(
discriminator = ('adapter', for_, provides),
callable = handler,
args = ('Adapters', 'provideAdapter', for_, provides, factory),
)
]
def utility(_context, component, provides, permission_id=None):
provides = _context.resolve(provides)
component = _context.resolve(component)
if permission_id is not None:
if permission_id == 'Zope.Public':
permission_id = CheckerPublic
checker = InterfaceChecker(provides, permission_id)
component = Proxy(component, checker)
return [
Action(
discriminator = ('utility', provides),
callable = handler,
args = ('Utilities', 'provideUtility', provides, component),
)
]
def factory(_context, component, factory_id=None):
if factory_id is None:
factory_id = component
component = _context.resolve(component)
return [
Action(
discriminator = ('factory', factory_id),
callable = handler,
args = ('Factories','provideFactory',factory_id, component),
)
]
def _checker(_context, permission_id, allowed_interface, allowed_attributes):
if (not allowed_attributes) and (not allowed_interface):
raise ConfigurationError(
"Must specify allowed_interface or allowed_names "
"to be allowed with permission_id.")
if permission_id == 'Zope.Public':
permission_id = CheckerPublic
require={}
for name in (allowed_attributes or '').split():
require[name] = permission_id
if allowed_interface:
for name in _context.resolve(allowed_interface).names(1):
require[name] = permission_id
checker = Checker(require.get)
return checker
def resource(_context, factory, type, name, layer='',
permission_id=None,
allowed_interface=None, allowed_attributes=None):
if ((allowed_attributes or allowed_interface)
and (not permission_id)):
raise ConfigurationError(
"Must use name attribute with allowed_interface or "
"allowed_attributes"
)
type = _context.resolve(type)
factory = _context.resolve(factory)
if permission_id:
checker = _checker(_context, permission_id,
allowed_interface, allowed_attributes)
def proxyResource(request, factory=factory, checker=checker):
return Proxy(factory(request), checker)
factory = proxyResource
return [
Action(
discriminator = ('resource', name, type, layer),
callable = handler,
args = ('Resources','provideResource',
name, type, factory, layer),
)
]
def view(_context, factory, type, name, for_=None, layer='',
permission_id=None, allowed_interface=None, allowed_attributes=None):
if ((allowed_attributes or allowed_interface)
and (not permission_id)):
raise ConfigurationError(
"Must use name attribute with allowed_interface or "
"allowed_attributes"
)
if for_ is not None: for_ = _context.resolve(for_)
type = _context.resolve(type)
factory = map(_context.resolve, factory.strip().split())
if not factory:
raise ConfigurationError("No view factory specified.")
if permission_id:
checker = _checker(_context, permission_id,
allowed_interface, allowed_attributes)
def proxyView(context, request, factory=factory[-1], checker=checker):
return Proxy(factory(context, request), checker)
factory[-1] = proxyView
return [
Action(
discriminator = ('view', for_, name, type, layer),
callable = handler,
args = ('Views','provideView',for_, name, type, factory, layer),
)
]
def defaultView(_context, type, name, factory=None, for_=None, layer='',
permission_id=None,
allowed_interface=None, allowed_attributes=None):
if factory is None:
if (permission_id or allowed_attributes or allowed_interface):
raise ConfigurationError(
"Must specify a factory with permission_id, "
"allowed_interface, or allowed_attributes.")
actions = []
else:
actions = view(_context, factory, type, name, for_, layer,
permission_id, allowed_interface, allowed_attributes)
if for_ is not None:
for_ = _context.resolve(for_)
type = _context.resolve(type)
actions += [Action(
discriminator = ('defaultViewName', for_, name, type),
callable = handler,
args = ('Views','setDefaultViewName', for_, type, name),
)]
return actions
def serviceType(_context, name, interface):
return [
Action(
discriminator = ('serviceType', name),
callable = managerHandler,
args = ('defineService',name, _context.resolve(interface)),
)
]
def service(_context, name, component):
component = _context.resolve(component)
return [
Action(
discriminator = ('service', name),
callable = managerHandler,
args = ('provideService', name, component),
)
]
def skin(_context, name, layers, type):
type = _context.resolve(type)
layers = [layer.strip() for layer in layers.split(',')]
return [
Action(
discriminator = ('skin', name, type),
callable = handler,
args = ('Skins','defineSkin',name, type, layers)
)
]