[Checkins] SVN: grok/trunk/src/grok/ don't depend on alphabetical
order
Philipp von Weitershausen
philikon at philikon.de
Sat Oct 14 13:57:01 EDT 2006
Log message for revision 70618:
don't depend on alphabetical order
Changed:
U grok/trunk/src/grok/_grok.py
U grok/trunk/src/grok/adapter.txt
A grok/trunk/src/grok/tests/alphabetical.py
-=-
Modified: grok/trunk/src/grok/_grok.py
===================================================================
--- grok/trunk/src/grok/_grok.py 2006-10-14 17:43:28 UTC (rev 70617)
+++ grok/trunk/src/grok/_grok.py 2006-10-14 17:56:59 UTC (rev 70618)
@@ -36,7 +36,9 @@
def grok(dotted_name):
# TODO for now we only grok modules
module = resolve(dotted_name)
+
context = None
+ adapters = []
for name in dir(module):
obj = getattr(module, name)
@@ -46,6 +48,10 @@
if check_subclass(obj, Model):
context = obj
elif check_subclass(obj, Adapter):
- if context is None:
- raise GrokError("Adapter without context")
- component.provideAdapter(obj, adapts=(context,))
+ adapters.append(obj)
+
+ if adapters and context is None:
+ raise GrokError("Adapter without context")
+
+ for factory in adapters:
+ component.provideAdapter(factory, adapts=(context,))
Modified: grok/trunk/src/grok/adapter.txt
===================================================================
--- grok/trunk/src/grok/adapter.txt 2006-10-14 17:43:28 UTC (rev 70617)
+++ grok/trunk/src/grok/adapter.txt 2006-10-14 17:56:59 UTC (rev 70618)
@@ -43,3 +43,23 @@
Traceback (most recent call last):
...
GrokError: Adapter without context
+
+Clean up:
+
+ >>> cleanUp()
+
+Grok does not depend on the alphabetical order:
+
+ >>> grok.grok('grok.tests.alphabetical')
+
+ >>> from grok.tests.alphabetical import IHome, Home, ZCave
+ >>> cave = ZCave()
+ >>> home = IHome(cave)
+
+ >>> IHome.providedBy(home)
+ True
+ >>> isinstance(home, Home)
+ True
+
+If the model is defined after the adapter, it should still be grokked
+properly:
Added: grok/trunk/src/grok/tests/alphabetical.py
===================================================================
--- grok/trunk/src/grok/tests/alphabetical.py 2006-10-14 17:43:28 UTC (rev 70617)
+++ grok/trunk/src/grok/tests/alphabetical.py 2006-10-14 17:56:59 UTC (rev 70618)
@@ -0,0 +1,12 @@
+import grok
+from zope import interface
+
+class ZCave(grok.Model):
+ """we call this `ZCave` because we want to test that we do not
+ depend on alphabetical order"""
+
+class IHome(interface.Interface):
+ pass
+
+class Home(grok.Adapter):
+ grok.implements(IHome)
Property changes on: grok/trunk/src/grok/tests/alphabetical.py
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Checkins
mailing list