[Checkins] SVN: zope.generic/trunk/src/zope/generic/ new readme:
errors!
Dominik Huber
dominik.huber at perse.ch
Sun Apr 9 10:52:38 EDT 2006
Log message for revision 66728:
new readme: errors!
Changed:
U zope.generic/trunk/src/zope/generic/configuration/testing.py
A zope.generic/trunk/src/zope/generic/information/NEW_README.txt
U zope.generic/trunk/src/zope/generic/information/api.py
U zope.generic/trunk/src/zope/generic/information/base.py
U zope.generic/trunk/src/zope/generic/information/helper.py
U zope.generic/trunk/src/zope/generic/information/interfaces.py
U zope.generic/trunk/src/zope/generic/information/meta.zcml
U zope.generic/trunk/src/zope/generic/information/metaconfigure.py
U zope.generic/trunk/src/zope/generic/information/metadirectives.py
U zope.generic/trunk/src/zope/generic/information/testing.py
U zope.generic/trunk/src/zope/generic/information/tests.py
U zope.generic/trunk/src/zope/generic/type/metaconfigure.py
-=-
Modified: zope.generic/trunk/src/zope/generic/configuration/testing.py
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/testing.py 2006-04-09 14:45:44 UTC (rev 66727)
+++ zope.generic/trunk/src/zope/generic/configuration/testing.py 2006-04-09 14:52:37 UTC (rev 66728)
@@ -18,6 +18,7 @@
__docformat__ = 'restructuredtext'
+from zope.app.testing import setup
from zope.component import provideAdapter
from zope.configuration.xmlconfig import XMLConfig
from zope.interface import Interface
@@ -85,3 +86,13 @@
placelesssetup = PlacelessSetup()
+
+
+
+class PlacelessSetup2(PlacelessSetup):
+
+ def setUp(self, doctesttest=None):
+ super(PlacelessSetup, self).setUp(doctesttest)
+ setup.setUpTestAsModule(doctesttest, 'zope.generic.example')
+
+placelesssetup2 = PlacelessSetup2()
Added: zope.generic/trunk/src/zope/generic/information/NEW_README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/information/NEW_README.txt 2006-04-09 14:45:44 UTC (rev 66727)
+++ zope.generic/trunk/src/zope/generic/information/NEW_README.txt 2006-04-09 14:52:37 UTC (rev 66728)
@@ -0,0 +1,123 @@
+===================================
+How to use the information package?
+===================================
+
+We are developing a logger framework that can be used by user-application
+domains and supplier-application domains.
+
+Therefore we provide two public information registries for the members of our
+orthagonal application domain such as suppliers. The log-supplier-information
+registry is holding supplier-specific informations. The log-user-information
+registry is holding user-specific informations.
+
+In order to implement such an information registry we have to declare an
+*key-like* interface extending the IInformation interface:
+
+ >>> from zope.generic.information import IInformation
+
+ >>> class ILogSupplierInformation(IInformation):
+ ... """Store log supplier information."""
+
+ >>> class ILogUserInformation(IInformation):
+ ... """Store log user information."""
+
+This specialized information interface has to be registered later by
+informationRegistry-directive.
+
+Such an extended information is logical container for configurations and
+annotations. In our framework example we have now to specify concrete
+configuration that are registered to the two registries by the corresponding
+member group.
+
+A supplier has to provide global log instance (dotted name) and an optional
+time formatter. We capture this configuration information within a configuration
+that can be attached to a dedicated supplier information.
+
+ >>> from zope.interface import Interface
+ >>> from zope.configuration.fields import GlobalObject
+ >>> from zope.schema import BytesLine
+
+ >>> class ILogConfiguration(Interface):
+ ... """Define the log output."""
+ ... log = GlobalObject(title=u'Log')
+ ... timeFormat = BytesLine(title=u'Time Format', required=False, default='%d.%m.%y')
+
+This configuration should be registered by using the configuration directive:
+
+ >>> registerDirective('''
+ ... <generic:configuration
+ ... interface="zope.generic.example.ILogConfiguration"
+ ... />
+ ... ''')
+
+A user has to provide logger configuration. This configuration defines the
+selected logger and a user-specific source tag:
+
+ >>> from zope.configuration.fields import GlobalInterface
+
+ >>> class ILoggerConfiguration(Interface):
+ ... """Define the log output."""
+ ... logger = GlobalInterface(title=u'Logger')
+ ... sourceTag = BytesLine(title=u'Source Tag', required=False, default=' ')
+
+ >>> registerDirective('''
+ ... <generic:configuration
+ ... interface="zope.generic.example.ILoggerConfiguration"
+ ... />
+ ... ''')
+
+TODO: Should be a dependency between informationRegistry and its configuration?
+
+ >>> registerDirective('''
+ ... <generic:informationRegistry
+ ... interface='zope.generic.example.ILogSupplierInformation'
+ ... />
+ ... ''')
+
+ >>> registerDirective('''
+ ... <generic:informationRegistry
+ ... interface='zope.generic.example.ILogUserInformation'
+ ... />
+ ... ''')
+
+The third part of our framework is the logger itself. The logger will be
+implmented as an adapter. We have to declare the logger interface:
+
+ >>> class ILogger(Interface):
+ ... """Log."""
+ ... def log(message):
+ ... """Log the message."""
+
+ >>> from zope.interface import implements
+ >>> from zope.component import adapts
+ >>> from zope.generic.information import IInformationDeclaration
+
+ >>> class Logger(object):
+ ... """Generic logger adapter."""
+ ... implements(ILogger)
+ ... adapts(IInformationDeclaration)
+ ... def __init__(self, context):
+ ... self.context = context
+ ... def log(self, message):
+ ... id = IInformationDeclaration(self.context())
+ ... info = queryInformation(id.interface, ILogUserInformation)
+
+
+
+After the registration we can retrieve the registries using the
+queryInformationRegistry function:
+
+ >>> from zope.generic.information.api import queryInformationRegistry
+
+ >>> supplier_registry = queryInformationRegistry(ILogSupplierInformation)
+ >>> supplier_registry.label
+ u'ILogSupplierInformation'
+ >>> supplier_registry.hint
+ u'Store log supplier information.'
+
+ >>> user_registry = queryInformationRegistry(ILogUserInformation)
+ >>> user_registry.label
+ u'ILogUserInformation'
+ >>> user_registry.hint
+ u'Store log user information.'
+
Property changes on: zope.generic/trunk/src/zope/generic/information/NEW_README.txt
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: zope.generic/trunk/src/zope/generic/information/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/information/api.py 2006-04-09 14:45:44 UTC (rev 66727)
+++ zope.generic/trunk/src/zope/generic/information/api.py 2006-04-09 14:52:37 UTC (rev 66728)
@@ -22,5 +22,6 @@
from zope.generic.information.base import Information
from zope.generic.information.helper import dottedName
from zope.generic.information.helper import queryInformation
+from zope.generic.information.helper import queryInformationRegistry
from zope.generic.information.helper import registeredInformations
from zope.generic.information.metaconfigure import provideInformation
Modified: zope.generic/trunk/src/zope/generic/information/base.py
===================================================================
--- zope.generic/trunk/src/zope/generic/information/base.py 2006-04-09 14:45:44 UTC (rev 66727)
+++ zope.generic/trunk/src/zope/generic/information/base.py 2006-04-09 14:52:37 UTC (rev 66728)
@@ -40,12 +40,12 @@
self.interface = interface
if label is None:
- self.label = _(dottedName(interface))
+ self.label = _(interface.__name__)
else:
self.label = label
if hint is None:
- self.hint = _('No hint available.')
+ self.hint = _(interface.__doc__)
else:
self.hint = hint
@@ -62,7 +62,7 @@
>>> from zope.interface import Interface
>>> class IFooMarker(Interface):
- ... pass
+ ... '''Foo is member of the example domain.'''
>>> info = Information(IFooMarker, ISpecialInformation)
@@ -77,10 +77,10 @@
>>> info.interface == IFooMarker
True
>>> info.label
- u'zope.generic.information.base.IFooMarker'
+ u'IFooMarker'
>>> info.hint
- u'No hint available.'
+ u'Foo is member of the example domain.'
Often you will provide a specific label and hint for the end-user:
Modified: zope.generic/trunk/src/zope/generic/information/helper.py
===================================================================
--- zope.generic/trunk/src/zope/generic/information/helper.py 2006-04-09 14:45:44 UTC (rev 66727)
+++ zope.generic/trunk/src/zope/generic/information/helper.py 2006-04-09 14:52:37 UTC (rev 66728)
@@ -23,8 +23,10 @@
from zope.generic.configuration.api import resolveClass
+from zope.generic.information import IInformationRegistryInformation
+
def dottedName(klass):
if klass is None:
return 'None'
@@ -45,6 +47,12 @@
return default
+
+def queryInformationRegistry(interface, default=None):
+ return queryInformation(interface, IInformationRegistryInformation, default)
+
+
+
def registeredInformations(registry, default=None):
for name, information in getUtilitiesFor(registry):
yield (resolveClass(name), information)
Modified: zope.generic/trunk/src/zope/generic/information/interfaces.py
===================================================================
--- zope.generic/trunk/src/zope/generic/information/interfaces.py 2006-04-09 14:45:44 UTC (rev 66727)
+++ zope.generic/trunk/src/zope/generic/information/interfaces.py 2006-04-09 14:52:37 UTC (rev 66728)
@@ -18,6 +18,7 @@
__docformat__ = 'restructuredtext'
+from zope.interface import alsoProvides
from zope.interface import Interface
from zope.interface.interfaces import IInterface
from zope.schema import Object
@@ -28,11 +29,6 @@
-__all__ = ['IInformationDeclaration', 'IInformationDescription', 'IInformation',
- 'IInformationRegistryInformation']
-
-
-
class IInformationDeclaration(Interface):
"""Declare an interface as information-specific-key."""
@@ -69,5 +65,14 @@
+class IInformationRegistryType(IInterface):
+ """Mark information interface as information type."""
+
+
+
class IInformationRegistryInformation(IInformation):
"""Provide information about registered information registries."""
+
+
+
+alsoProvides(IInformationRegistryInformation, IInformationRegistryType)
Modified: zope.generic/trunk/src/zope/generic/information/meta.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/information/meta.zcml 2006-04-09 14:45:44 UTC (rev 66727)
+++ zope.generic/trunk/src/zope/generic/information/meta.zcml 2006-04-09 14:52:37 UTC (rev 66728)
@@ -17,6 +17,19 @@
</meta:complexDirective>
+ <meta:complexDirective
+ name="informationRegistry"
+ schema=".metadirectives.IInformationRegistryDirective"
+ handler=".metaconfigure.InformationRegistryDirective"
+ >
+
+ <meta:subdirective
+ name="configuration"
+ schema=".metadirectives.IConfigurationSubdirective"
+ />
+
+ </meta:complexDirective>
+
</meta:directives>
</configure>
Modified: zope.generic/trunk/src/zope/generic/information/metaconfigure.py
===================================================================
--- zope.generic/trunk/src/zope/generic/information/metaconfigure.py 2006-04-09 14:45:44 UTC (rev 66727)
+++ zope.generic/trunk/src/zope/generic/information/metaconfigure.py 2006-04-09 14:52:37 UTC (rev 66728)
@@ -26,6 +26,8 @@
from zope.generic.configuration.api import IConfigurations
from zope.generic.information import IInformation
+from zope.generic.information import IInformationRegistryInformation
+from zope.generic.information import IInformationRegistryType
from zope.generic.information.base import Information
from zope.generic.information.helper import dottedName
from zope.generic.information.helper import queryInformation
@@ -87,7 +89,7 @@
class InformationDirective(object):
"""Provide a new information of a certain information registry."""
- _interface_type = None
+ _information_type = None
def __init__(self, _context, interface, registry, label=None, hint=None):
self._interface = interface
@@ -95,8 +97,8 @@
self._registry = registry
# assert type as soon as possible
- if self._interface_type is not None:
- alsoProvides(interface, self._interface_type)
+ if self._information_type is not None:
+ alsoProvides(interface, self._information_type)
_context.action(
discriminator = ('provideInformation', self._interface, self._registry),
@@ -131,3 +133,13 @@
callable = provideConfiguration,
args = (self._interface, self._registry, interface, data),
)
+
+
+
+class InformationRegistryDirective(InformationDirective):
+ """Provide a new information registry."""
+
+ _information_type = IInformationRegistryType
+
+ def __init__(self, _context, interface, label=None, hint=None):
+ super(InformationRegistryDirective, self).__init__(_context, interface, IInformationRegistryInformation, label, hint)
Modified: zope.generic/trunk/src/zope/generic/information/metadirectives.py
===================================================================
--- zope.generic/trunk/src/zope/generic/information/metadirectives.py 2006-04-09 14:45:44 UTC (rev 66727)
+++ zope.generic/trunk/src/zope/generic/information/metadirectives.py 2006-04-09 14:52:37 UTC (rev 66728)
@@ -53,7 +53,8 @@
class IInformationDirective(IBaseInformationDirective):
- """Directive for informations and information registries."""
+ """Directive to register an information to corresponding information
+ registry."""
registry = GlobalInterface(
title=_('Information Registry Key'),
@@ -65,6 +66,11 @@
+class IInformationRegistryDirective(IBaseInformationDirective):
+ """Directive to register an information registry."""
+
+
+
class IConfigurationSubdirective(Interface):
"""Declare a certain configuration of a type."""
Modified: zope.generic/trunk/src/zope/generic/information/testing.py
===================================================================
--- zope.generic/trunk/src/zope/generic/information/testing.py 2006-04-09 14:45:44 UTC (rev 66727)
+++ zope.generic/trunk/src/zope/generic/information/testing.py 2006-04-09 14:52:37 UTC (rev 66728)
@@ -22,8 +22,8 @@
import zope.generic.testing.testing
+from zope.app.testing import setup
-
################################################################################
#
# Public Test implementations
@@ -46,8 +46,7 @@
# register the directive of this package
import zope.generic.information
- XMLConfig('meta.zcml', zope.generic.information)()
-
+ XMLConfig('meta.zcml', zope.generic.information)()
def tearDown(self, doctesttest=None):
super(PlacelessSetup, self).tearDown(doctesttest)
Modified: zope.generic/trunk/src/zope/generic/information/tests.py
===================================================================
--- zope.generic/trunk/src/zope/generic/information/tests.py 2006-04-09 14:45:44 UTC (rev 66727)
+++ zope.generic/trunk/src/zope/generic/information/tests.py 2006-04-09 14:52:37 UTC (rev 66728)
@@ -23,6 +23,7 @@
from zope.testing import doctest
from zope.generic.configuration.testing import placelesssetup
+from zope.generic.configuration.testing import placelesssetup2
from zope.generic.testing.testing import registerDirective
from zope.generic.information import testing
@@ -41,6 +42,14 @@
'testing': testing},
optionflags=doctest.NORMALIZE_WHITESPACE+
doctest.ELLIPSIS),
+ doctest.DocFileSuite('NEW_README.txt',
+ setUp=placelesssetup2.setUp,
+ tearDown=placelesssetup2.tearDown,
+ globs={'component': component, 'interface': interface,
+ 'registerDirective': registerDirective,
+ 'testing': testing},
+ optionflags=doctest.NORMALIZE_WHITESPACE+
+ doctest.ELLIPSIS),
))
if __name__ == '__main__': unittest.main()
Modified: zope.generic/trunk/src/zope/generic/type/metaconfigure.py
===================================================================
--- zope.generic/trunk/src/zope/generic/type/metaconfigure.py 2006-04-09 14:45:44 UTC (rev 66727)
+++ zope.generic/trunk/src/zope/generic/type/metaconfigure.py 2006-04-09 14:52:37 UTC (rev 66728)
@@ -82,7 +82,7 @@
"""Provide a new logical type."""
# mark types with a type marker type
- _interface_type = ITypeType
+ _information_type = ITypeType
def __init__(self, _context, interface, class_, label=None, hint=None):
More information about the Checkins
mailing list