summaryrefslogtreecommitdiffstats
path: root/ipalib/plugable.py
diff options
context:
space:
mode:
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.