[Checkins] SVN: zope.generic/trunk/src/zope/generic/ cosmetics and
usability changes
Dominik Huber
dominik.huber at perse.ch
Wed Apr 12 11:12:59 EDT 2006
Log message for revision 66895:
cosmetics and usability changes
proposal TODO for the next refactoring iteration
Changed:
U zope.generic/trunk/src/zope/generic/configuration/api.py
U zope.generic/trunk/src/zope/generic/configuration/helper.py
U zope.generic/trunk/src/zope/generic/operation/README.txt
U zope.generic/trunk/src/zope/generic/operation/api.py
U zope.generic/trunk/src/zope/generic/operation/base.py
U zope.generic/trunk/src/zope/generic/operation/helper.py
U zope.generic/trunk/src/zope/generic/operation/metaconfigure.py
A zope.generic/trunk/src/zope/generic/type/TODO.txt
-=-
Modified: zope.generic/trunk/src/zope/generic/configuration/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/api.py 2006-04-12 14:40:04 UTC (rev 66894)
+++ zope.generic/trunk/src/zope/generic/configuration/api.py 2006-04-12 15:12:58 UTC (rev 66895)
@@ -20,6 +20,7 @@
from zope.generic.configuration.base import ConfigurationData
from zope.generic.configuration.interfaces import *
from zope.generic.configuration.helper import deleteConfigurationData
+from zope.generic.configuration.helper import getConfigurationData
from zope.generic.configuration.helper import provideConfigurationData
from zope.generic.configuration.helper import queryConfigurationData
from zope.generic.configuration.helper import queryConfigurationHandler
Modified: zope.generic/trunk/src/zope/generic/configuration/helper.py
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/helper.py 2006-04-12 14:40:04 UTC (rev 66894)
+++ zope.generic/trunk/src/zope/generic/configuration/helper.py 2006-04-12 15:12:58 UTC (rev 66895)
@@ -43,18 +43,22 @@
+def getConfigurationData(context, interface):
+ """Evaluate corresponding configuration data satisfying the interface."""
+ return interface(IConfigurations(context))
+
+
+
def queryConfigurationData(context, interface, default=None):
"""Evaluate corresponding configuration data satisfying the interface."""
try:
- configurations = IConfigurations(context)
+ return getConfigurationData(context, interface)
except:
return default
- return interface(configurations, default)
-
def provideConfigurationData(context, interface, data):
"""Set configuration data into the context."""
from zope.generic.configuration.base import ConfigurationData
Modified: zope.generic/trunk/src/zope/generic/operation/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/operation/README.txt 2006-04-12 14:40:04 UTC (rev 66894)
+++ zope.generic/trunk/src/zope/generic/operation/README.txt 2006-04-12 15:12:58 UTC (rev 66895)
@@ -101,12 +101,16 @@
... />
... ''')
-Step 2: Build a complex operation by using the base operations
---------------------------------------------------------------
+Step 2: Build a complex operation reusing the base operations
+-------------------------------------------------------------
+There is a new interface marking the combined operation:
+
>>> class IMakeSiteSetupPAUConfigureAnythingOperation(interface.Interface):
... """Use the other three operation as nested information."""
+Maybe you need an extra configuration:
+
>>> class IComplexConfig(interface.Interface):
... """Output complex configuration."""
... pau = TextLine()
@@ -114,15 +118,22 @@
... any_b = TextLine()
... any_c = TextLine()
- >>> def privateOperation(context, *pos, **kws):
- ... print 'privateOperation'
-
>>> registerDirective('''
... <generic:configuration
... interface="example.IComplexConfig"
... />
... ''')
+Sometimes you like to extend the base operation. Therefore you can include a simple
+function. It's not necessary to register such a private function as a public
+function using the operation directive:
+
+ >>> def privateOperation(context, *pos, **kws):
+ ... print 'privateOperation'
+
+At least we register the complex operation using the operation marker interfaces
+and the private operation:
+
>>> registerDirective('''
... <generic:operation
... interface="example.IMakeSiteSetupPAUConfigureAnythingOperation"
@@ -142,10 +153,20 @@
>>> len(listing)
4
- >>> config = api.queryOperationConfiguration(IMakeSiteSetupPAUConfigureAnythingOperation)
- >>> config.operation(None)
+We can retrieve any registered operation by the following function:
+
+ >>> operation = api.queryOperation(IMakeSiteSetupPAUConfigureAnythingOperation)
+
+ >>> operation(None)
makeSiteOperation
setupPAUOperation
configureAnythingOperation
privateOperation
+ >>> [c.__name__ for c in api.queryOperationInput(IMakeSiteSetupPAUConfigureAnythingOperation)]
+ ['IComplexConfig']
+
+ >>> [c.__name__ for c in api.queryOperationOutput(IMakeSiteSetupPAUConfigureAnythingOperation)]
+ []
+
+
Modified: zope.generic/trunk/src/zope/generic/operation/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/operation/api.py 2006-04-12 14:40:04 UTC (rev 66894)
+++ zope.generic/trunk/src/zope/generic/operation/api.py 2006-04-12 15:12:58 UTC (rev 66895)
@@ -20,5 +20,9 @@
from zope.generic.operation.interfaces import *
from zope.generic.operation.helper import getOperationInformation
+from zope.generic.operation.helper import getOperationConfiguration
from zope.generic.operation.helper import queryOperationInformation
from zope.generic.operation.helper import queryOperationConfiguration
+from zope.generic.operation.helper import queryOperation
+from zope.generic.operation.helper import queryOperationInput
+from zope.generic.operation.helper import queryOperationOutput
Modified: zope.generic/trunk/src/zope/generic/operation/base.py
===================================================================
--- zope.generic/trunk/src/zope/generic/operation/base.py 2006-04-12 14:40:04 UTC (rev 66894)
+++ zope.generic/trunk/src/zope/generic/operation/base.py 2006-04-12 15:12:58 UTC (rev 66895)
@@ -42,13 +42,13 @@
else:
self.interface = IPrivateOperation
- def __call__(self, context):
+ def __call__(self, context, *pos, **kws):
self._proceed(context)
- def _proceed(self, context):
+ def _proceed(self, context, *pos, **kws):
# this method can be overwritten by subclasses
if self.__callable is not None:
- return self.__callable(context)
+ self.__callable(context, *pos, **kws)
@@ -59,6 +59,6 @@
super(OperationChain, self).__init__(None, interface)
self.__operations = operations
- def _proceed(self, context):
+ def _proceed(self, context, *pos, **kws):
"""Invoke operation in the listed order."""
[operation(context) for operation in self.__operations]
Modified: zope.generic/trunk/src/zope/generic/operation/helper.py
===================================================================
--- zope.generic/trunk/src/zope/generic/operation/helper.py 2006-04-12 14:40:04 UTC (rev 66894)
+++ zope.generic/trunk/src/zope/generic/operation/helper.py 2006-04-12 15:12:58 UTC (rev 66895)
@@ -19,7 +19,7 @@
__docformat__ = 'restructuredtext'
from zope.generic.information.api import getInformation
-from zope.generic.configuration.api import queryConfigurationData
+from zope.generic.configuration.api import getConfigurationData
from zope.generic.operation import IOperationInformation
from zope.generic.operation import IOperationConfiguration
@@ -42,11 +42,50 @@
-def queryOperationConfiguration(object, default=None):
+def getOperationConfiguration(object):
"""Evaluate an operation configuration."""
+
+ return getConfigurationData(getOperationInformation(object), IOperationConfiguration)
- info = queryOperationInformation(object, default)
- if info is default:
+
+
+def queryOperationConfiguration(object, default=None):
+ """Evaluate an operation configuration or default."""
+ try:
+ return getOperationConfiguration(object)
+
+ except:
return default
-
- return queryConfigurationData(info, IOperationConfiguration)
+
+
+
+def queryOperation(interface, default=None):
+ """Return the operation of operation marker."""
+
+ try:
+ return getOperationConfiguration(interface).operation
+
+ except:
+ return default
+
+
+
+def queryOperationInput(interface, default=None):
+ """Return the input paramters of an operation as tuple of configuration interfaces."""
+
+ try:
+ return getOperationConfiguration(interface).input
+
+ except:
+ return default
+
+
+
+def queryOperationOutput(interface, default=None):
+ """Return the ouput paramters of an operation as tuple of configuration interfaces."""
+
+ try:
+ return getOperationConfiguration(interface).output
+
+ except:
+ return default
Modified: zope.generic/trunk/src/zope/generic/operation/metaconfigure.py
===================================================================
--- zope.generic/trunk/src/zope/generic/operation/metaconfigure.py 2006-04-12 14:40:04 UTC (rev 66894)
+++ zope.generic/trunk/src/zope/generic/operation/metaconfigure.py 2006-04-12 15:12:58 UTC (rev 66895)
@@ -88,7 +88,7 @@
configurations = IConfigurations(info)
# create and set configuration data
provideConfigurationData(info, IOperationConfiguration,
- {'operation': operation, 'input': input, 'output': output})
+ {'operation': operation, 'input': tuple(input), 'output': tuple(output)})
Added: zope.generic/trunk/src/zope/generic/type/TODO.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/type/TODO.txt 2006-04-12 14:40:04 UTC (rev 66894)
+++ zope.generic/trunk/src/zope/generic/type/TODO.txt 2006-04-12 15:12:58 UTC (rev 66895)
@@ -0,0 +1,26 @@
+====
+TODO
+====
+
+ logical type
+ >>> class IFoo(Interface):
+ ... """IFoo bla."""
+
+ >>> foo = api.createObject(IFoo)
+
+ >>> foo.__key_interface__ == IFoo
+ True
+ >>> IKeyInterface(foo) == IFoo
+ True
+ >>> type_registration = IType(foo) # heute type_information
+ >>> type_registration.__key_interface__ == IFoo
+ True
+ >>> type_registration.label
+ u'example.IFoo'
+ >>> type_registration.hint
+ u'Foo bla'
+ >>> IConfigurations.providedBy(type_registration)
+ True
+ >>> any_type_config = IAnyConfig(type_registration)
+ >>> IAnyConfig.providedBy(any_type_config)
+ True
\ No newline at end of file
Property changes on: zope.generic/trunk/src/zope/generic/type/TODO.txt
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Checkins
mailing list