diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-01 03:12:17 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-01 03:12:17 +0000 |
commit | 31fc955355ac8d873b82d129021f599f820c2694 (patch) | |
tree | 85e686aefaffeddd6307e4e0eeff4447c85727e3 /ipalib/plugable.py | |
parent | f53dec2600f95246a72fa3c847a485d2a94edfa7 (diff) | |
download | freeipa-31fc955355ac8d873b82d129021f599f820c2694.tar.gz freeipa-31fc955355ac8d873b82d129021f599f820c2694.tar.xz freeipa-31fc955355ac8d873b82d129021f599f820c2694.zip |
34: Added tests.unit_common with frequently used utility functions; split ro __setattr__, __delattr__ methods out of Proxy and into new ReadOnly base class; added corresponding unit tests
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r-- | ipalib/plugable.py | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py index de5f3f8ff..e74809cd7 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -67,7 +67,32 @@ class Plugin(object): ) -class Proxy(object): +class ReadOnly(object): + """ + Base class for classes with read-only attributes. + """ + __slots__ = tuple() + + def __setattr__(self, name, value): + """ + This raises an AttributeError anytime an attempt is made to set an + attribute. + """ + raise AttributeError('read-only: cannot set %s.%s' % + (self.__class__.__name__, name) + ) + + def __delattr__(self, name): + """ + This raises an AttributeError anytime an attempt is made to delete an + attribute. + """ + raise AttributeError('read-only: cannot del %s.%s' % + (self.__class__.__name__, name) + ) + + +class Proxy(ReadOnly): """ Used to only export certain attributes into the dynamic API. @@ -92,24 +117,6 @@ class Proxy(object): for name in self.__slots__: object.__setattr__(self, name, getattr(obj, name)) - def __setattr__(self, name, value): - """ - Proxy instances are read-only. This raises an AttributeError - anytime an attempt is made to set an attribute. - """ - raise AttributeError('cannot set %s.%s' % - (self.__class__.__name__, name) - ) - - def __delattr__(self, name): - """ - Proxy instances are read-only. This raises an AttributeError - anytime an attempt is made to delete an attribute. - """ - raise AttributeError('cannot del %s.%s' % - (self.__class__.__name__, name) - ) - def __repr__(self): return '%s(%r)' % (self.__class__.__name__, self.__obj) |