diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2009-05-20 15:19:09 -0600 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2009-05-21 14:32:45 -0400 |
commit | 7e58b29a92157fad40b50ef31f8c075b9dc363b7 (patch) | |
tree | 5f541cde18209bda0bd5df7c34365ce59d4c70b2 /ipalib/parameters.py | |
parent | 7b93f7bbd7d52132503a3c5691841c3e757616f9 (diff) | |
download | freeipa-7e58b29a92157fad40b50ef31f8c075b9dc363b7.tar.gz freeipa-7e58b29a92157fad40b50ef31f8c075b9dc363b7.tar.xz freeipa-7e58b29a92157fad40b50ef31f8c075b9dc363b7.zip |
Completed Param.use_in_context() functionality, which is now used by Command and Object
Diffstat (limited to 'ipalib/parameters.py')
-rw-r--r-- | ipalib/parameters.py | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/ipalib/parameters.py b/ipalib/parameters.py index 0c2748ee5..2ecc6178d 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -381,24 +381,54 @@ class Param(ReadOnly): def use_in_context(self, env): """ - Return ``True`` if this param should be used in ``env.context``. + Return ``True`` if this parameter should be used in ``env.context``. - For example: + If a parameter is created with niether the ``include`` nor the + ``exclude`` kwarg, this method will always return ``True``. For + example: >>> from ipalib.config import Env - >>> server = Env() - >>> server.context = 'server' - >>> client = Env() - >>> client.context = 'client' - >>> param = Param('my_param', include=['server', 'webui']) - >>> param.use_in_context(server) + >>> param = Param('my_param') + >>> param.use_in_context(Env(context='foo')) + True + >>> param.use_in_context(Env(context='bar')) + True + + If a parameter is created with an ``include`` kwarg, this method will + only return ``True`` if ``env.context`` is in ``include``. For example: + + >>> param = Param('my_param', include=['foo', 'whatever']) + >>> param.include + frozenset(['foo', 'whatever']) + >>> param.use_in_context(Env(context='foo')) True - >>> param.use_in_context(client) + >>> param.use_in_context(Env(context='bar')) + False + + If a paremeter is created with an ``exclude`` kwarg, this method will + only return ``True`` if ``env.context`` is not in ``exclude``. For + example: + + >>> param = Param('my_param', exclude=['foo', 'whatever']) + >>> param.exclude + frozenset(['foo', 'whatever']) + >>> param.use_in_context(Env(context='foo')) False + >>> param.use_in_context(Env(context='bar')) + True + + Note that the ``include`` and ``exclude`` kwargs are mutually exclusive + and that at most one can be suppelied to `Param.__init__()`. For + example: + + >>> param = Param('nope', include=['foo'], exclude=['bar']) + Traceback (most recent call last): + ... + ValueError: Param('nope'): cannot have both include=frozenset(['foo']) and exclude=frozenset(['bar']) - So that a subclass can add additional logic basic on other environment - variables, the `config.Env` instance is passed in rather than just the - value of ``env.context``. + So that subclasses can add additional logic based on other environment + variables, the entire `config.Env` instance is passed in rather than + just the value of ``env.context``. """ if self.include is not None: return (env.context in self.include) |