[Checkins] SVN: zope.generic/trunk/src/zope/generic/ clean up

Dominik Huber dominik.huber at perse.ch
Wed May 3 09:45:45 EDT 2006


Log message for revision 67881:
  clean up
  
  getInformation and derivates refactoring. the new parameter order is:
  
  informationkey, [information], keyface, conface, [default]

Changed:
  U   zope.generic/trunk/src/zope/generic/adapter/property.py
  U   zope.generic/trunk/src/zope/generic/content/EXAMPLE.txt
  U   zope.generic/trunk/src/zope/generic/content/README.txt
  U   zope.generic/trunk/src/zope/generic/content/api.py
  U   zope.generic/trunk/src/zope/generic/content/base.py
  D   zope.generic/trunk/src/zope/generic/content/helper.py
  U   zope.generic/trunk/src/zope/generic/content/interfaces.py
  U   zope.generic/trunk/src/zope/generic/factory/README.txt
  U   zope.generic/trunk/src/zope/generic/factory/api.py
  U   zope.generic/trunk/src/zope/generic/factory/factory.py
  U   zope.generic/trunk/src/zope/generic/informationprovider/NEW_README.txt
  U   zope.generic/trunk/src/zope/generic/informationprovider/README.txt
  U   zope.generic/trunk/src/zope/generic/informationprovider/api.py
  U   zope.generic/trunk/src/zope/generic/informationprovider/base.py
  U   zope.generic/trunk/src/zope/generic/informationprovider/configure.zcml
  U   zope.generic/trunk/src/zope/generic/informationprovider/interfaces.py
  U   zope.generic/trunk/src/zope/generic/informationprovider/metaconfigure.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/metaconfigure.py

-=-
Modified: zope.generic/trunk/src/zope/generic/adapter/property.py
===================================================================
--- zope.generic/trunk/src/zope/generic/adapter/property.py	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/adapter/property.py	2006-05-03 13:45:43 UTC (rev 67881)
@@ -69,7 +69,7 @@
             for registry in self._providers:
                 try:
                     provider = getInformationProvider(context, registry)
-                    configuration = getInformation(provider, keyface)
+                    configuration = getInformation(keyface, provider)
                     break
                 except:
                     pass
@@ -116,7 +116,7 @@
                     for registry in self._providers:
                         try:
                             provider = getInformationProvider(context, registry)
-                            configuration = getInformation(provider, keyface)
+                            configuration = getInformation(keyface, provider)
                             break
                         except:
                             pass

Modified: zope.generic/trunk/src/zope/generic/content/EXAMPLE.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/content/EXAMPLE.txt	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/content/EXAMPLE.txt	2006-05-03 13:45:43 UTC (rev 67881)
@@ -20,8 +20,28 @@
 
     >>> class IArticle(IText, INote):
     ...     """Logical article marker"""
-    
 
+    >>> registerDirective('''
+    ... <generic:interface
+    ...     interface="example.IText"
+    ...     type="zope.generic.face.IKeyfaceType"
+    ...     />
+    ... ''') 
+
+    >>> registerDirective('''
+    ... <generic:interface
+    ...     interface="example.INote"
+    ...     type="zope.generic.face.IKeyfaceType"
+    ...     />
+    ... ''')
+
+    >>> registerDirective('''
+    ... <generic:interface
+    ...     interface="example.IArticle"
+    ...     type="zope.generic.face.IKeyfaceType"
+    ...     />
+    ... ''')
+
 Step 2: Building Blocks
 -----------------------
 
@@ -67,7 +87,6 @@
     >>> from zope.generic.informationprovider.api import queryInformation
     >>> from zope.generic.informationprovider.api import provideInformation
     >>> from zope.generic.informationprovider.api import deleteInformation
-    >>> from zope.generic.content.api import queryTypeConfiguration
 
 Let's implement the initializer of the article. Initializers are called from
 ``__init__``. Initializers are used to add additional logic at the 
@@ -80,18 +99,18 @@
     ...     - raises an exception if no configurationis defined
     ...     """
     ...     # looks up the allready configured data on the object
-    ...     article_config = queryInformation(context, 
-    ...         IArticleInitializationConfiguration)
+    ...     article_config = queryInformation(IArticleInitializationConfiguration, 
+    ...                                        context)
     ...     if article_config is None:
-    ...         text_config = queryTypeConfiguration(context, ITextConfig)
-    ...         note_config = queryTypeConfiguration(context, INoteConfig)
+    ...         text_config = queryInformation(context.keyface, ITextConfig)
+    ...         note_config = queryInformation(context.keyface, INoteConfig)
     ...         text, note = text_config.text, note_config.text
     ...     else:
     ...         text, note = article_config.text, article_config.note
     ...
-    ...     provideInformation(context, ITextConfig, {'body': text})
-    ...     provideInformation(context, INoteConfig, {'body': note})
-    ...     deleteInformation(context, IArticleInitializationConfiguration)
+    ...     provideInformation(ITextConfig, {'body': text}, context)
+    ...     provideInformation(INoteConfig, {'body': note}, context)
+    ...     deleteInformation(IArticleInitializationConfiguration, context)
  
     >>> from zope.generic.configuration.api import ConfigurationData
     
@@ -176,10 +195,10 @@
     >>> IArticle.providedBy(article)
     True
 
-    >>> queryInformation(article, ITextConfig).body
+    >>> queryInformation(ITextConfig, article).body
     u'First version of article.'
     
-    >>> queryInformation(article, IArticleInitializationConfiguration).text
+    >>> queryInformation(IArticleInitializationConfiguration, article).text
     Traceback (most recent call last):
     ...
     AttributeError: 'NoneType' object has no attribute 'text'

Modified: zope.generic/trunk/src/zope/generic/content/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/content/README.txt	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/content/README.txt	2006-05-03 13:45:43 UTC (rev 67881)
@@ -79,19 +79,21 @@
     >>> from zope.component import queryUtility
     >>> from zope.generic.face.api import toDottedName
 
-    >>> info = queryUtility(IUndefinedContext, toDottedName(IFooMarker))
+    >>> provider = queryUtility(IUndefinedContext, toDottedName(IFooMarker))
 
-    >>> info.keyface == IFooMarker
+    >>> provider.keyface == IFooMarker
     True
 
 There is convenience function for the lookup of corresponding type information.
 You can lookup the type information by the type marker interface or an object
 providing ITypedContent by implementation or adaption:
 
-	>>> api.queryTypeInformation(IFooMarker) == info
+    >>> from zope.generic.informationprovider.api import getInformationProvider
+
+	>>> getInformationProvider(IFooMarker) == provider
 	True
 
-    >>> api.queryTypeInformation(foo) == info
+    >>> getInformationProvider(foo.keyface) == provider
     True
 
 
@@ -200,39 +202,44 @@
 You can retrieve type information by a typed instance or the marker type itself
 using the following convenience function:
 
-	>>> api.queryTypeConfiguration(IBarMarker, IAnyConfiguration).any
+    >>> from zope.generic.informationprovider.api import queryInformation
+
+	>>> queryInformation(IAnyConfiguration, IBarMarker).any
 	u'Guguseli from Type!'
 
-	>>> api.queryTypeConfiguration(bar, IAnyConfiguration).any
+	>>> queryInformation(IAnyConfiguration, bar.keyface).any
 	u'Guguseli from Type!'
 
-	>>> api.queryTypeConfiguration(IBarMarker, IOtherConfiguration) is None
+	>>> queryInformation(IOtherConfiguration, IBarMarker) is None
 	True
 
 This configuration is type specific. You cannot lookup any object- or 
 instance-specific configuration, but you can use a function that `acquires`
 different configurations:
 
-	>>> api.queryObjectConfiguration(bar, IAnyConfiguration) is None
+    >>> from zope.generic.informationprovider.api import acquireInformation
+    
+
+	>>> queryInformation(IAnyConfiguration, bar) is None
 	True
 
-	>>> api.queryObjectConfiguration(bar, IOtherConfiguration).other
+	>>> queryInformation(IOtherConfiguration, bar).other
 	u'Specific initialization data.'
 
-	>>> api.acquireObjectConfiguration(bar, IAnyConfiguration).any
+	>>> acquireInformation(IAnyConfiguration, bar).any
 	u'Guguseli from Type!'
 
-	>>> api.acquireObjectConfiguration(bar, IOtherConfiguration).other
+	>>> acquireInformation(IOtherConfiguration, bar).other
 	u'Specific initialization data.'
 
     >>> from zope.generic.configuration.api import IConfigurations
 	>>> objectdata = ConfigurationData(IAnyConfiguration, {'any': u'Guguseli from Object!'})
 	>>> IConfigurations(bar)[IAnyConfiguration] = objectdata
 	
-	>>> api.queryObjectConfiguration(bar, IAnyConfiguration).any
+	>>> queryInformation(IAnyConfiguration, bar).any
 	u'Guguseli from Object!'
 
-	>>> api.acquireObjectConfiguration(bar, IAnyConfiguration).any
+	>>> acquireInformation(IAnyConfiguration, bar).any
 	u'Guguseli from Object!'
 
 The configurationAdapter subdirective provides an adapter too:
@@ -249,7 +256,7 @@
 the type configuration, but only the object's configuration can be set:
 
     >>> from zope.generic.informationprovider.api import deleteInformation
-    >>> deleteInformation(bar, IAnyConfiguration)
+    >>> deleteInformation(IAnyConfiguration, bar)
 
     >>> IAnyConfiguration(bar).any
     u'Guguseli from Type!'

Modified: zope.generic/trunk/src/zope/generic/content/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/content/api.py	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/content/api.py	2006-05-03 13:45:43 UTC (rev 67881)
@@ -26,8 +26,3 @@
 from zope.generic.content.base import Folder
 from zope.generic.content.base import OrderedContainer
 from zope.generic.content.base import OrderedFolder
-
-from zope.generic.content.helper import acquireObjectConfiguration
-from zope.generic.content.helper import queryObjectConfiguration
-from zope.generic.content.helper import queryTypeConfiguration
-from zope.generic.content.helper import queryTypeInformation

Modified: zope.generic/trunk/src/zope/generic/content/base.py
===================================================================
--- zope.generic/trunk/src/zope/generic/content/base.py	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/content/base.py	2006-05-03 13:45:43 UTC (rev 67881)
@@ -23,12 +23,12 @@
 from zope.app import folder
 from zope.app.component.interfaces import IPossibleSite
 from zope.app.component.interfaces import ISite
+from zope.app.component.interfaces import NewLocalSite 
 from zope.app.container import btree
 from zope.app.container import contained
 from zope.app.container import ordered
 from zope.component.interfaces import ComponentLookupError
 from zope.component.interfaces import IComponentLookup
-from zope.app.component.interfaces import NewLocalSite 
 from zope.event import notify
 from zope.interface import directlyProvidedBy
 from zope.interface import directlyProvides

Deleted: zope.generic/trunk/src/zope/generic/content/helper.py
===================================================================
--- zope.generic/trunk/src/zope/generic/content/helper.py	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/content/helper.py	2006-05-03 13:45:43 UTC (rev 67881)
@@ -1,75 +0,0 @@
-##############################################################################
-#
-# 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.face.api import getKeyface
-from zope.generic.informationprovider.api import getInformationProvider
-from zope.generic.informationprovider.api import queryInformation
-
-from zope.generic.face import IUndefinedContext
-
-
-
-
-def getTypeInformation(object, conface=IUndefinedContext):
-    return getInformationProvider(getKeyface(object), conface)
-
-
-
-def queryTypeInformation(object, default=None):
-    """Lookup an type information of any object."""
-
-    try:
-        return getTypeInformation(object)
-
-    except:
-        return default
-
-
-
-def queryObjectConfiguration(object, configuration, default=None):   
-    return queryInformation(object, configuration, default)
-
-
-
-def queryTypeConfiguration(object, configuration, default=None):
-    info = queryTypeInformation(object)
-    return queryInformation(info, configuration, default)
-
-
-
-def acquireTypeConfiguration(object, configuration, default=None):
-    try:
-        keyface = getKeyface(object, default)
-
-    except:
-        return default
-
-
-
-def acquireObjectConfiguration(object, configuration, default=None):
-    # first try to evaluate object configuration data
-    data = queryObjectConfiguration(object, configuration, default)
-
-    if data is not default:
-        return data
-    
-    # return type configuration data
-    else:
-        return queryTypeConfiguration(object, configuration, default)

Modified: zope.generic/trunk/src/zope/generic/content/interfaces.py
===================================================================
--- zope.generic/trunk/src/zope/generic/content/interfaces.py	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/content/interfaces.py	2006-05-03 13:45:43 UTC (rev 67881)
@@ -18,15 +18,13 @@
 
 __docformat__ = 'restructuredtext'
 
-from zope.annotation.interfaces import IAttributeAnnotatable
-
-from zope.generic.configuration.api import IAttributeConfigurable
 from zope.generic.face import IFace
 from zope.generic.face import IProvidesAttributeFaced
+from zope.generic.informationprovider import IAttributeInformable
 
 
 
-class ITypedContent(IFace, IAttributeConfigurable, IAttributeAnnotatable):
+class ITypedContent(IFace, IAttributeInformable):
     """Content that provides the declared key interface."""
 
 

Modified: zope.generic/trunk/src/zope/generic/factory/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/factory/README.txt	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/factory/README.txt	2006-05-03 13:45:43 UTC (rev 67881)
@@ -28,11 +28,11 @@
 Then we have to implement an example class with dedicated initalization
 parameters:
 
-    >>> from zope.generic.configuration import IAttributeConfigurable
+    >>> from zope.generic.informationprovider import IAttributeInformable
     >>> from zope.generic.face import IAttributeFaced
 
     >>> class Example(object):
-    ...    interface.implements(IAttributeFaced, IAttributeConfigurable)
+    ...    interface.implements(IAttributeFaced, IAttributeInformable)
     ...    def __init__(self, a, b, c):
     ...        print '__init__:', 'a=',a ,', b=', b, ', c=', c
 
@@ -149,7 +149,8 @@
 configuration:
 
     >>> from zope.generic.informationprovider.api import getInformation
-    >>> info = getInformation(ex, IMyParameter)
+
+    >>> info = getInformation(IMyParameter, ex)
     >>> info.a, info.b, info.c
     (u'a bla', None, u'c default')
 

Modified: zope.generic/trunk/src/zope/generic/factory/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/factory/api.py	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/factory/api.py	2006-05-03 13:45:43 UTC (rev 67881)
@@ -39,7 +39,7 @@
 def createParameter(keyface):
     """Evaluate initializer parameters."""
     provider = getInformationProvider(keyface)
-    config = queryInformation(provider, IOperationConfiguration)
+    config = queryInformation(IOperationConfiguration, provider)
     if config:
         return config.input
     

Modified: zope.generic/trunk/src/zope/generic/factory/factory.py
===================================================================
--- zope.generic/trunk/src/zope/generic/factory/factory.py	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/factory/factory.py	2006-05-03 13:45:43 UTC (rev 67881)
@@ -193,10 +193,10 @@
     Such an configuration can be retrieved later on using the queryInformation
     function:
 
-        >>> from zope.generic.configuration import IAttributeConfigurable
+        >>> from zope.generic.informationprovider import IAttributeInformable
 
         >>> class SimpleConfigurable(object):
-        ...    interface.implements(IAttributeFaced, IAttributeConfigurable)
+        ...    interface.implements(IAttributeInformable, IAttributeFaced)
         ...    def __init__(self, a, b, c):
         ...        print '__init__:', 'a=',a ,', b=', b, ', c=', c
 
@@ -207,7 +207,7 @@
         
         >>> from zope.generic.informationprovider.api import queryInformation
         
-        >>> config = queryInformation(instance, IMyParameter)
+        >>> config = queryInformation(IMyParameter, instance)
         >>> config.a, config.b, config.c
         (u'a bla', None, u'c default')
 
@@ -262,7 +262,7 @@
             input = config.input
             if input:
                 configuration = parameterToConfiguration(input, *pos, **kws)
-                provideInformation(instance, input, configuration)
+                provideInformation(input, configuration, instance)
 
         # invoke initializer operations
         if mode > 1:
@@ -279,7 +279,7 @@
         if '_Factory__config' not in self.__dict__:
             try:
                 provider = getInformationProvider(self.keyface)
-                self.__dict__['_Factory__config'] = queryInformation(provider, IOperationConfiguration)
+                self.__dict__['_Factory__config'] = queryInformation(IOperationConfiguration, provider)
 
             except:
                 self.__dict__['_Factory__config'] = None

Modified: zope.generic/trunk/src/zope/generic/informationprovider/NEW_README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/NEW_README.txt	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/informationprovider/NEW_README.txt	2006-05-03 13:45:43 UTC (rev 67881)
@@ -98,13 +98,13 @@
 
 You can retrieve this configurations the following way:
 
-    >>> provider_for_nokeyface_at_suppliercontext = api.getInformationProvider(conface=ISupplierContext)
-    >>> data = api.getInformation(provider_for_nokeyface_at_suppliercontext, ILogConfiguration)
+    >>> provider_at_suppliercontext = api.getInformationProvider(conface=ISupplierContext)
+    >>> data = api.getInformation(ILogConfiguration, provider_at_suppliercontext)
     >>> data.header, data.timeFormat
     ('Supplier', '%y.%m.%d')
 
-    >>> provider_for_nokeyface_at_usercontext = api.getInformationProvider(conface=IUserContext)
-    >>> data = api.getInformation(provider_for_nokeyface_at_usercontext, ILogConfiguration)
+    >>> provider_at_usercontext = api.getInformationProvider(conface=IUserContext)
+    >>> data = api.getInformation(ILogConfiguration, provider_at_usercontext)
     >>> data.header, data.timeFormat
     ('General', '%d.%m.%y')
 
@@ -133,7 +133,7 @@
     ...         keyface = api.getKeyface(self.context)
     ...         conface = api.getConface(self)
     ...         provider = api.acquireInformationProvider(keyface, conface)
-    ...         logconfig = api.getInformation(provider, ILogConfiguration)
+    ...         logconfig = api.getInformation(ILogConfiguration, provider)
     ...         return '%s: %s, %s' % (logconfig.header, message, 
     ...                               time.strftime(logconfig.timeFormat))
 

Modified: zope.generic/trunk/src/zope/generic/informationprovider/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/README.txt	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/informationprovider/README.txt	2006-05-03 13:45:43 UTC (rev 67881)
@@ -101,7 +101,7 @@
 additional informations in a well-known manner. At the moment there are no 
 configurations:
 
-    >>> api.queryInformation(provider, 'example.my_annotation') is None
+    >>> api.queryInformation('example.my_annotation', provider) is None
     True
 
 Information providers are configurable. The configurations mechanism is used 
@@ -127,7 +127,7 @@
 
 At the moment there are no configurations:
 
-    >>> api.queryInformation(provider, IMyConfiguration) is None
+    >>> api.queryInformation(IMyConfiguration, provider) is None
     True
 
 We now can use an annotation and a configuration to extend our information
@@ -159,11 +159,11 @@
     ... ''')
 
     >>> provider = api.queryInformationProvider(IMyFoo, ISpecialContext)
-    >>> api.queryInformation(provider, 'example.my_annotation') is my_annotation
+    >>> api.queryInformation('example.my_annotation', provider) is my_annotation
     True
 
     >>> provider = api.queryInformationProvider(IMyFoo, ISpecialContext)
-    >>> api.queryInformation(provider, IMyConfiguration) is my_configuration
+    >>> api.queryInformation(IMyConfiguration, provider) is my_configuration
     True
 
 Further information provider exploration

Modified: zope.generic/trunk/src/zope/generic/informationprovider/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/api.py	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/informationprovider/api.py	2006-05-03 13:45:43 UTC (rev 67881)
@@ -43,23 +43,25 @@
 
 
 
-def queryInformationProvider(object=None, conface=IUndefinedContext, default=None):
-    """Evaluate the next information provider utility for an object or keyface."""
+def queryInformationProvider(keyface=IUndefinedKeyface, conface=IUndefinedContext, default=None):
+    """Query the information provider for an faced object or face-typed interface."""
     try:
-        return getInformationProvider(object, conface)
+        return getInformationProvider(keyface, conface)
 
     except:
         return default
 
 
 
-def acquireInformationProvider(object=None, conface=IUndefinedContext):
-    """Evaluate the next information provider utility for an object or keyface."""
-        
-    keyface = getKeyface(object)
+def acquireInformationProvider(keyface=IUndefinedKeyface, conface=IUndefinedContext):
+    """Acquire the information provider for an faced object or face-typed interface."""
+
     if conface is None:
-        conface = getConface(object)
+        conface = getConface(keyface)
 
+    if not IKeyfaceType.providedBy(keyface):
+        keyface = getKeyface(keyface)
+
     for more_general_conface in conface.__iro__:
         for more_general_keyface in keyface.__iro__:
             if IConfaceType.providedBy(more_general_conface) and IKeyfaceType.providedBy(more_general_keyface):
@@ -76,7 +78,7 @@
 
 
 def getInformationProvidersFor(face):
-    """Evaluate all information providers of a certain information aspect."""
+    """Evaluate available information providers of a certain information aspect."""
 
     if IConfaceType.providedBy(face):
         for name, provider in getUtilitiesFor(face):
@@ -92,8 +94,15 @@
 
 
 
-def getInformation(context, informationkey):
+def getInformation(informationkey, keyface=IUndefinedKeyface, conface=IUndefinedContext):
     """Evaluate an information by a keyface (string or key keyface)."""
+    
+    if IInformable.providedBy(keyface):
+        context = keyface
+
+    else:
+        context = getInformationProvider(keyface, conface)
+    
     if IConfigurationType.providedBy(informationkey):
         return informationkey(IConfigurations(context))
 
@@ -102,19 +111,38 @@
 
 
 
-def queryInformation(context, informationkey, default=None):
+def queryInformation(informationkey, keyface=IUndefinedKeyface, conface=IUndefinedContext, default=None):
     """Evaluate an information by a keyface (string or key interface)."""
     try:
-        return getInformation(context, informationkey)
+        return getInformation(informationkey, keyface, conface)
 
     except:
         return default
 
 
 
-def provideInformation(context, informationkey, information):
+def acquireInformation(informationkey, keyface=IUndefinedKeyface, conface=IUndefinedContext):
+    """Evaluate an information by a keyface (string or key keyface)."""
+    
+    if IInformable.providedBy(keyface):
+        try:
+            return getInformation(informationkey, keyface, conface)
+        except:
+            pass
+
+    return getInformation(informationkey, getKeyface(keyface), conface)
+
+
+
+def provideInformation(informationkey, information, keyface=IUndefinedKeyface, conface=IUndefinedContext):
     """Set an information to a context using a keyface (string or key interface)."""
 
+    if IInformable.providedBy(keyface):
+        context = keyface
+
+    else:
+        context = getInformationProvider(keyface, conface)
+
     if IConfigurationType.providedBy(informationkey):
         if type(information) is dict:
             information = ConfigurationData(informationkey, information)
@@ -126,11 +154,18 @@
 
 
 
-def deleteInformation(context, informationkey):
+def deleteInformation(informationkey, keyface, conface=IUndefinedContext):
     """Delete an information of a context using a keyface (string or key interface)."""
 
+    if IInformable.providedBy(keyface):
+        context = keyface
+
+    else:
+        context = getInformationProvider(keyface, conface)
+
     if IConfigurationType.providedBy(informationkey):
         del IConfigurations(context)[informationkey]
     
     else:
         del IAnnotations(context)[informationkey]
+

Modified: zope.generic/trunk/src/zope/generic/informationprovider/base.py
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/base.py	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/informationprovider/base.py	2006-05-03 13:45:43 UTC (rev 67881)
@@ -20,6 +20,7 @@
 
 from persistent import Persistent
 from zope.annotation import IAnnotations
+from zope.annotation import IAttributeAnnotatable
 from zope.annotation.attribute import AttributeAnnotations
 from zope.app.container.contained import Contained
 from zope.app.i18n import ZopeMessageFactory as _
@@ -28,6 +29,7 @@
 from zope.schema.fieldproperty import FieldProperty
 
 from zope.generic.configuration import IConfigurations
+from zope.generic.configuration import IAttributeConfigurable
 from zope.generic.configuration.api import AttributeConfigurations
 from zope.generic.directlyprovides.api import provides
 from zope.generic.directlyprovides.api import updateDirectlyProvided
@@ -89,7 +91,7 @@
 
     """
 
-    implements(IInformationProvider)
+    implements(IInformationProvider, IAttributeConfigurable, IAttributeAnnotatable)
 
     def __init__(self, __conface__=None, __keyface__=None):
         if __keyface__:

Modified: zope.generic/trunk/src/zope/generic/informationprovider/configure.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/configure.zcml	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/informationprovider/configure.zcml	2006-05-03 13:45:43 UTC (rev 67881)
@@ -15,12 +15,6 @@
   <!-- information providers. -->
 
   <class class="zope.generic.informationprovider.api.GlobalInformationProvider">
-    <implements
-        interface="zope.generic.configuration.IAttributeConfigurable"
-        />
-    <implements
-        interface="zope.annotation.IAttributeAnnotatable"
-        />
     <require
         permission="zope.Public"
         interface="zope.generic.face.IFace"
@@ -28,12 +22,6 @@
   </class>
 
   <class class="zope.generic.informationprovider.api.LocalInformationProvider">
-    <implements
-        interface="zope.generic.configuration.IAttributeConfigurable"
-        />
-    <implements
-        interface="zope.annotation.IAttributeAnnotatable"
-        />
     <require
         permission="zope.Public"
         interface="zope.generic.face.IFace"

Modified: zope.generic/trunk/src/zope/generic/informationprovider/interfaces.py
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/interfaces.py	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/informationprovider/interfaces.py	2006-05-03 13:45:43 UTC (rev 67881)
@@ -18,31 +18,34 @@
 
 __docformat__ = 'restructuredtext'
 
+from zope.annotation.interfaces import IAnnotatable
+from zope.annotation.interfaces import IAttributeAnnotatable
 from zope.app.i18n import ZopeMessageFactory as _
 from zope.interface import Interface
 from zope.schema import Text
 from zope.schema import TextLine
 
+from zope.generic.configuration import IAttributeConfigurable
+from zope.generic.configuration import IConfigurable
 from zope.generic.face import IProvidesAttributeFaced
 
 
+class IInformable(IConfigurable, IAnnotatable):
+    """Provide generic mechanism to access or attach information to the object."""
 
-class IInformationProvider(IProvidesAttributeFaced):
+
+
+class IAttributeInformable(IInformable, IAttributeConfigurable, IAttributeAnnotatable):
+    """Provide generic mechanism to access or attach information to the object."""
+
+
+
+class IInformationProvider(IInformable, IProvidesAttributeFaced):
     """Provide information to a dedicated context and key interface pair.
 
     Information provider will be registered as utility providing the context 
     interface and named by the dotted name of the key interface.
 
-    Information providers can be extended by generic information mechanism
-    such as zope.annotation.IAnnotations simply by adding a specific marker to
-    the information provider implementation. The marker should invoke the 
-    specific information mechanism:
-    
-        classProvides(api.InformationProvider, IAttributeAnnotatable)
-
-        <class class="zope.generic.api.InformationProvider" >
-            <implements="zope.annotation.IAttributeAnnotatable" />
-        </class>
     """
 
 

Modified: zope.generic/trunk/src/zope/generic/informationprovider/metaconfigure.py
===================================================================
--- zope.generic/trunk/src/zope/generic/informationprovider/metaconfigure.py	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/informationprovider/metaconfigure.py	2006-05-03 13:45:43 UTC (rev 67881)
@@ -41,13 +41,14 @@
 
 
 
-def getInformationProvider(object=None, conface=IUndefinedContext):
-    """Evaluate the next information provider utility for an object or keyface."""
-
-    keyface = getKeyface(object)
+def getInformationProvider(keyface=IUndefinedKeyface, conface=IUndefinedContext):
+    """Get the information provider for an faced object or face-typed interface."""
     if conface is None:
-        conface = getConface(object)
+        conface = getConface(keyface)
 
+    if not IKeyfaceType.providedBy(keyface):
+        keyface = getKeyface(keyface)
+
     try:
         provider = getUtility(conface, toDottedName(keyface))
         # return only provider that is or extends a certain context.

Modified: zope.generic/trunk/src/zope/generic/operation/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/operation/README.txt	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/operation/README.txt	2006-05-03 13:45:43 UTC (rev 67881)
@@ -176,16 +176,16 @@
     >>> def inputToConfigurations(context, *pos, **kws):
     ...    print 'Private operation: inputToConfigurations'
     ...    input = parameterToConfiguration(IComplexConfig, *pos, **kws)
-    ...    provideInformation(context, IAnyInput, {'a': input.any})
-    ...    provideInformation(context, IPAUConfig, {'a': input.pau})
+    ...    provideInformation(IAnyInput, {'a': input.any}, context)
+    ...    provideInformation(IPAUConfig, {'a': input.pau}, context)
 
     >>> def pauInitializer(context, *pos, **kws):
     ...    print 'Private operation: pauInitializer'
-    ...    return getInformation(context, IPAUConfig)
+    ...    return getInformation(IPAUConfig, context)
 
     >>> def anyOperationInitializer(context, *pos, **kws):
     ...    print 'Private operation: anyOperationInitializer'
-    ...    return getInformation(context, IAnyInput)
+    ...    return getInformation(IAnyInput, context)
 
     >>> def void(context, *pos, **kws):
     ...    print 'Private operation: void'
@@ -206,10 +206,11 @@
 
 Now we will check the behavior of the example on a dedicated context:
 
-    >>> from zope.generic.configuration import IAttributeConfigurable
+    >>> from zope.generic.informationprovider import IAttributeInformable
+    >>> from zope.generic.face.api import Face
 
-    >>> class DummyContext(object):
-    ...     interface.implements(IAttributeConfigurable)
+    >>> class DummyContext(Face):
+    ...     interface.implements(IAttributeInformable)
     ...     def __repr__(self):
     ...         return 'DummyContext'
 

Modified: zope.generic/trunk/src/zope/generic/operation/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/operation/api.py	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/operation/api.py	2006-05-03 13:45:43 UTC (rev 67881)
@@ -29,7 +29,7 @@
 def getOperationConfiguration(object, conface=IUndefinedContext):
     """Evaluate an operation configuration."""
     
-    return getInformation(getInformationProvider(object, conface), IOperationConfiguration)
+    return getInformation(IOperationConfiguration, getInformationProvider(object, conface))
 
 
 

Modified: zope.generic/trunk/src/zope/generic/operation/metaconfigure.py
===================================================================
--- zope.generic/trunk/src/zope/generic/operation/metaconfigure.py	2006-05-03 12:48:26 UTC (rev 67880)
+++ zope.generic/trunk/src/zope/generic/operation/metaconfigure.py	2006-05-03 13:45:43 UTC (rev 67881)
@@ -71,7 +71,7 @@
         if info is None:
             ConfigurationError('Operation %s does not exist.' % handler.__name__)
 
-        config = queryInformation(info, IOperationConfiguration)
+        config = queryInformation(IOperationConfiguration, info)
 
         if config is None:
             ConfigurationError('OperationConfiguration for Operation %s does not exist.' % handler.__name__)



More information about the Checkins mailing list