[Checkins] SVN: martian/trunk/ Merge infrae-multiple-nobase branch.
Martijn Faassen
faassen at infrae.com
Fri Sep 19 08:34:56 EDT 2008
Log message for revision 91265:
Merge infrae-multiple-nobase branch.
Changed:
U martian/trunk/CHANGES.txt
U martian/trunk/src/martian/__init__.py
U martian/trunk/src/martian/directive.py
U martian/trunk/src/martian/directive.txt
-=-
Modified: martian/trunk/CHANGES.txt
===================================================================
--- martian/trunk/CHANGES.txt 2008-09-19 12:27:30 UTC (rev 91264)
+++ martian/trunk/CHANGES.txt 2008-09-19 12:34:55 UTC (rev 91265)
@@ -4,8 +4,12 @@
0.11 (unreleased)
=================
-* ...
+Feature changes
+---------------
+* Added MULTIPLE_NOBASE option for directive store. This is like MULTIPLE
+ but doesn't inherit information from the base class.
+
0.10 (2008-06-06)
=================
Modified: martian/trunk/src/martian/__init__.py
===================================================================
--- martian/trunk/src/martian/__init__.py 2008-09-19 12:27:30 UTC (rev 91264)
+++ martian/trunk/src/martian/__init__.py 2008-09-19 12:34:55 UTC (rev 91265)
@@ -5,7 +5,7 @@
from martian.components import MethodGrokker
from martian.util import scan_for_classes
from martian.directive import Directive, MarkerDirective, MultipleTimesDirective
-from martian.directive import ONCE, ONCE_NOBASE, MULTIPLE, DICT
+from martian.directive import ONCE, ONCE_NOBASE, MULTIPLE, MULTIPLE_NOBASE, DICT
from martian.directive import CLASS, CLASS_OR_MODULE, MODULE
from martian.directive import (
validateText, validateInterface, validateClass, validateInterfaceOrClass)
Modified: martian/trunk/src/martian/directive.py
===================================================================
--- martian/trunk/src/martian/directive.py 2008-09-19 12:27:30 UTC (rev 91264)
+++ martian/trunk/src/martian/directive.py 2008-09-19 12:34:55 UTC (rev 91265)
@@ -56,6 +56,13 @@
MULTIPLE = StoreMultipleTimes()
+class StoreMultipleTimesNoBase(StoreMultipleTimes):
+
+ def get(self, directive, component, default):
+ return component.__dict__.get(directive.dotted_name(), default)
+
+MULTIPLE_NOBASE = StoreMultipleTimesNoBase()
+
class StoreDict(StoreOnce):
def get(self, directive, component, default):
@@ -203,7 +210,6 @@
store = MULTIPLE
default = []
-
class MarkerDirective(Directive):
store = ONCE
default = False
Modified: martian/trunk/src/martian/directive.txt
===================================================================
--- martian/trunk/src/martian/directive.txt 2008-09-19 12:27:30 UTC (rev 91264)
+++ martian/trunk/src/martian/directive.txt 2008-09-19 12:34:55 UTC (rev 91265)
@@ -216,7 +216,25 @@
>>> multi.bind().get(Qux)
[u'Once', u'Twice', u'Triple']
+You can also create a directive that ignores the values on the base classes::
+ >>> from martian import MULTIPLE_NOBASE
+ >>> class multi(Directive):
+ ... scope = CLASS
+ ... store = MULTIPLE_NOBASE
+
+ >>> class Foo(object):
+ ... multi(u"Once")
+ ... multi(u"Twice")
+ >>> multi.bind().get(Foo)
+ [u'Once', u'Twice']
+
+ >>> class Qux(Foo):
+ ... multi(u'Triple')
+ ... multi(u'More')
+ >>> multi.bind().get(Qux)
+ [u'Triple', u'More']
+
Using a directive multiple times, as a dictionary
-------------------------------------------------
More information about the Checkins
mailing list