diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-14 00:39:23 -0600 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-14 00:39:23 -0600 |
commit | 20fa90cfb6e954040de47551762dfbb7680dba51 (patch) | |
tree | 63b319ac079f189ca8785f834dfa78e167693a7d /ipalib | |
parent | 149912d0e7bb75459c52c9404a1af537023729dc (diff) | |
download | freeipa-20fa90cfb6e954040de47551762dfbb7680dba51.tar.gz freeipa-20fa90cfb6e954040de47551762dfbb7680dba51.tar.xz freeipa-20fa90cfb6e954040de47551762dfbb7680dba51.zip |
Some small cleanup on Environment, filled in docstrings
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/plugable.py | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 87f96876d..4a2658a74 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -693,19 +693,37 @@ class Registrar(DictProxy): class Environment(object): + """ + A mapping object used to store the environment variables. + """ + def __init__(self): object.__setattr__(self, '_Environment__map', {}) - def __setattr__(self, name, value): - self[name] = value - def __getattr__(self, name): + """ + Return the attribute named ``name``. + """ return self[name] + def __setattr__(self, name, value): + """ + Set the attribute named ``name`` to ``value``. + """ + self[name] = value + def __delattr__(self, name): - del self[name] + """ + Raise AttributeError (deletion is not allowed). + """ + raise AttributeError('cannot del %s.%s' % + (self.__class__.__name__, name) + ) def __getitem__(self, key): + """ + Return the value corresponding to ``key``. + """ val = self.__map[key] if hasattr(val, 'get_value'): return val.get_value() @@ -713,22 +731,26 @@ class Environment(object): return val def __setitem__(self, key, value): + """ + Set the item at ``key`` to ``value``. + """ if key in self or hasattr(self, key): raise AttributeError('cannot overwrite %s.%s' % (self.__class__.__name__, key) ) self.__map[key] = value - def __delitem__(self, key): - raise AttributeError('read-only: cannot del %s.%s' % - (self.__class__.__name__, key) - ) - def __contains__(self, key): + """ + Return True if instance contains ``key``; otherwise return False. + """ return key in self.__map def __iter__(self): - for key in self.__map: + """ + Iterate through keys in ascending order. + """ + for key in sorted(self.__map): yield key def update(self, new_vals, ignore_errors = False): |