| [] |
[] |
| |
|
| Whenever the directive is used on a sub class of a component, the values set by |
Whenever the directive is used on a sub class of a component, the values set by |
| directives on the base classes are concatenated:: |
directives on the base classes are combined:: |
| |
|
| >>> class Qux(Foo): |
>>> class Qux(Foo): |
| ... multi(u'Triple') |
... multi(u'Triple') |
| GrokImportError: The factory method for the 'wrongmulti2' directive should |
GrokImportError: The factory method for the 'wrongmulti2' directive should |
| return a key-value pair. |
return a key-value pair. |
| |
|
| |
Like with MULTIPLE store, values set by directives using the DICT store are |
| |
combined:: |
| |
|
| >>> class multi(Directive): |
>>> class multi(Directive): |
| ... scope = CLASS |
... scope = CLASS |
| ... store = DICT |
... store = DICT |
| >>> print sorted(d.items()) |
>>> print sorted(d.items()) |
| [(1, 'CCC'), (2, 'BBB'), (3, 'DDD'), (4, 'EEE')] |
[(1, 'CCC'), (2, 'BBB'), (3, 'DDD'), (4, 'EEE')] |
| |
|
| |
Using MULTIPLE and DICT can also work on a module level, even though |
| |
inheritance has no meaning there:: |
| |
|
| |
>>> from martian import MODULE |
| |
>>> class multi(MultipleTimesDirective): |
| |
... scope = MODULE |
| |
... |
| |
>>> multi.__module__ = 'somethingelse' |
| |
>>> class module_with_directive(FakeModule): |
| |
... fake_module = True |
| |
... |
| |
... multi('One') |
| |
... multi('Two') |
| |
... |
| |
>>> module_with_directive = fake_import(module_with_directive) |
| |
>>> print multi.get(module_with_directive) |
| |
['One', 'Two'] |
| |
|
| |
>>> from martian import MODULE |
| |
>>> class multi(Directive): |
| |
... scope = MODULE |
| |
... store = DICT |
| |
... def factory(self, value, andanother): |
| |
... return value, andanother |
| |
... |
| |
>>> multi.__module__ = 'somethingelse' |
| |
>>> class module_with_directive(FakeModule): |
| |
... fake_module = True |
| |
... |
| |
... multi(1, 'One') |
| |
... multi(2, 'Two') |
| |
... |
| |
>>> module_with_directive = fake_import(module_with_directive) |
| |
>>> d = multi.get(module_with_directive) |
| |
>>> print sorted(d.items()) |
| |
[(1, 'One'), (2, 'Two')] |
| |
|
| Calculated defaults |
Calculated defaults |
| ------------------- |
------------------- |
| |
|