[Checkins] SVN: zope.generic/trunk/src/zope/generic/ remove
.configurator and .controller
Dominik Huber
dominik.huber at perse.ch
Wed Apr 12 08:07:15 EDT 2006
Log message for revision 66883:
remove .configurator and .controller
add new .operation package
Changed:
U zope.generic/trunk/src/zope/generic/configuration/helper.py
D zope.generic/trunk/src/zope/generic/configurator/
D zope.generic/trunk/src/zope/generic/controller/
U zope.generic/trunk/src/zope/generic/information/api.py
U zope.generic/trunk/src/zope/generic/information/helper.py
U zope.generic/trunk/src/zope/generic/information/metaconfigure.py
A zope.generic/trunk/src/zope/generic/operation/
U zope.generic/trunk/src/zope/generic/operation/README.txt
U zope.generic/trunk/src/zope/generic/operation/SETUP.cfg
U zope.generic/trunk/src/zope/generic/operation/__init__.py
A zope.generic/trunk/src/zope/generic/operation/api.py
A zope.generic/trunk/src/zope/generic/operation/base.py
A zope.generic/trunk/src/zope/generic/operation/helper.py
U zope.generic/trunk/src/zope/generic/operation/interfaces.py
A zope.generic/trunk/src/zope/generic/operation/meta.zcml
A zope.generic/trunk/src/zope/generic/operation/metaconfigure.py
A zope.generic/trunk/src/zope/generic/operation/metadirectives.py
A zope.generic/trunk/src/zope/generic/operation/testing.py
A zope.generic/trunk/src/zope/generic/operation/tests.py
D zope.generic/trunk/src/zope/generic/operation/zope.generic.controller-configure.zcml
A zope.generic/trunk/src/zope/generic/operation/zope.generic.operation-configure.zcml
A zope.generic/trunk/src/zope/generic/operation/zope.generic.operation-meta.zcml
-=-
Modified: zope.generic/trunk/src/zope/generic/configuration/helper.py
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/helper.py 2006-04-12 11:32:11 UTC (rev 66882)
+++ zope.generic/trunk/src/zope/generic/configuration/helper.py 2006-04-12 12:07:12 UTC (rev 66883)
@@ -45,14 +45,13 @@
def queryConfigurationData(context, interface, default=None):
"""Evaluate corresponding configuration data satisfying the interface."""
+ try:
+ configurations = IConfigurations(context)
- configurations = IConfigurations(context, default)
-
- if configurations is default:
+ except:
return default
- else:
- return interface(configurations, default)
+ return interface(configurations, default)
Modified: zope.generic/trunk/src/zope/generic/information/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/information/api.py 2006-04-12 11:32:11 UTC (rev 66882)
+++ zope.generic/trunk/src/zope/generic/information/api.py 2006-04-12 12:07:12 UTC (rev 66883)
@@ -20,6 +20,7 @@
from zope.generic.information.interfaces import *
from zope.generic.information.base import Information
+from zope.generic.information.helper import getInformation
from zope.generic.information.helper import queryInformation
from zope.generic.information.helper import queryInformationRegistry
from zope.generic.information.helper import registeredInformations
Modified: zope.generic/trunk/src/zope/generic/information/helper.py
===================================================================
--- zope.generic/trunk/src/zope/generic/information/helper.py 2006-04-12 11:32:11 UTC (rev 66882)
+++ zope.generic/trunk/src/zope/generic/information/helper.py 2006-04-12 12:07:12 UTC (rev 66883)
@@ -42,12 +42,12 @@
else:
interface = IInterfaceKey(object).interface
- #return interface
return getUtility(registry, toDottedName(interface))
def queryInformation(interface, registry, default=None):
+ """Request an information or return default."""
try:
return getInformation(interface, registry)
Modified: zope.generic/trunk/src/zope/generic/information/metaconfigure.py
===================================================================
--- zope.generic/trunk/src/zope/generic/information/metaconfigure.py 2006-04-12 11:32:11 UTC (rev 66882)
+++ zope.generic/trunk/src/zope/generic/information/metaconfigure.py 2006-04-12 12:07:12 UTC (rev 66883)
@@ -34,7 +34,7 @@
-def provideInformation(interface, registry, label=None, hint=None, factory=None):
+def provideInformation(interface, registry=IInformationRegistryInformation, label=None, hint=None, factory=None):
"""Provide new information for the given registry-interface.
Register an information as utiliy under registry-interface using
Copied: zope.generic/trunk/src/zope/generic/operation (from rev 66848, zope.generic/trunk/src/zope/generic/controller)
Modified: zope.generic/trunk/src/zope/generic/operation/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/README.txt 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/README.txt 2006-04-12 12:07:12 UTC (rev 66883)
@@ -1,22 +1,151 @@
-==========
-Controller
-==========
+=========
+Operation
+=========
-The controller is a single instance registered for an interface-key marker
-registered as generic type.
+Step 1: A few people develop generic base operations
+----------------------------------------------------
+An operation is a reusable processing unit. The unit is also marked by a
+dedicated interface:
+
+ >>> class IMakeSiteOperation(interface.Interface):
+ ... """This operation makes a folderish context to a site."""
+
+ >>> class ISetupPAUOperation(interface.Interface):
+ ... """Setup a PAU within the context."""
+
+ >>> class IConfigureAnythingOperation(interface.Interface):
+ ... """Write a configuration."""
+
+
+If needed we have specify new or we can reuse existing input and output
+configuration schema.
+
+ >>> from zope.schema import TextLine
+
+ >>> class IPAUConfig(interface.Interface):
+ ... """Configuration information to setup a pau."""
+ ... a = TextLine(required=False, default=u'Default pau config.')
+
+ >>> class IAnyInputConfig(interface.Interface):
+ ... """Input configuration for the any application."""
+ ... a = TextLine()
+ ... b = TextLine(required=False)
+ ... c = TextLine(required=False)
+
+ >>> class IAConfig(interface.Interface):
+ ... """Output a configuration."""
+ ... a = TextLine()
+
+ >>> class IBConfig(interface.Interface):
+ ... """Output b configuration."""
+ ... b = TextLine()
+
+
>>> registerDirective('''
- ... <generic:controller
- ... interface="example.IBarMarker"
- ... class='zope.generic.type.api.Object'
- ... >
- ... <initializer
- ... interface='example.IOtherConfiguration'
- ... handler='example.barInitializer'
- ... />
- ... <configuration
- ... interface='example.IAnyConfiguration'
- ... data='example.typedata'
- ... />
- ... </generic:type>
+ ... <generic:configuration
+ ... interface="example.IPAUConfig"
+ ... />
+ ... ''')
+
+ >>> registerDirective('''
+ ... <generic:configuration
+ ... interface="example.IAnyInputConfig"
+ ... />
+ ... ''')
+
+ >>> registerDirective('''
+ ... <generic:configuration
+ ... interface="example.IAConfig"
+ ... />
+ ... ''')
+
+ >>> registerDirective('''
+ ... <generic:configuration
+ ... interface="example.IBConfig"
+ ... />
+ ... ''')
+
+The operation can be implemented in different ways:
+
+ >>> def makeSiteOperation(context, *pos, **kws):
+ ... print 'makeSiteOperation'
+
+ >>> def setupPAUOperation(context, *pos, **kws):
+ ... print 'setupPAUOperation'
+
+ >>> def configureAnythingOperation(context, *pos, **kws):
+ ... print 'configureAnythingOperation'
+
+
+ >>> registerDirective('''
+ ... <generic:operation
+ ... interface="example.IMakeSiteOperation"
+ ... operations="example.makeSiteOperation"
+ ... />
... ''')
+
+ >>> registerDirective('''
+ ... <generic:operation
+ ... interface="example.ISetupPAUOperation"
+ ... operations="example.setupPAUOperation"
+ ... input="example.IPAUConfig"
+ ... />
+ ... ''')
+
+ >>> registerDirective('''
+ ... <generic:operation
+ ... interface="example.IConfigureAnythingOperation"
+ ... operations="example.configureAnythingOperation"
+ ... input="example.IPAUConfig"
+ ... />
+ ... ''')
+
+Step 2: Build a complex operation by using the base operations
+--------------------------------------------------------------
+
+ >>> class IMakeSiteSetupPAUConfigureAnythingOperation(interface.Interface):
+ ... """Use the other three operation as nested information."""
+
+ >>> class IComplexConfig(interface.Interface):
+ ... """Output complex configuration."""
+ ... pau = TextLine()
+ ... any_a = TextLine()
+ ... any_b = TextLine()
+ ... any_c = TextLine()
+
+ >>> def privateOperation(context, *pos, **kws):
+ ... print 'privateOperation'
+
+ >>> registerDirective('''
+ ... <generic:configuration
+ ... interface="example.IComplexConfig"
+ ... />
+ ... ''')
+
+ >>> registerDirective('''
+ ... <generic:operation
+ ... interface="example.IMakeSiteSetupPAUConfigureAnythingOperation"
+ ... operations="example.IMakeSiteOperation example.setupPAUOperation
+ ... example.configureAnythingOperation example.privateOperation"
+ ... input="example.IComplexConfig"
+ ... output=""
+ ... />
+ ... ''')
+
+For each operation directive we registered an operation information. This
+operation information can be retrieved:
+
+ >>> from zope.generic.information.api import registeredInformations
+
+ >>> listing = list(registeredInformations(api.IOperationInformation))
+ >>> len(listing)
+ 4
+
+ >>> config = api.queryOperationConfiguration(IMakeSiteSetupPAUConfigureAnythingOperation)
+ >>> config.operation(None)
+ makeSiteOperation
+ setupPAUOperation
+ configureAnythingOperation
+ privateOperation
+
Modified: zope.generic/trunk/src/zope/generic/operation/SETUP.cfg
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/SETUP.cfg 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/SETUP.cfg 2006-04-12 12:07:12 UTC (rev 66883)
@@ -1,3 +1,3 @@
<data-files zopeskel/etc/package-includes>
- zope.generic.controller-*.zcml
+ zope.generic.operation-*.zcml
</data-files>
\ No newline at end of file
Modified: zope.generic/trunk/src/zope/generic/operation/__init__.py
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/__init__.py 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/__init__.py 2006-04-12 12:07:12 UTC (rev 66883)
@@ -16,4 +16,4 @@
$Id$
"""
-from zope.generic.configurator.interfaces import *
\ No newline at end of file
+from zope.generic.operation.interfaces import *
\ No newline at end of file
Added: zope.generic/trunk/src/zope/generic/operation/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/api.py 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/api.py 2006-04-12 12:07:12 UTC (rev 66883)
@@ -0,0 +1,24 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+# usage see README.txt
+from zope.generic.operation.interfaces import *
+
+from zope.generic.operation.helper import getOperationInformation
+from zope.generic.operation.helper import queryOperationInformation
+from zope.generic.operation.helper import queryOperationConfiguration
Property changes on: zope.generic/trunk/src/zope/generic/operation/api.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/operation/base.py
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/base.py 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/base.py 2006-04-12 12:07:12 UTC (rev 66883)
@@ -0,0 +1,64 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+from zope.interface import implements
+from zope.schema.fieldproperty import FieldProperty
+
+from zope.generic.operation import IOperation
+from zope.generic.operation import IPrivateOperation
+
+
+
+class Operation(object):
+ """Generic operation wrapper."""
+
+ implements(IOperation)
+
+ interface = FieldProperty(IOperation['interface'])
+
+ def __init__(self, callable=None, interface=None):
+ self.__callable = callable
+
+ # otherwise use IPrivatConfigurationHandler
+ if interface is not None:
+ self.interface = interface
+ else:
+ self.interface = IPrivateOperation
+
+ def __call__(self, context):
+ self._proceed(context)
+
+ def _proceed(self, context):
+ # this method can be overwritten by subclasses
+ if self.__callable is not None:
+ return self.__callable(context)
+
+
+
+class OperationChain(Operation):
+ """Generic operation chain wrapper."""
+
+ def __init__(self, operations, interface=None):
+ super(OperationChain, self).__init__(None, interface)
+ self.__operations = operations
+
+ def _proceed(self, context):
+ """Invoke operation in the listed order."""
+ [operation(context) for operation in self.__operations]
Property changes on: zope.generic/trunk/src/zope/generic/operation/base.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/operation/helper.py
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/helper.py 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/helper.py 2006-04-12 12:07:12 UTC (rev 66883)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+from zope.generic.information.api import getInformation
+from zope.generic.configuration.api import queryConfigurationData
+
+from zope.generic.operation import IOperationInformation
+from zope.generic.operation import IOperationConfiguration
+
+
+
+def getOperationInformation(object):
+ """Evaluate an operation information from an object."""
+ return getInformation(object, IOperationInformation)
+
+
+
+def queryOperationInformation(object, default=None):
+ """Evaluate an operation information from an object or return default."""
+ try:
+ return getOperationInformation(object)
+
+ except:
+ return default
+
+
+
+def queryOperationConfiguration(object, default=None):
+ """Evaluate an operation configuration."""
+
+ info = queryOperationInformation(object, default)
+ if info is default:
+ return default
+
+ return queryConfigurationData(info, IOperationConfiguration)
Property changes on: zope.generic/trunk/src/zope/generic/operation/helper.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: zope.generic/trunk/src/zope/generic/operation/interfaces.py
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/interfaces.py 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/interfaces.py 2006-04-12 12:07:12 UTC (rev 66883)
@@ -18,142 +18,92 @@
__docformat__ = 'restructuredtext'
-from zope.app.annotation import IAnnotations
from zope.app.i18n import ZopeMessageFactory as _
+from zope.interface import alsoProvides
from zope.interface import Interface
+from zope.interface.interfaces import IInterface
from zope.schema import Bool
from zope.schema import Object
from zope.schema import Tuple
from zope.generic.component import IInterfaceKey
-from zope.generic.configuration import IConfiguraitons
+from zope.generic.configuration import IConfigurationType
+from zope.generic.information import IInformation
+from zope.generic.information import IInformationRegistryType
from zope.generic.type import ITypeType
-class IHandler(Interface):
- """ """
- def __call__(controller, event=None):
- """Handle the controller's context."""
+class IContextProxy(Interface):
+ """Proxy the context of a component."""
+ def __conform__(interface):
+ """Might cache adapters."""
+ def __getattr__(name):
+ """Get an attribute of
+ """
+ def __setattr__(name, value):
+ """Set an attribute of."""
-class IHandlerConfiguration(Interface):
- """Tell the controller which handler should be invoked."""
- preHandlers = Tuple(title=_('Pre-Handlers'),
- description=_('Handler that should be invoked before the Super-Call.'),
- required=False,
- default=(),
- value_type=Object(schema=IHandler))
- postHandlers = Tuple(title=_('Post-Handlers'),
- description=_('Handler that should be invoked after the Super-Call.'),
- required=False,
- default=(),
- value_type=Object(schema=IHandler))
+class IOperation(IInterfaceKey):
+ """Proceed operation"""
- callSupers = Bool(title=_('Call Super'),
- description=_('Should the supers be called?'),
- default=False)
+ def __call__(context, *pos, **kws):
+ """Proceed the operation on the given context.
-class IInitializeConfiguration(IHandlerConfiguration):
- """Configuration for initializer handlers."""
+ Public operation requires zero to n configuations.
+ The configuration can be passed as *pos, **kws. If no arguments are
+ passed the operation should lookup the declared configurations on the
+ context.
+
+ If pos we assume one configuration or dict in order to the declared order.
+ If not pos we extact the kws as configuration data
+ """
-class IModifyConfiguration(IHandlerConfiguration):
- """Configuration for adder handlers."""
-class IAddConfiguration(IHandlerConfiguration):
- """Configuration for adder handlers."""
+class IOperationInformation(IInformation):
+ """Registration about an global operation."""
-class IMoveConfiguration(IHandlerConfiguration):
- """Configuration for adder handlers."""
+alsoProvides(IOperationInformation, IInformationRegistryType)
-class IRemoveConfiguration(IHandlerConfiguration):
- """Configuration for adder handlers."""
+class IOperationType(IInterface):
+ """Mark operation marker interface."""
-class IUpdateConfiguration(IHandlerConfiguration):
- """Configuration for adder handlers."""
-alsoProvides(IControllerConfiguration, IConfigurationType)
+class IPrivateOperation(Interface):
+ """Mark private callables."""
-class IListener(IInterfaceKey):
- """Listen as a subscriber to events defined by the interface."""
+alsoProvides(IPrivateOperation, IOperationType)
- def __call__(component, event):
- """Redirect the call to the controller.
- name = toDottedName()
- controller = IController(component, event)
-
-
-
-
- """
+class IOperationConfiguration(Interface):
+ """Tell the controller which handler should be invoked."""
+ operation = Object(title=_('Operation'),
+ description=_('Callable operation.'),
+ required=False,
+ schema=IOperation)
-class IController(Interface):
- """Apply dedicated handlers to a component context.
+ input = Tuple(title=_('Input Configurations'),
+ description=_('Tuple of configuration schema that will be respected.'),
+ required=False,
+ default=(),
+ value_type=Object(schema=IConfigurationType))
- The controller should invoke the handler in a object-oriented manner.
+ output = Tuple(title=_('Output Configurations'),
+ description=_('Tuple of configuration schema that might be modified or created.'),
+ required=False,
+ default=(),
+ value_type=Object(schema=IConfigurationType))
- Object-orientation provides an overwrites-mechanism within an inheritance
- hierarchy. There are to possibilities for an certain class of that
- inheritance tree to be invoke by a call:
-
- def method(x):
- # before the supers will be called
- any_pre_super_call_procedures(x)
- # super call
- super_call(x)
- # after the supers were called.
- any_post_super_call_procedures(x)
-
- We can observe an generalizing information flow from specialized to
- generalized (preSuperCall) and an specializing information flow
- from generalized to specialized (postSuperCall). an configurator will
- """
- context = Object(title=_('Context'),
- description=_('The context that should be configured.'),
- default=True)
-
- def __call__(event=None):
- """Apply the handlers.
-
- First invoke the pre-handlers defined by the interface-inheritance order
- of the interface-key marker as listed in inface-key.flattened() call if
- the interface provides ITypeType.
-
- Second invoke the post-handlers in the inverse order.
-
- id = ITyped(component).interface
- if callSupers:
- interfaces = [iface for iface in id.flattened if ITypeType.providedBy(iface)]
- else:
- interfaces = [id]
-
- for iface in interfaces:
- getAdapter(component, [IController], name=toDottedName(id))
-
- """
-
- configurations = Object(
- title=_('Configurations'),
- description=_('The configurations of the component.'),
- required=False,
- readonly=True,
- schema=IConfigurations)
-
- annotations = Object(
- title=_('Annotations'),
- description=_('The annotations of the component.'),
- required=False,
- readonly=True,
- schema=IAnnotations)
+alsoProvides(IOperationConfiguration, IConfigurationType)
Added: zope.generic/trunk/src/zope/generic/operation/meta.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/meta.zcml 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/meta.zcml 2006-04-12 12:07:12 UTC (rev 66883)
@@ -0,0 +1,15 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:meta="http://namespaces.zope.org/meta">
+
+ <meta:directives namespace="http://namespaces.zope.org/generic">
+
+ <meta:directive
+ name="operation"
+ schema=".metadirectives.IOperationDirective"
+ handler=".metaconfigure.operationDirective"
+ />
+
+ </meta:directives>
+
+</configure>
Property changes on: zope.generic/trunk/src/zope/generic/operation/meta.zcml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/operation/metaconfigure.py
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/metaconfigure.py 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/metaconfigure.py 2006-04-12 12:07:12 UTC (rev 66883)
@@ -0,0 +1,114 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 Projekt01 GmbH 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+from zope.app.component.interface import provideInterface
+from zope.configuration.exceptions import ConfigurationError
+from zope.interface import alsoProvides
+
+from zope.generic.information.api import queryInformation
+from zope.generic.information.metaconfigure import provideInformation
+
+from zope.generic.configuration import IConfigurationType
+from zope.generic.configuration import IConfigurations
+from zope.generic.configuration.api import ConfigurationData
+from zope.generic.configuration.api import provideConfigurationData
+from zope.generic.configuration.api import queryConfigurationData
+
+from zope.generic.operation import IOperation
+from zope.generic.operation import IOperationConfiguration
+from zope.generic.operation import IOperationInformation
+from zope.generic.operation import IOperationType
+from zope.generic.operation.base import Operation
+from zope.generic.operation.base import OperationChain
+
+
+def _assertOperation(handler, interface=None):
+ """Assert that we get an operation."""
+
+ if IOperation.providedBy(handler):
+ return handler
+
+ if IOperationType.providedBy(handler):
+ registry = IOperationInformation
+ info = queryInformation(handler, IOperationInformation)
+
+ if info is None:
+ ConfigurationError('Operation %s does not exist.' % handler.__name__)
+
+ config = queryConfigurationData(info, IOperationConfiguration)
+
+ if config is None:
+ ConfigurationError('OperationConfiguration for Operation %s does not exist.' % handler.__name__)
+
+ return config.operation
+
+ # asume callabe (context)
+ return Operation(handler, interface)
+
+
+
+def provideOperationConfiguration(interface, operations=(), input=(), output=()):
+ """Provide the handler to an configuration information."""
+
+ registry = IOperationInformation
+ info = queryInformation(interface, IOperationInformation)
+
+ # this should never happen...
+ if info is None:
+ ConfigurationError('No operation information for %s'
+ % interface.__name__)
+
+ if len(operations) == 0:
+ # hidding overwrite -> pass handler
+ operation = _assertOperation(None, interface)
+
+ elif len(operations) == 1:
+ operation = _assertOperation(operations[0], interface)
+
+ else:
+ operation = OperationChain([_assertOperation(handler) for handler in operations], interface)
+
+ configurations = IConfigurations(info)
+ # create and set configuration data
+ provideConfigurationData(info, IOperationConfiguration,
+ {'operation': operation, 'input': input, 'output': output})
+
+
+
+def operationDirective(_context, interface, operations=(), input=(), output=(), label=None, hint=None):
+ """Register a public operation."""
+
+ # assert type as soon as possible
+ if not IOperationType.providedBy(interface):
+ alsoProvides(interface, IOperationType)
+
+ registry = IOperationInformation
+
+ _context.action(
+ discriminator = ('provideInformation', interface, registry),
+ callable = provideInformation,
+ args = (interface, registry, label, hint),
+ )
+
+ _context.action(
+ discriminator = ('provideOperationConfiguration', interface),
+ callable = provideOperationConfiguration,
+ args = (interface, operations, input, output),
+ )
Property changes on: zope.generic/trunk/src/zope/generic/operation/metaconfigure.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/operation/metadirectives.py
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/metadirectives.py 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/metadirectives.py 2006-04-12 12:07:12 UTC (rev 66883)
@@ -0,0 +1,53 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+from zope.app.i18n import ZopeMessageFactory as _
+from zope.configuration.fields import GlobalInterface
+from zope.configuration.fields import GlobalObject
+from zope.configuration.fields import Tokens
+
+from zope.generic.configuration import IConfigurationType
+from zope.generic.information.metadirectives import IBaseInformationDirective
+
+
+
+class IOperationDirective(IBaseInformationDirective):
+ """Register a public operation.
+
+ The operation will be registered as interface utility typed by IOperationType.
+ """
+
+ operations = Tokens(
+ title=_('Operation or IOperationType'),
+ description=_('Global operation or callable(context) or IOperationType interface.'),
+ required=False,
+ value_type=GlobalObject()
+ )
+
+ input = Tokens(title=_('Input Configurations'),
+ description=_('Tuple of configuration schema that will be respected.'),
+ required=False,
+ value_type=GlobalInterface())
+
+ output = Tokens(title=_('Output Configurations'),
+ description=_('Tuple of configuration schema that might be modified or created.'),
+ required=False,
+ value_type=GlobalInterface())
+
\ No newline at end of file
Property changes on: zope.generic/trunk/src/zope/generic/operation/metadirectives.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/operation/testing.py
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/testing.py 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/testing.py 2006-04-12 12:07:12 UTC (rev 66883)
@@ -0,0 +1,86 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+from zope.configuration.xmlconfig import XMLConfig
+
+import zope.app.testing.placelesssetup
+import zope.generic.component.testing
+import zope.generic.configuration.testing
+import zope.generic.directlyprovides.testing
+import zope.generic.information.testing
+import zope.generic.operation
+import zope.generic.testing.testing
+
+from zope.generic.information.api import provideInformation
+from zope.generic.operation import IOperationInformation
+
+
+
+################################################################################
+#
+# Public Test implementations
+#
+################################################################################
+
+
+################################################################################
+#
+# Placeless setup
+#
+################################################################################
+
+# specific tests
+def setUp(doctest=None):
+ # register operation information registry
+ provideInformation(IOperationInformation)
+
+ # register the directive of this package
+ XMLConfig('meta.zcml', zope.generic.operation)()
+
+def tearDown(doctest=None):
+ pass
+
+
+
+class PlacelessSetup(zope.app.testing.placelesssetup.PlacelessSetup):
+
+ def setUp(self, doctest=None):
+ super(PlacelessSetup, self).setUp(doctest)
+ # external setup
+ zope.generic.testing.testing.setUp(doctest)
+ zope.generic.directlyprovides.testing.setUp(doctest)
+ zope.generic.component.testing.setUp(doctest)
+ zope.generic.information.testing.setUp(doctest)
+ zope.generic.configuration.testing.setUp(doctest)
+ # internal setup
+ setUp(doctest)
+
+ def tearDown(self, doctest=None):
+ super(PlacelessSetup, self).tearDown()
+ # external teardown
+ zope.generic.testing.testing.tearDown(doctest)
+ zope.generic.directlyprovides.testing.tearDown(doctest)
+ zope.generic.component.testing.tearDown(doctest)
+ zope.generic.information.testing.tearDown(doctest)
+ zope.generic.configuration.testing.tearDown(doctest)
+ # internal teardown
+ tearDown(doctest)
+
+placelesssetup = PlacelessSetup()
Property changes on: zope.generic/trunk/src/zope/generic/operation/testing.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/operation/tests.py
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/tests.py 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/tests.py 2006-04-12 12:07:12 UTC (rev 66883)
@@ -0,0 +1,42 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+import unittest
+from zope import component
+from zope import interface
+from zope.testing import doctest
+
+from zope.generic.testing.testing import registerDirective
+
+from zope.generic.operation import api
+from zope.generic.operation import testing
+
+
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocFileSuite('README.txt',
+ setUp=testing.placelesssetup.setUp,
+ tearDown=testing.placelesssetup.tearDown,
+ globs={'component': component, 'interface': interface,
+ 'registerDirective': registerDirective,
+ 'testing': testing, 'api': api},
+ optionflags=doctest.NORMALIZE_WHITESPACE+
+ doctest.ELLIPSIS),
+ ))
+
+if __name__ == '__main__': unittest.main()
Property changes on: zope.generic/trunk/src/zope/generic/operation/tests.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Deleted: zope.generic/trunk/src/zope/generic/operation/zope.generic.controller-configure.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/zope.generic.controller-configure.zcml 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/zope.generic.controller-configure.zcml 2006-04-12 12:07:12 UTC (rev 66883)
@@ -1,5 +0,0 @@
-<configure xmlns="http://namespaces.zope.org/zope">
-
- <include package="zope.generic.controller" />
-
-</configure>
Added: zope.generic/trunk/src/zope/generic/operation/zope.generic.operation-configure.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/zope.generic.operation-configure.zcml 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/zope.generic.operation-configure.zcml 2006-04-12 12:07:12 UTC (rev 66883)
@@ -0,0 +1,5 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+ <include package="zope.generic.operation" />
+
+</configure>
Property changes on: zope.generic/trunk/src/zope/generic/operation/zope.generic.operation-configure.zcml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/operation/zope.generic.operation-meta.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/controller/zope.generic.operation-meta.zcml 2006-04-11 10:33:52 UTC (rev 66848)
+++ zope.generic/trunk/src/zope/generic/operation/zope.generic.operation-meta.zcml 2006-04-12 12:07:12 UTC (rev 66883)
@@ -0,0 +1,5 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+ <include package="zope.generic.operation" file="meta.zcml" />
+
+</configure>
Property changes on: zope.generic/trunk/src/zope/generic/operation/zope.generic.operation-meta.zcml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Checkins
mailing list