[Checkins] SVN: zope.generic/trunk/src/zope/generic/ factor keyface
stuff out of .component into .keyface
Dominik Huber
dominik.huber at perse.ch
Thu Apr 20 04:32:33 EDT 2006
Log message for revision 67168:
factor keyface stuff out of .component into .keyface
Changed:
U zope.generic/trunk/src/zope/generic/component/NEW_README.txt
U zope.generic/trunk/src/zope/generic/component/README.txt
D zope.generic/trunk/src/zope/generic/component/README_2.txt
U zope.generic/trunk/src/zope/generic/component/adapter.py
U zope.generic/trunk/src/zope/generic/component/api.py
U zope.generic/trunk/src/zope/generic/component/base.py
U zope.generic/trunk/src/zope/generic/component/interfaces.py
U zope.generic/trunk/src/zope/generic/component/testing.py
U zope.generic/trunk/src/zope/generic/component/tests.py
U zope.generic/trunk/src/zope/generic/component/zope.generic.component-configure.zcml
A zope.generic/trunk/src/zope/generic/keyface/
A zope.generic/trunk/src/zope/generic/keyface/DEPENDENCIES.cfg
A zope.generic/trunk/src/zope/generic/keyface/README.txt
A zope.generic/trunk/src/zope/generic/keyface/SETUP.cfg
A zope.generic/trunk/src/zope/generic/keyface/__init__.py
A zope.generic/trunk/src/zope/generic/keyface/adapter.py
A zope.generic/trunk/src/zope/generic/keyface/api.py
A zope.generic/trunk/src/zope/generic/keyface/base.py
A zope.generic/trunk/src/zope/generic/keyface/configure.zcml
A zope.generic/trunk/src/zope/generic/keyface/interfaces.py
A zope.generic/trunk/src/zope/generic/keyface/testing.py
A zope.generic/trunk/src/zope/generic/keyface/tests.py
A zope.generic/trunk/src/zope/generic/keyface/zope.generic.keyface-configure.zcml
U zope.generic/trunk/src/zope/generic/operation/base.py
U zope.generic/trunk/src/zope/generic/operation/interfaces.py
U zope.generic/trunk/src/zope/generic/operation/testing.py
U zope.generic/trunk/src/zope/generic/type/adapter.py
U zope.generic/trunk/src/zope/generic/type/interfaces.py
U zope.generic/trunk/src/zope/generic/type/testing.py
-=-
Modified: zope.generic/trunk/src/zope/generic/component/NEW_README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/component/NEW_README.txt 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/component/NEW_README.txt 2006-04-20 08:32:31 UTC (rev 67168)
@@ -92,7 +92,7 @@
>>> from zope.interface import implements
>>> from zope.component import adapts
- >>> from zope.generic.component import IKeyface
+ >>> from zope.generic.keyface import IKeyface
>>> class Logger(object):
... """Generic logger adapter."""
Modified: zope.generic/trunk/src/zope/generic/component/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/component/README.txt 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/component/README.txt 2006-04-20 08:32:31 UTC (rev 67168)
@@ -2,17 +2,10 @@
Generic Component
=================
-The behavior of components within the ca-framework depends heavily on their
-provided interfaces. A component, except most of the adapters and utilities,
-regularly provides more than one interface. The adaption and subscriber
-mechanism of the ca-framework invokes the provided interfaces by a
-lookup-algorithmus similar to the method resolution order by class inherintance.
+The key interface (see zope.generic.keyface) can be used to lookup corresponding
+information providers. This package offers a way to implement information
+providers generically.
-Most of the time this behavior satisfies our requirements. Additionally this
-package offers a mechanism to declare a single key interface (IKeyface).
-This key interface can be used to lookup corresponding information providers
-more explicitly.
-
You can register different information providers to the same key interface. An
information provider encapsulates a certain information aspect of the key
interface. The relation between information providers of a key interface to
@@ -71,7 +64,7 @@
>>> len(listing) is 1
True
>>> [(key.__name__, value) for key, value in listing]
- [('IFooMarker', {})]
+ [('IFooMarker', <zope.generic.component.base.InformationProvider ...>)]
A single information provider can be retrieved by the get- or
queryInformationProvider function:
Deleted: zope.generic/trunk/src/zope/generic/component/README_2.txt
===================================================================
Modified: zope.generic/trunk/src/zope/generic/component/adapter.py
===================================================================
--- zope.generic/trunk/src/zope/generic/component/adapter.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/component/adapter.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -28,11 +28,12 @@
from zope.event import notify
from zope.interface import implements
+from zope.generic.keyface import IAttributeKeyfaced
+from zope.generic.keyface import IKeyface
+
from zope.generic.component import IAttributeConfigurable
from zope.generic.component import IConfigurationType
from zope.generic.component import IConfigurations
-from zope.generic.component import IKeyface
-from zope.generic.component import IAttributeKeyface
from zope.generic.component.event import Configuration
from zope.generic.component.event import ObjectConfiguredEvent
from zope.generic.component.helper import configuratonToDict
@@ -41,16 +42,16 @@
class Keyface(object):
- """Adapts IAttributeKeyface to IKeyface.
+ """Adapts IAttributeKeyfaced to IKeyface.
- You can adapt IKeyface if you provide IAttributeKeyface:
+ You can adapt IKeyface if you provide IAttributeKeyfaced:
- >>> class AnyAttributeKeyface(Keyface):
+ >>> class AnyAttributeKeyfaced(Keyface):
... def __init__(self, keyface):
... self.__keyface__ = keyface
>>> fake_keyface = object()
- >>> any = AnyAttributeKeyface(fake_keyface)
+ >>> any = AnyAttributeKeyfaced(fake_keyface)
>>> Keyface(any).keyface == fake_keyface
True
@@ -60,7 +61,7 @@
"""
implements(IKeyface)
- adapts(IAttributeKeyface)
+ adapts(IAttributeKeyfaced)
def __init__(self, context):
self.context = context
Modified: zope.generic/trunk/src/zope/generic/component/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/component/api.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/component/api.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -22,45 +22,20 @@
from zope.component import getUtilitiesFor
from zope.component import getUtility
from zope.interface.interfaces import IInterface
+from zope.generic.keyface.api import getKey
+from zope.generic.keyface.api import queryKey
from zope.generic.component import *
from zope.generic.component.base import ConfigurationData
from zope.generic.component.base import InformationProvider
-from zope.generic.component.base import Keyface
-from zope.generic.component.base import KeyfaceDescription
+from zope.generic.keyface.api import Keyface
+from zope.generic.keyface.api import KeyfaceDescription
from zope.generic.component.helper import configuratonToDict
from zope.generic.component.helper import toDottedName
from zope.generic.component.helper import toKeyface
-def getKey(object):
- """Evaluate the interface keyface from an object."""
-
- if IInterface.providedBy(object):
- keyface = object
-
- elif IKeyface.providedBy(object):
- keyface = object.keyface
-
- else:
- keyface = IKeyface(object).keyface
-
- return keyface
-
-
-
-def queryKey(object, default=None):
- """Evaluate the keyface keyface from an object."""
-
- try:
- return getKey(object)
-
- except:
- return default
-
-
-
def getInformationProvider(object, provider=IInformationProviderInformation):
"""Evaluate an information provider for an object."""
Modified: zope.generic/trunk/src/zope/generic/component/base.py
===================================================================
--- zope.generic/trunk/src/zope/generic/component/base.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/component/base.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -30,68 +30,19 @@
from zope.interface.interfaces import IMethod
from zope.schema.interfaces import IField
+from zope.generic.keyface import IAttributeKeyfaced
+from zope.generic.keyface import IKeyface
+from zope.generic.keyface.api import KeyfaceDescription
+from zope.generic.keyface.api import KeyfaceForAttributeKeyfaced
+
from zope.generic.component import IAttributeConfigurable
from zope.generic.component import IConfigurationData
from zope.generic.component import IConfigurations
from zope.generic.component import IInformationProvider
-from zope.generic.component import IKeyface
-from zope.generic.component import IAttributeKeyface
-from zope.generic.component import IKeyfaceDescription
-from zope.generic.component import adapter
from zope.generic.component.helper import toDottedName
-class Keyface(object):
- """Key interface mixin for key interface attribute implementations.
-
- You can mixin this class if you like to provide IKeyface for
- IAttributeKeyface implementations:
-
- >>> class AnyAttributeKeyface(Keyface):
- ... def __init__(self, keyface):
- ... self.__keyface__ = keyface
-
- >>> fake_keyface = object()
- >>> any = AnyAttributeKeyface(fake_keyface)
- >>> any.__keyface__ == fake_keyface
- True
-
- You get only the following method decorator for free :):
-
- >>> any.keyface == fake_keyface
- True
-
- """
-
- implements(IKeyface)
-
- @property
- def keyface(self):
- return self.__keyface__
-
-
-
-class KeyfaceDescription(Keyface):
- """Key interface description mixin."""
-
- implements(IKeyfaceDescription)
-
- def __init__(self, keyface, label=None, hint=None):
- self.__keyface__ = keyface
-
- if label is None:
- self.label = _(keyface.__name__)
- else:
- self.label = label
-
- if hint is None:
- self.hint = _(keyface.__doc__)
- else:
- self.hint = hint
-
-
-
_marker = object()
class ConfigurationData(Persistent):
@@ -166,7 +117,7 @@
"""
- implements(IAttributeKeyface, IConfigurationData)
+ implements(IAttributeKeyfaced, IConfigurationData)
def __init__(self, schema, data):
# preconditions
@@ -185,12 +136,12 @@
self.__dict__['__keyface__'] = schema
directlyProvides(self, schema)
- def __conform__(self, keyface):
- if keyface is IKeyface:
- return adapter.Keyface(self)
+ def __conform__(self, interface):
+ if interface is IKeyface:
+ return KeyfaceForAttributeKeyfaced(self)
def __getattr__(self, name):
- # assert IAttributeKeyface
+ # assert IAttributeKeyfaced
if name == '__keyface__':
return self.__dict__['__keyface__']
Modified: zope.generic/trunk/src/zope/generic/component/interfaces.py
===================================================================
--- zope.generic/trunk/src/zope/generic/component/interfaces.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/component/interfaces.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -26,70 +26,12 @@
from zope.interface import alsoProvides
from zope.interface import Attribute
from zope.interface.interfaces import IInterface
-from zope.schema import Bool
-from zope.schema import Dict
-from zope.schema import Object
-from zope.schema import Text
-from zope.schema import TextLine
-from zope.schema import Tuple
+from zope.generic.keyface import IKeyfaced
+from zope.generic.keyface import IKeyfaceDescription
-###############################################################################
-#
-# Base key interface related interfaces
-#
-###############################################################################
-class IKeyfaceProvider(Interface):
- """Assert that a key interface can be looked up.
- The key interface must be provided by adaption to IKeyface."""
-
-
-
-class IAttributeKeyface(IKeyfaceProvider):
- """Provide the key interface within the __keyface__ attribute."""
-
- __keyface__ = Object(
- title=_('Key interface'),
- description=_('Key interface that allows to lookup ' +
- 'key-interface-specific informations such as ' +
- 'configurations providers.'),
- required=True,
- readonly=True,
- schema=IInterface)
-
-
-
-class IKeyface(IKeyfaceProvider):
- """Declare a key interface as component-specific key.
-
- You can use this key to lookup component-specific informations.
- """
-
- keyface = Object(
- title=_('Key interface'),
- description=_('Key interface of the adapted context.'),
- required=True,
- readonly=True,
- schema=IInterface)
-
-
-
-class IKeyfaceDescription(IKeyface):
- """User description about the associated key interface."""
-
- label = TextLine(title=_('Label'),
- description=_('Label for associated key interface.'),
- required=True
- )
-
- hint = Text(title=_('Hint'),
- description=_('Hint explaning the properties of the associated key interface.'),
- required=True
- )
-
-
###############################################################################
#
# base configurations related interfaces
@@ -106,7 +48,7 @@
-class IConfigurationData(IKeyfaceProvider):
+class IConfigurationData(IKeyfaced):
"""Marker for configuration data implementations."""
Modified: zope.generic/trunk/src/zope/generic/component/testing.py
===================================================================
--- zope.generic/trunk/src/zope/generic/component/testing.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/component/testing.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -25,6 +25,7 @@
from zope.schema import TextLine
import zope.generic.component.testing
+import zope.generic.keyface.testing
import zope.generic.directlyprovides.testing
import zope.generic.testing.testing
@@ -91,6 +92,7 @@
# external setup
zope.generic.testing.testing.setUp(doctest)
zope.generic.directlyprovides.testing.setUp(doctest)
+ zope.generic.keyface.testing.setUp(doctest)
zope.generic.component.testing.setUp(doctest)
# internal setup
setUp(doctest)
@@ -99,6 +101,7 @@
super(PlacelessSetup, self).tearDown()
# external teardown
zope.generic.component.testing.tearDown(doctest)
+ zope.generic.keyface.testing.tearDown(doctest)
zope.generic.directlyprovides.testing.tearDown(doctest)
zope.generic.testing.testing.tearDown(doctest)
# internal teardown
Modified: zope.generic/trunk/src/zope/generic/component/tests.py
===================================================================
--- zope.generic/trunk/src/zope/generic/component/tests.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/component/tests.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -62,27 +62,10 @@
self.assertEqual(getattr(test_obj, 'fo'), fo_field.default)
-class KeyfaceAdapterTest(InterfaceBaseTest):
- @property
- def _test_interface(self):
- from zope.generic.component import IKeyface
- return IKeyface
-
- @property
- def _test_class(self):
- from zope.generic.component.adapter import Keyface
- return Keyface
-
- @property
- def _test_pos(self):
- return (testing.TestKeyfaceAttriute(),)
-
-
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ConfigurationDataTest),
- #TODO: Why does it fail? unittest.makeSuite(KeyfaceAdapterTest),
doctest.DocTestSuite('zope.generic.component.helper'),
doctest.DocTestSuite('zope.generic.component.base'),
doctest.DocTestSuite('zope.generic.component.event'),
Modified: zope.generic/trunk/src/zope/generic/component/zope.generic.component-configure.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/component/zope.generic.component-configure.zcml 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/component/zope.generic.component-configure.zcml 2006-04-20 08:32:31 UTC (rev 67168)
@@ -1,5 +1,5 @@
<configure xmlns="http://namespaces.zope.org/zope">
- <include package="zope.generic.directlyprovides" />
+ <include package="zope.generic.component" />
</configure>
Added: zope.generic/trunk/src/zope/generic/keyface/DEPENDENCIES.cfg
===================================================================
--- zope.generic/trunk/src/zope/generic/keyface/DEPENDENCIES.cfg 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/keyface/DEPENDENCIES.cfg 2006-04-20 08:32:31 UTC (rev 67168)
@@ -0,0 +1,16 @@
+BTrees
+persistent
+zope.app.annotation
+zope.app.component
+zope.app.event
+zope.app.location
+zope.app.testing
+zope.component
+zope.configuration
+zope.dottedname
+zope.event
+zope.generic.directlyprovides
+zope.generic.testing
+zope.interface
+zope.schema
+zope.testing
\ No newline at end of file
Property changes on: zope.generic/trunk/src/zope/generic/keyface/DEPENDENCIES.cfg
___________________________________________________________________
Name: svn:keywords
+ Id
Added: zope.generic/trunk/src/zope/generic/keyface/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/keyface/README.txt 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/keyface/README.txt 2006-04-20 08:32:31 UTC (rev 67168)
@@ -0,0 +1,69 @@
+===============
+Generic Keyface
+===============
+
+The behavior of components within the ca-framework depends heavily on their
+provided interfaces. A component, except most of the adapters and utilities,
+regularly provides more than one interface. The adaption and subscriber
+mechanism of the ca-framework invokes the provided interfaces by a
+lookup-algorithmus similar to the method resolution order by class inherintance.
+
+Most of the time this behavior satisfies our requirements. Additionally this
+package offers a mechanism to declare a single key interface (IKeyface).
+This key interface can be used to lookup corresponding information providers
+more explicitly.
+
+A component that like to use this mechanism should provide a mechanism to look
+up the key interface. This is regularly done providing IAttributeKeyfaced.
+
+First we use a key interface:
+
+ >>> class IFooMarker(interface.Interface):
+ ... pass
+
+Then we have to decorate a corresponding key-faced component:
+
+ >>> class FooKeyfaced(object):
+ ... interface.implements(api.IAttributeKeyfaced)
+ ... __keyface__ = IFooMarker
+
+There is a default adapter to IKeyface for key-faced objects:
+
+ >>> fookeyfaced = FooKeyfaced()
+
+ >>> adapted = api.IKeyface(fookeyfaced)
+ >>> adapted.keyface == IFooMarker
+ True
+
+Furthermore there is simple Keyface mixin for AttributeKeyfaced objects:
+
+ >>> class FooKeyface(FooKeyfaced, api.Keyface):
+ ... __keyface__ = IFooMarker
+
+ >>> fookeyface = FooKeyface()
+ >>> fookeyface.keyface == IFooMarker
+ True
+
+The api provides convenience functions to get the key interfaces of components:
+
+ >>> api.getKey(fookeyfaced) == IFooMarker
+ True
+
+ >>> api.getKey(fookeyface) == IFooMarker
+ True
+
+ >>> api.getKey(object())
+ Traceback (most recent call last):
+ ...
+ TypeError: ('Could not adapt', ...)
+
+ >>> api.queryKey(fookeyfaced) == IFooMarker
+ True
+
+ >>> api.queryKey(fookeyface) == IFooMarker
+ True
+
+ >>> api.queryKey(object()) == None
+ True
+
+
Property changes on: zope.generic/trunk/src/zope/generic/keyface/README.txt
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/keyface/SETUP.cfg
===================================================================
--- zope.generic/trunk/src/zope/generic/keyface/SETUP.cfg 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/keyface/SETUP.cfg 2006-04-20 08:32:31 UTC (rev 67168)
@@ -0,0 +1,3 @@
+<data-files zopeskel/etc/package-includes>
+ zope.generic.keyface-*.zcml
+</data-files>
\ No newline at end of file
Property changes on: zope.generic/trunk/src/zope/generic/keyface/SETUP.cfg
___________________________________________________________________
Name: svn:keywords
+ Id
Added: zope.generic/trunk/src/zope/generic/keyface/__init__.py
===================================================================
--- zope.generic/trunk/src/zope/generic/keyface/__init__.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/keyface/__init__.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -0,0 +1,19 @@
+##############################################################################
+#
+# 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$
+"""
+
+from zope.generic.keyface.interfaces import *
\ No newline at end of file
Property changes on: zope.generic/trunk/src/zope/generic/keyface/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/keyface/adapter.py
===================================================================
--- zope.generic/trunk/src/zope/generic/keyface/adapter.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/keyface/adapter.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -0,0 +1,57 @@
+##############################################################################
+#
+# 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.location import Location
+from zope.component import adapts
+from zope.interface import implements
+
+from zope.generic.keyface import IAttributeKeyfaced
+from zope.generic.keyface import IKeyface
+
+
+
+class KeyfaceForAttributeKeyfaced(Location):
+ """Adapts IAttributeKeyfaced to IKeyface.
+
+ You can adapt IKeyface if you provide IAttributeKeyfaced:
+
+ >>> class AnyAttributeKeyfaced(object):
+ ... def __init__(self, keyface):
+ ... self.__keyface__ = keyface
+
+ >>> fake_keyface = object()
+ >>> any = AnyAttributeKeyfaced(fake_keyface)
+
+ >>> KeyfaceForAttributeKeyfaced(any).keyface == fake_keyface
+ True
+ >>> IKeyface.providedBy(KeyfaceForAttributeKeyfaced(any))
+ True
+
+"""
+
+ implements(IKeyface)
+ adapts(IAttributeKeyfaced)
+
+ def __init__(self, context):
+ self.context = context
+
+ @property
+ def keyface(self):
+ return self.context.__keyface__
Property changes on: zope.generic/trunk/src/zope/generic/keyface/adapter.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/keyface/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/keyface/api.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/keyface/api.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -0,0 +1,51 @@
+##############################################################################
+#
+# 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.keyface import *
+from zope.generic.keyface.adapter import KeyfaceForAttributeKeyfaced
+from zope.generic.keyface.base import Keyface
+from zope.generic.keyface.base import KeyfaceDescription
+
+
+
+def getKey(object):
+ """Evaluate the interface keyface from an object."""
+
+ if IInterface.providedBy(object):
+ keyface = object
+
+ elif IKeyface.providedBy(object):
+ keyface = object.keyface
+
+ else:
+ keyface = IKeyface(object).keyface
+
+ return keyface
+
+
+
+def queryKey(object, default=None):
+ """Evaluate the keyface keyface from an object."""
+
+ try:
+ return getKey(object)
+
+ except:
+ return default
Property changes on: zope.generic/trunk/src/zope/generic/keyface/api.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/keyface/base.py
===================================================================
--- zope.generic/trunk/src/zope/generic/keyface/base.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/keyface/base.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -0,0 +1,76 @@
+##############################################################################
+#
+# 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.interface import implements
+
+from zope.generic.keyface import IAttributeKeyfaced
+from zope.generic.keyface import IKeyface
+from zope.generic.keyface import IKeyfaceDescription
+
+
+
+class Keyface(object):
+ """Key interface mixin for key interface attribute implementations.
+
+ You can mixin this class if you like to provide IKeyface for
+ IAttributeKeyfaced implementations:
+
+ >>> class AnyAttributeKeyfaced(Keyface):
+ ... def __init__(self, keyface):
+ ... self.__keyface__ = keyface
+
+ >>> fake_keyface = object()
+ >>> any = AnyAttributeKeyfaced(fake_keyface)
+ >>> any.__keyface__ == fake_keyface
+ True
+
+ You get only the following method decorator for free :):
+
+ >>> any.keyface == fake_keyface
+ True
+
+ """
+
+ implements(IKeyface)
+
+ @property
+ def keyface(self):
+ return self.__keyface__
+
+
+
+class KeyfaceDescription(Keyface):
+ """Key interface description mixin."""
+
+ implements(IKeyfaceDescription)
+
+ def __init__(self, keyface, label=None, hint=None):
+ self.__keyface__ = keyface
+
+ if label is None:
+ self.label = _(keyface.__name__)
+ else:
+ self.label = label
+
+ if hint is None:
+ self.hint = _(keyface.__doc__)
+ else:
+ self.hint = hint
Property changes on: zope.generic/trunk/src/zope/generic/keyface/base.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/keyface/configure.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/keyface/configure.zcml 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/keyface/configure.zcml 2006-04-20 08:32:31 UTC (rev 67168)
@@ -0,0 +1,20 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:generic="http://namespaces.zope.org/generic"
+ i18n_domain="zope">
+
+ <!-- attribute configurations -->
+ <class class=".adapter.KeyfaceForAttributeKeyfaced">
+ <require
+ permission="zope.Public"
+ interface=".IKeyface"
+ />
+ </class>
+
+ <adapter
+ factory=".adapter.KeyfaceForAttributeKeyfaced"
+ provides=".IKeyface"
+ trusted="True"
+ />
+
+</configure>
Property changes on: zope.generic/trunk/src/zope/generic/keyface/configure.zcml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/keyface/interfaces.py
===================================================================
--- zope.generic/trunk/src/zope/generic/keyface/interfaces.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/keyface/interfaces.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -0,0 +1,82 @@
+##############################################################################
+#
+# 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.interface import Interface
+from zope.interface.interfaces import IInterface
+from zope.schema import Object
+from zope.schema import Text
+from zope.schema import TextLine
+
+
+###############################################################################
+#
+# Base key interface related interfaces
+#
+###############################################################################
+
+class IKeyfaced(Interface):
+ """Assert that a key interface can be looked up.
+
+ The key interface must be provided by adaption to IKeyface."""
+
+
+
+class IAttributeKeyfaced(IKeyfaced):
+ """Provide the key interface within the __keyface__ attribute."""
+
+ __keyface__ = Object(
+ title=_('Key interface'),
+ description=_('Key interface that allows to lookup ' +
+ 'key-interface-specific informations such as ' +
+ 'configurations providers.'),
+ required=True,
+ readonly=True,
+ schema=IInterface)
+
+
+
+class IKeyface(IKeyfaced):
+ """Declare a key interface as component-specific key.
+
+ You can use this key to lookup component-specific informations.
+ """
+
+ keyface = Object(
+ title=_('Key interface'),
+ description=_('Key interface of the adapted context.'),
+ required=True,
+ readonly=True,
+ schema=IInterface)
+
+
+
+class IKeyfaceDescription(IKeyface):
+ """User description about the associated key interface."""
+
+ label = TextLine(title=_('Label'),
+ description=_('Label for associated key interface.'),
+ required=True
+ )
+
+ hint = Text(title=_('Hint'),
+ description=_('Hint explaning the properties of the associated key interface.'),
+ required=True
+ )
Property changes on: zope.generic/trunk/src/zope/generic/keyface/interfaces.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/keyface/testing.py
===================================================================
--- zope.generic/trunk/src/zope/generic/keyface/testing.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/keyface/testing.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -0,0 +1,84 @@
+##############################################################################
+#
+# 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'
+
+import zope.app.testing.placelesssetup
+from zope.component import provideAdapter
+from zope.configuration.xmlconfig import XMLConfig
+from zope.interface import Interface
+
+import zope.generic.keyface.testing
+import zope.generic.directlyprovides.testing
+import zope.generic.testing.testing
+
+################################################################################
+#
+# Public Test implementations
+#
+################################################################################
+
+class IFoo(Interface):
+ """Test marker"""
+
+
+class TestKeyfaceAttriute(object):
+ __keyface__ = IFoo
+
+
+
+################################################################################
+#
+# Placeless setup
+#
+################################################################################
+
+# specific tests
+def setUp(doctest=None):
+ # register default keyface adapter
+ import zope.generic.keyface.adapter
+ from zope.generic.keyface import IKeyface
+ provideAdapter(zope.generic.keyface.adapter.KeyfaceForAttributeKeyfaced ,
+ provides=IKeyface)
+
+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.keyface.testing.setUp(doctest)
+ # internal setup
+ setUp(doctest)
+
+ def tearDown(self, doctest=None):
+ super(PlacelessSetup, self).tearDown()
+ # external teardown
+ zope.generic.keyface.testing.tearDown(doctest)
+ zope.generic.directlyprovides.testing.tearDown(doctest)
+ zope.generic.testing.testing.tearDown(doctest)
+ # internal teardown
+ tearDown(doctest)
+
+placelesssetup = PlacelessSetup()
Property changes on: zope.generic/trunk/src/zope/generic/keyface/testing.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/keyface/tests.py
===================================================================
--- zope.generic/trunk/src/zope/generic/keyface/tests.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/keyface/tests.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -0,0 +1,74 @@
+##############################################################################
+#
+# 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 InterfaceBaseTest
+from zope.generic.testing.testing import registerDirective
+
+from zope.generic.keyface import api
+from zope.generic.keyface import testing
+
+
+###############################################################################
+#
+# Unit tests
+#
+###############################################################################
+
+
+class KeyfaceAdapterTest(InterfaceBaseTest):
+
+ _verify_class = False
+
+ @property
+ def _test_interface(self):
+ from zope.generic.keyface import IKeyface
+ return IKeyface
+
+ @property
+ def _test_class(self):
+ from zope.generic.keyface.adapter import KeyfaceForAttributeKeyfaced
+ return KeyfaceForAttributeKeyfaced
+
+ @property
+ def _test_pos(self):
+ return (testing.TestKeyfaceAttriute(),)
+
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(KeyfaceAdapterTest),
+ doctest.DocTestSuite('zope.generic.keyface.adapter'),
+ 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/keyface/tests.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.generic/trunk/src/zope/generic/keyface/zope.generic.keyface-configure.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/keyface/zope.generic.keyface-configure.zcml 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/keyface/zope.generic.keyface-configure.zcml 2006-04-20 08:32:31 UTC (rev 67168)
@@ -0,0 +1,5 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+ <include package="zope.generic.keyface" />
+
+</configure>
Property changes on: zope.generic/trunk/src/zope/generic/keyface/zope.generic.keyface-configure.zcml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: zope.generic/trunk/src/zope/generic/operation/base.py
===================================================================
--- zope.generic/trunk/src/zope/generic/operation/base.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/operation/base.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -21,7 +21,7 @@
from zope.interface import implements
from zope.schema.fieldproperty import FieldProperty
-from zope.generic.component import IAttributeKeyface
+from zope.generic.keyface import IAttributeKeyfaced
from zope.generic.component.api import Keyface
from zope.generic.operation import IOperation
@@ -34,7 +34,7 @@
implements(IOperation)
- keyface = FieldProperty(IAttributeKeyface['__keyface__'])
+ keyface = FieldProperty(IAttributeKeyfaced['__keyface__'])
def __init__(self, callable=None, keyface=None):
self.__callable = callable
Modified: zope.generic/trunk/src/zope/generic/operation/interfaces.py
===================================================================
--- zope.generic/trunk/src/zope/generic/operation/interfaces.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/operation/interfaces.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -26,10 +26,10 @@
from zope.schema import Object
from zope.schema import Tuple
-from zope.generic.component import IKeyface
from zope.generic.component import IConfigurationType
from zope.generic.component import IInformationProvider
from zope.generic.component import IInformationProviderType
+from zope.generic.keyface import IKeyface
from zope.generic.type import ITypeType
Modified: zope.generic/trunk/src/zope/generic/operation/testing.py
===================================================================
--- zope.generic/trunk/src/zope/generic/operation/testing.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/operation/testing.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -21,10 +21,9 @@
from zope.configuration.xmlconfig import XMLConfig
import zope.app.testing.placelesssetup
-import zope.generic.component.testing
-import zope.generic.component.testing
import zope.generic.directlyprovides.testing
import zope.generic.component.testing
+import zope.generic.keyface.testing
import zope.generic.operation
import zope.generic.testing.testing
@@ -66,20 +65,19 @@
# external setup
zope.generic.testing.testing.setUp(doctest)
zope.generic.directlyprovides.testing.setUp(doctest)
+ zope.generic.keyface.testing.setUp(doctest)
zope.generic.component.testing.setUp(doctest)
- zope.generic.component.testing.setUp(doctest)
- zope.generic.component.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.component.testing.tearDown(doctest)
- zope.generic.component.testing.tearDown(doctest)
+ zope.generic.keyface.testing.tearDown(doctest)
+ zope.generic.directlyprovides.testing.tearDown(doctest)
+ zope.generic.testing.testing.tearDown(doctest)
+
# internal teardown
tearDown(doctest)
Modified: zope.generic/trunk/src/zope/generic/type/adapter.py
===================================================================
--- zope.generic/trunk/src/zope/generic/type/adapter.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/type/adapter.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -23,11 +23,11 @@
from zope.interface import classImplements
from zope.interface import implements
-from zope.generic.component import IAttributeKeyface
from zope.generic.component import IConfigurations
from zope.generic.component import IConfigurationType
from zope.generic.component.api import provideInformation
from zope.generic.component.api import ConfigurationData
+from zope.generic.keyface import IAttributeKeyfaced
from zope.generic.type import IInitializer
from zope.generic.type import IInitializerConfiguration
Modified: zope.generic/trunk/src/zope/generic/type/interfaces.py
===================================================================
--- zope.generic/trunk/src/zope/generic/type/interfaces.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/type/interfaces.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -25,10 +25,10 @@
from zope.schema import Bool
from zope.schema import Object
-from zope.generic.component import IKeyface
from zope.generic.component import IConfigurationType
+from zope.generic.component import IInformationProvider
from zope.generic.directlyprovides import IProvides
-from zope.generic.component import IInformationProvider
+from zope.generic.keyface import IKeyface
__all__ = ['ITypeType', 'ITypeable', 'ITyped', 'IDirectlyTyped',
Modified: zope.generic/trunk/src/zope/generic/type/testing.py
===================================================================
--- zope.generic/trunk/src/zope/generic/type/testing.py 2006-04-19 18:20:08 UTC (rev 67167)
+++ zope.generic/trunk/src/zope/generic/type/testing.py 2006-04-20 08:32:31 UTC (rev 67168)
@@ -23,6 +23,7 @@
import zope.app.testing.placelesssetup
import zope.generic.directlyprovides.testing
import zope.generic.component.testing
+import zope.generic.keyface.testing
import zope.generic.testing.testing
################################################################################
@@ -60,6 +61,7 @@
# external setup
zope.generic.testing.testing.setUp(doctest)
zope.generic.directlyprovides.testing.setUp(doctest)
+ zope.generic.keyface.testing
zope.generic.component.testing.setUp(doctest)
# internal setup
setUp(doctest)
@@ -67,9 +69,10 @@
def tearDown(self, doctest=None):
super(PlacelessSetup, self).tearDown()
# external teardown
+ zope.generic.component.testing.tearDown(doctest)
+ zope.generic.keyface.testing.tearDown(doctest)
+ zope.generic.directlyprovides.testing.tearDown(doctest)
zope.generic.testing.testing.tearDown(doctest)
- zope.generic.directlyprovides.testing.tearDown(doctest)
- zope.generic.component.testing.tearDown(doctest)
# internal teardown
tearDown(doctest)
More information about the Checkins
mailing list