summaryrefslogtreecommitdiffstats
path: root/ipalib/plugable.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-08-15 01:04:19 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-08-15 01:04:19 +0000
commitf6c2181eebf6e6bd794eaca8b78d3b35ad3be4e4 (patch)
tree4b0fc2718504736d16916445aeabde7e01ff46b7 /ipalib/plugable.py
parent88a5b3ae2587ef71efecc1b59eb9ec94e09cacad (diff)
downloadfreeipa-f6c2181eebf6e6bd794eaca8b78d3b35ad3be4e4.tar.gz
freeipa-f6c2181eebf6e6bd794eaca8b78d3b35ad3be4e4.tar.xz
freeipa-f6c2181eebf6e6bd794eaca8b78d3b35ad3be4e4.zip
170: Added SetProxy and DictProxy classes to plugable so container emulation can be consolidated
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r--ipalib/plugable.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 45c73354..0d8286a4 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -122,6 +122,39 @@ def lock(readonly):
return readonly
+class SetProxy(ReadOnly):
+ def __init__(self, s):
+ allowed = (set, frozenset, dict)
+ if type(s) not in allowed:
+ raise TypeError('%r not in %r' % (type(s), allowed))
+ self.__s = s
+ lock(self)
+
+ def __len__(self):
+ return len(self.__s)
+
+ def __iter__(self):
+ for key in sorted(self.__s):
+ yield key
+
+ def __contains__(self, key):
+ return key in self.__s
+
+
+class DictProxy(SetProxy):
+ def __init__(self, d):
+ if type(d) is not dict:
+ raise TypeError('%r is not %r' % (type(d), dict))
+ self.__d = d
+ super(DictProxy, self).__init__(d)
+
+ def __getitem__(self, key):
+ """
+ Returns the value
+ """
+ return self.__d[key]
+
+
class Plugin(ReadOnly):
"""
Base class for all plugins.