[Checkins] SVN: grok/branches/faassen-martian/martian/src/martian/
Initial code for meta-martians. Should test.
Martijn Faassen
faassen at infrae.com
Tue May 1 18:15:08 EDT 2007
Log message for revision 74979:
Initial code for meta-martians. Should test.
Changed:
U grok/branches/faassen-martian/martian/src/martian/core.py
U grok/branches/faassen-martian/martian/src/martian/util.py
-=-
Modified: grok/branches/faassen-martian/martian/src/martian/core.py
===================================================================
--- grok/branches/faassen-martian/martian/src/martian/core.py 2007-05-01 22:08:06 UTC (rev 74978)
+++ grok/branches/faassen-martian/martian/src/martian/core.py 2007-05-01 22:15:07 UTC (rev 74979)
@@ -7,11 +7,6 @@
from martian.components import (MartianBase, ClassMartian, InstanceMartian,
GlobalMartian)
-def is_baseclass(name, component):
- return (type(component) is type and
- (name.endswith('Base') or
- util.class_annotation_nobase(component, 'grok.baseclass', False)))
-
class ModuleMartian(MartianBase):
implements(IMultiMartian)
@@ -39,7 +34,7 @@
obj = getattr(module, name)
if not util.defined_locally(obj, module.__name__):
continue
- if is_baseclass(name, obj):
+ if util.is_baseclass(name, obj):
continue
grokked = martian.grok(name, obj, **kw)
if grokked:
@@ -127,3 +122,25 @@
return self._multi_global_martian.grok(name, obj, **kw)
else:
return self._multi_instance_martian.grok(name, obj, **kw)
+
+# deep meta mode here - we define martians that can pick up the
+# three kinds of martian: ClassMartian, InstanceMartian and ModuleMartian
+class MetaMartian(ClassMartian):
+ def grok(self, name, obj, **kw):
+ the_martian.register(obj())
+
+class ClassMetaMartian(MetaMartian):
+ component_class = ClassMartian
+
+class InstanceMetaMartian(MetaMartian):
+ component_class = InstanceMartian
+
+class GlobalMetaMartian(MetaMartian):
+ component_class = GlobalMartian
+
+# the global single martian to bootstrap everything
+the_martian = MultiMartian()
+# bootstrap the meta-martians
+the_martian.register(ClassMetaMartian())
+the_martian.register(InstanceMetaMartian())
+the_martian.register(GlobalMetaMartian())
Modified: grok/branches/faassen-martian/martian/src/martian/util.py
===================================================================
--- grok/branches/faassen-martian/martian/src/martian/util.py 2007-05-01 22:08:06 UTC (rev 74978)
+++ grok/branches/faassen-martian/martian/src/martian/util.py 2007-05-01 22:15:07 UTC (rev 74979)
@@ -47,6 +47,10 @@
def caller_module():
return sys._getframe(2).f_globals['__name__']
+def is_baseclass(name, component):
+ return (type(component) is type and
+ (name.endswith('Base') or
+ class_annotation_nobase(component, 'grok.baseclass', False)))
def class_annotation(obj, name, default):
return getattr(obj, '__%s__' % name.replace('.', '_'), default)
More information about the Checkins
mailing list