[Checkins] SVN: grok/trunk/src/grok/ implemented continue_scanning
for Grokkers
Wolfgang Schnerring
wosc at wosc.de
Sat Jan 6 08:56:55 EST 2007
Log message for revision 71733:
implemented continue_scanning for Grokkers
Changed:
U grok/trunk/src/grok/components.py
U grok/trunk/src/grok/grokker.py
A grok/trunk/src/grok/tests/grokker/continue_scanning.py
A grok/trunk/src/grok/tests/grokker/continue_scanning_fixture.py
-=-
Modified: grok/trunk/src/grok/components.py
===================================================================
--- grok/trunk/src/grok/components.py 2007-01-06 13:29:33 UTC (rev 71732)
+++ grok/trunk/src/grok/components.py 2007-01-06 13:56:55 UTC (rev 71733)
@@ -52,6 +52,7 @@
"""
priority = 0
+ continue_scanning = False
class ClassGrokker(GrokkerBase):
Modified: grok/trunk/src/grok/grokker.py
===================================================================
--- grok/trunk/src/grok/grokker.py 2007-01-06 13:29:33 UTC (rev 71732)
+++ grok/trunk/src/grok/grokker.py 2007-01-06 13:56:55 UTC (rev 71733)
@@ -43,7 +43,8 @@
for grokker in grokkers:
if grokker.match(obj):
components[grokker.component_class].append((name, obj))
- break
+ if not grokker.continue_scanning:
+ break
return components
Added: grok/trunk/src/grok/tests/grokker/continue_scanning.py
===================================================================
--- grok/trunk/src/grok/tests/grokker/continue_scanning.py 2007-01-06 13:29:33 UTC (rev 71732)
+++ grok/trunk/src/grok/tests/grokker/continue_scanning.py 2007-01-06 13:56:55 UTC (rev 71733)
@@ -0,0 +1,40 @@
+"""
+A Grokker can declare that scanning should continue, so that other Grokkers can
+still perform actions on the grokked components.
+
+Here we define AlphaGrokker which has higher priority than BetaGrokker but does
+not block BetaGrokker from picking up the same component::
+
+ >>> grok.grok(__name__)
+
+In the fixture there is AlphaBetaSub that inherits from both Alpha and Beta.
+Thus, both Grokkers are executed, with AlphaGrokker coming before BetaGrokker::
+
+ >>> grok.grok('grok.tests.grokker.continue_scanning_fixture')
+ alpha
+ beta
+
+"""
+import grok
+
+
+class Alpha(object):
+ pass
+
+class Beta(object):
+ pass
+
+class AlphaGrokker(grok.ClassGrokker):
+ component_class = Alpha
+ continue_scanning = True
+ priority = 1 # we need to go before BetaGrokker
+
+ def register(self, context, name, factory, module_info, templates):
+ print "alpha"
+
+
+class BetaGrokker(grok.ClassGrokker):
+ component_class = Beta
+
+ def register(self, context, name, factory, module_info, templates):
+ print "beta"
Added: grok/trunk/src/grok/tests/grokker/continue_scanning_fixture.py
===================================================================
--- grok/trunk/src/grok/tests/grokker/continue_scanning_fixture.py 2007-01-06 13:29:33 UTC (rev 71732)
+++ grok/trunk/src/grok/tests/grokker/continue_scanning_fixture.py 2007-01-06 13:56:55 UTC (rev 71733)
@@ -0,0 +1,4 @@
+from grok.tests.grokker.continue_scanning import Alpha, Beta
+
+class AlphaBetaSub(Alpha, Beta):
+ pass
More information about the Checkins
mailing list