summaryrefslogtreecommitdiffstats
path: root/ipalib/plugable.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-18 21:45:25 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-18 21:45:25 +0000
commite524c826db12ffed029d627bd4afcfc03e7f899a (patch)
tree97494f019e9090324e55cc12a64e8857b9f6434d /ipalib/plugable.py
parent14eb96493b5b323eeee53b81a91f93508189b918 (diff)
downloadfreeipa-e524c826db12ffed029d627bd4afcfc03e7f899a.tar.gz
freeipa-e524c826db12ffed029d627bd4afcfc03e7f899a.tar.xz
freeipa-e524c826db12ffed029d627bd4afcfc03e7f899a.zip
297: Added a better example in docstring for ReadOnly
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r--ipalib/plugable.py37
1 files changed, 18 insertions, 19 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index dfefbe16b..4e356783c 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -48,26 +48,25 @@ class ReadOnly(object):
For example:
- >>> class givenname(ReadOnly):
- >>> def __init__(self):
- >>> self.whatever = 'some value' # Hasn't been locked yet
- >>> lock(self)
- >>>
- >>> def finalize(self, api):
- >>> # After the instance has been locked, attributes can still be
- >>> # set, but only in a round-about, unconventional way:
- >>> object.__setattr__(self, 'api', api)
- >>>
- >>> def normalize(self, value):
- >>> # After the instance has been locked, trying to set an
- >>> # attribute in the normal way will raise AttributeError.
- >>> self.value = value # Not thread safe!
- >>> return self.actually_normalize()
- >>>
- >>> def actually_normalize(self):
- >>> # Again, this is not thread safe:
- >>> return unicode(self.value).strip()
+ >>> ro = ReadOnly() # Initially unlocked, can setattr, delattr
+ >>> ro.name = 'John Doe'
+ >>> ro.message = 'Hello, world!'
+ >>> del ro.message
+ >>> ro.__lock__() # Now locked, cannot setattr, delattr
+ >>> ro.message = 'How are you?'
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ File "/home/jderose/projects/freeipa2/ipalib/plugable.py", line 93, in __setattr__
+ (self.__class__.__name__, name)
+ AttributeError: read-only: cannot set ReadOnly.message
+ >>> del ro.name
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ File "/home/jderose/projects/freeipa2/ipalib/plugable.py", line 104, in __delattr__
+ (self.__class__.__name__, name)
+ AttributeError: read-only: cannot del ReadOnly.name
"""
+
__locked = False
def __lock__(self):