[Checkins]
SVN: grokcore.component/branches/jw-philipp-using-ndir-directives/
Merged from the trunk:
Philipp von Weitershausen
philikon at philikon.de
Sun May 4 08:41:57 EDT 2008
Log message for revision 86353:
Merged from the trunk:
Log message for revision 86233:
change determine_module_component so it takes an interface instead of
a list of base classes.
Also make Context implement IContext, so we can hook up things to that
instead of to the general base class.
Changed:
U grokcore.component/branches/jw-philipp-using-ndir-directives/CHANGES.txt
U grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/components.py
A grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/interfaces.py
U grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/meta.py
U grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/util.py
-=-
Modified: grokcore.component/branches/jw-philipp-using-ndir-directives/CHANGES.txt
===================================================================
--- grokcore.component/branches/jw-philipp-using-ndir-directives/CHANGES.txt 2008-05-04 12:41:50 UTC (rev 86352)
+++ grokcore.component/branches/jw-philipp-using-ndir-directives/CHANGES.txt 2008-05-04 12:41:55 UTC (rev 86353)
@@ -4,7 +4,11 @@
1.1 (unreleased)
----------------
-* ...
+* ``determine_module_component`` now looks for classes that implement
+ a certain interface (such as ``IContext``), instead of taking a list
+ of classes. If looking for ``IContext``, it still will find
+ ``Context`` subclasses, as these were also made to implement
+ ``IContext``.
1.0.1 (2008-05-02)
------------------
Modified: grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/components.py
===================================================================
--- grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/components.py 2008-05-04 12:41:50 UTC (rev 86352)
+++ grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/components.py 2008-05-04 12:41:55 UTC (rev 86353)
@@ -13,6 +13,10 @@
##############################################################################
"""Grok components"""
+from zope.interface import implements
+
+from grokcore.component.interfaces import IContext
+
class Adapter(object):
def __init__(self, context):
self.context = context
@@ -24,4 +28,4 @@
pass
class Context(object):
- pass
+ implements(IContext)
Copied: grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/interfaces.py (from rev 86233, grokcore.component/trunk/src/grokcore/component/interfaces.py)
===================================================================
--- grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/interfaces.py (rev 0)
+++ grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/interfaces.py 2008-05-04 12:41:55 UTC (rev 86353)
@@ -0,0 +1,18 @@
+from zope.interface import Interface
+
+class IContext(Interface):
+ """Marker interface for auto-association of context.
+
+ The ``grok.context()`` directive is used to associate adapters with the
+ class or interface they adapt. If there is only a single possible context
+ object to adapt to in a module, you can leave out this directive and
+ let the adapter associate automatically.
+
+ If you want to make an object to be a candidate for this automatic
+ association, you can subclass from ``grokcore.component.Context``.
+ This implements this ``IContext`` directive.
+
+ In some cases, you don't want to mix in a base class. You can instead
+ mark up your class with ``zope.interface.implements(IContext)`` to make
+ it a candidate for auto-association.
+ """
Modified: grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/meta.py
===================================================================
--- grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/meta.py 2008-05-04 12:41:50 UTC (rev 86352)
+++ grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/meta.py 2008-05-04 12:41:55 UTC (rev 86353)
@@ -21,6 +21,7 @@
from martian.error import GrokError
from grokcore.component.util import check_module_component
from grokcore.component.util import determine_module_component
+from grokcore.component.interfaces import IContext
def get_provides(factory):
provides = grokcore.component.provides.get(factory)
@@ -38,7 +39,7 @@
def grok(self, name, module, module_info, config, **kw):
context = determine_module_component(module_info,
grokcore.component.context,
- [grokcore.component.Context])
+ IContext)
grokcore.component.context.set(module, context)
return True
Modified: grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/util.py
===================================================================
--- grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/util.py 2008-05-04 12:41:50 UTC (rev 86352)
+++ grokcore.component/branches/jw-philipp-using-ndir-directives/src/grokcore/component/util.py 2008-05-04 12:41:55 UTC (rev 86353)
@@ -51,16 +51,16 @@
"directive."
% (component_name, factory, directive.__name__),
factory)
-
-def determine_module_component(module_info, directive, classes):
+
+def determine_module_component(module_info, directive, iface):
"""Determine module-level component.
The module-level component can be set explicitly using the
annotation (such as grok.context).
If there is no annotation, the module-level component is determined
- by scanning for subclasses of any in the list of classes.
-
+ by scanning for classes that implement an interface.
+
If there is no module-level component, the module-level component is
None.
@@ -70,7 +70,7 @@
is returned.
"""
module = module_info.getModule()
- components = list(scan_for_classes(module, classes))
+ components = list(scan_for_classes(module, interface=iface))
if len(components) == 0:
component = None
elif len(components) == 1:
More information about the Checkins
mailing list