[Checkins] SVN: zope.generic/trunk/src/zope/generic/ informationprovider directive:

Dominik Huber dominik.huber at perse.ch
Mon Apr 24 12:33:22 EDT 2006


Log message for revision 67571:
  informationprovider directive:
  
  - rename data attribute of the configuration subdirective to configuration.
  
  - add annotation subdirective

Changed:
  U   zope.generic/trunk/src/zope/generic/informationprovider/README.txt
  U   zope.generic/trunk/src/zope/generic/informationprovider/meta.zcml
  U   zope.generic/trunk/src/zope/generic/informationprovider/metaconfigure.py
  U   zope.generic/trunk/src/zope/generic/informationprovider/metadirectives.py
  U   zope.generic/trunk/src/zope/generic/operation/base.py
  U   zope.generic/trunk/src/zope/generic/type/EXAMPLE.txt
  U   zope.generic/trunk/src/zope/generic/type/README.txt

-=-
Modified: zope.generic/trunk/src/zope/generic/informationprovider/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/README.txt	2006-04-24 15:52:20 UTC (rev 67570)
+++ zope.generic/trunk/src/zope/generic/informationprovider/README.txt	2006-04-24 16:33:21 UTC (rev 67571)
@@ -97,43 +97,21 @@
     >>> info is None
     True
 
-Information providers are annotable
------------------------------------
+Information providers are extentable by informations
+----------------------------------------------------
 
+At the moment informations are an abstraction for annotations and
+configurations.
+
 Information providers are annotable. The annotations mechanism is used to provide
-additional informations in a generic manner:
+additional informations in a well-known manner. At the moment there are no 
+configurations:
 
-    >>> from zope.app.annotation.interfaces import IAnnotations
+    >>> api.queryInformation(info, 'example.my_annotation') is None
+    True
 
-    >>> info = api.queryInformationProvider(IFooMarker, ISpecialInformation)
-
-    >>> annotations = IAnnotations(info)
-    >>> annotations.get('test.annotation')
-    >>> annotations['test.annotation']
-    Traceback (most recent call last):
-    ...
-    KeyError: 'test.annotation'
-    >>> list(annotations.keys())
-    []
-    >>> del annotations['test.annotation']
-    Traceback (most recent call last):
-    ...
-    KeyError: 'test.annotation'
-    >>> annotations['test.annotation'] = 'a'
-    >>> annotations.get('test.annotation')
-    'a'
-    >>> annotations['test.annotation']
-    'a'
-    >>> list(annotations.keys())
-    ['test.annotation']
-    >>> del annotations['test.annotation']
-
-
-Information providers are configurable
---------------------------------------
-
 Information providers are configurable. The configurations mechanism is used 
-to provide additional configurations in a generic manner. A configuration
+to provide additional configurations in a generic manner too. A configuration
 is declared by a configuration schema providing IConfigurationType:
 
     >>> from zope.schema import TextLine
@@ -153,17 +131,22 @@
     >>> IConfigurationType.providedBy(IMyConfiguration)
     True
 
-We now can use this configuration to extend our information provider of the
-key interface IFooMarker. At the moment there are no configurations:
+At the moment there are no configurations:
 
     >>> api.queryInformation(info, IMyConfiguration) is None
     True
 
-The configuration subdirective of the information provider directive provides a mechanism
-to register further configurations to an information provider:
+We now can use an annotation and a configuration to extend our information
+provider of the key interface IFooMarker.
 
+The annotation and configuration subdirective of the information provider
+directive provides a mechanism to register further informations to an 
+information provider:
+
+    >>> my_annotation = object()
+
     >>> from zope.generic.configuration.api import ConfigurationData
-    >>> my_information_config = ConfigurationData(IMyConfiguration, {'my': u'My!'})
+    >>> my_configuration = ConfigurationData(IMyConfiguration, {'my': u'My!'})
 
     >>> registerDirective('''
     ... <generic:informationProvider
@@ -171,18 +154,26 @@
     ...     registry="example.ISpecialInformation"
     ...     label='Foo Specials' hint='Bla bla foo.'
     ...     >
+    ...        <annotation
+    ...            key="example.my_annotation"
+    ...            annotation="example.my_annotation"
+    ...            />
     ...        <configuration
     ...            keyface="example.IMyConfiguration"
-    ...            data="example.my_information_config"
+    ...            configuration="example.my_configuration"
     ...            />
     ...     </generic:informationProvider>
     ... ''')
 
     >>> info = api.queryInformationProvider(IFooMarker, ISpecialInformation)
-    >>> api.queryInformation(info, IMyConfiguration) is my_information_config
+    >>> api.queryInformation(info, 'example.my_annotation') is my_annotation
     True
 
+    >>> info = api.queryInformationProvider(IFooMarker, ISpecialInformation)
+    >>> api.queryInformation(info, IMyConfiguration) is my_configuration
+    True
 
+
 Configurations
 ---------------
 

Modified: zope.generic/trunk/src/zope/generic/informationprovider/meta.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/meta.zcml	2006-04-24 15:52:20 UTC (rev 67570)
+++ zope.generic/trunk/src/zope/generic/informationprovider/meta.zcml	2006-04-24 16:33:21 UTC (rev 67571)
@@ -15,6 +15,11 @@
           schema=".metadirectives.IConfigurationSubdirective"
           />
 
+      <meta:subdirective
+          name="annotation"
+          schema=".metadirectives.IAnnotationSubdirective"
+          />
+
     </meta:complexDirective>
 
   </meta:directives>

Modified: zope.generic/trunk/src/zope/generic/informationprovider/metaconfigure.py
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/metaconfigure.py	2006-04-24 15:52:20 UTC (rev 67570)
+++ zope.generic/trunk/src/zope/generic/informationprovider/metaconfigure.py	2006-04-24 16:33:21 UTC (rev 67571)
@@ -18,6 +18,7 @@
 
 __docformat__ = 'restructuredtext'
 
+from zope.app.annotation import IAnnotations
 from zope.app.component.interface import provideInterface
 from zope.component import provideUtility
 from zope.configuration.exceptions import ConfigurationError
@@ -77,16 +78,26 @@
 
 
 
-def provideConfiguration(keyface, registry, configuration, data):
-    """Provide configuration for a certain type marker."""
+def provideConfiguration(keyface, registry, configuration_keyface, configuration):
+    """Provide a configuration for a certain type marker."""
 
     info = queryInformationProvider(keyface, registry)
     
     configurations = IConfigurations(info)
-    configurations[configuration] = data
+    configurations[configuration_keyface] = configuration
 
 
 
+def provideAnnotation(keyface, registry, annotation_key, annotation):
+    """Provide an annotation for a certain type marker."""
+
+    info = queryInformationProvider(keyface, registry)
+    
+    annotations = IAnnotations(info)
+    annotations[annotation_key] = annotation
+
+
+
 class InformationProviderDirective(object):
     """Provide a new information of a certain information registry."""
     
@@ -123,14 +134,25 @@
         "Handle empty/simple declaration."
         return ()
 
-    def configuration(self, _context, keyface, data):
+    def configuration(self, _context, keyface, configuration):
+        """Add a configuration to the information provider."""
         # preconditions
-        if not keyface.providedBy(data):
+        if not keyface.providedBy(configuration):
             raise ConfigurationError('Data attribute must provide %s.' % keyface.__name__)
 
         _context.action(
             discriminator = (
-            'InformationConfiguration', self._keyface, self._registry, keyface),
+            'informationprovider.configuration', self._keyface, self._registry, keyface),
             callable = provideConfiguration,
-            args = (self._keyface, self._registry, keyface, data),
+            args = (self._keyface, self._registry, keyface, configuration),
             )
+
+    def annotation(self, _context, key, annotation):
+        """Add an annotation to the information provider."""
+
+        _context.action(
+            discriminator = (
+            'informationprovider.annotation', self._keyface, self._registry, key),
+            callable = provideAnnotation,
+            args = (self._keyface, self._registry, key, annotation),
+            )

Modified: zope.generic/trunk/src/zope/generic/informationprovider/metadirectives.py
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/metadirectives.py	2006-04-24 15:52:20 UTC (rev 67570)
+++ zope.generic/trunk/src/zope/generic/informationprovider/metadirectives.py	2006-04-24 16:33:21 UTC (rev 67571)
@@ -23,6 +23,7 @@
 from zope.configuration.fields import GlobalObject
 from zope.configuration.fields import MessageID
 from zope.interface import Interface
+from zope.schema import DottedName
 
 from zope.generic.informationprovider import IInformationProvider
 
@@ -74,9 +75,25 @@
         required=True
         )
 
-    data = GlobalObject(
-        title=_('Data'),
-        description=_('Configuration data component providing the configuraiton interface.'),
+    configuration = GlobalObject(
+        title=_('Configuration'),
+        description=_('Configuration component providing the key interface.'),
         required=True
         )
 
+
+
+class IAnnotationSubdirective(Interface):
+    """Declare a certain configuration of a type."""
+
+    key = DottedName(
+        title=_('Interface'),
+        description=_('Interface referencing a configuraiton.'),
+        required=True
+        )
+
+    annotation = GlobalObject(
+        title=_('Annotation'),
+        description=_('Annotation component expected undert the key.'),
+        required=True
+        )

Modified: zope.generic/trunk/src/zope/generic/operation/base.py
===================================================================
--- zope.generic/trunk/src/zope/generic/operation/base.py	2006-04-24 15:52:20 UTC (rev 67570)
+++ zope.generic/trunk/src/zope/generic/operation/base.py	2006-04-24 16:33:21 UTC (rev 67571)
@@ -49,9 +49,6 @@
             self.__keyface__ = IPrivateOperation
 
     def __call__(self, context, *pos, **kws):
-        return self._proceed(context, *pos, **kws)
-
-    def _proceed(self, context, *pos, **kws):
         # this method can be overwritten by subclasses
         if self._callable is not None:
             return self._callable(context, *pos, **kws)
@@ -65,7 +62,7 @@
         super(OperationPipe, self).__init__(None, keyface, input, output)
         self._operations = operations
 
-    def _proceed(self, context, *pos, **kws):
+    def __call__(self, context, *pos, **kws):
         """Invoke operation in the listed order."""
         last_output = argumentsToConfiguration(self._input, *pos, **kws)
         for operation in self._operations:

Modified: zope.generic/trunk/src/zope/generic/type/EXAMPLE.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/type/EXAMPLE.txt	2006-04-24 15:52:20 UTC (rev 67570)
+++ zope.generic/trunk/src/zope/generic/type/EXAMPLE.txt	2006-04-24 16:33:21 UTC (rev 67571)
@@ -117,7 +117,7 @@
     ...    />
     ...    <configuration
     ...        keyface='example.ITextConfig'
-    ...        data='example.textDefaults'
+    ...        configuration='example.textDefaults'
     ...    />
     ... </generic:type>
     ... ''')
@@ -132,7 +132,7 @@
     ...    />
     ...    <configuration
     ...        keyface='example.INoteConfig'
-    ...        data='example.noteDefaults'
+    ...        configuration='example.noteDefaults'
     ...    />
     ... </generic:type>
     ... ''')
@@ -148,11 +148,11 @@
     ...    />
     ...    <configuration
     ...        keyface='example.ITextConfig'
-    ...        data='example.articleTextDefaults'
+    ...        configuration='example.articleTextDefaults'
     ...    />
     ...    <configuration
     ...        keyface='example.INoteConfig'
-    ...        data='example.articleNoteDefaults'
+    ...        configuration='example.articleNoteDefaults'
     ...    />
     ... </generic:type>
     ... ''')

Modified: zope.generic/trunk/src/zope/generic/type/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/type/README.txt	2006-04-24 15:52:20 UTC (rev 67570)
+++ zope.generic/trunk/src/zope/generic/type/README.txt	2006-04-24 16:33:21 UTC (rev 67571)
@@ -164,7 +164,7 @@
     ...	   />
     ...	   <configuration
     ...	       keyface='example.IAnyConfiguration'
-    ...        data='example.typedata'
+    ...        configuration='example.typedata'
     ...	   />
     ...    <configurationAdapter
     ...        keyface='example.IAnyConfiguration'



More information about the Checkins mailing list