summaryrefslogtreecommitdiffstats
path: root/ipalib/plugable.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-10-30 01:11:33 -0600
committerJason Gerard DeRose <jderose@redhat.com>2008-10-30 01:11:33 -0600
commitddb5449c7faabbd4c1b71adfe84c386b943a163f (patch)
tree07a38af3cfbdd29d6df6adfae4169d9130c1086d /ipalib/plugable.py
parente37760a27358021962a6e6a8a7fbdc5195ce5bbe (diff)
downloadfreeipa-ddb5449c7faabbd4c1b71adfe84c386b943a163f.tar.gz
freeipa-ddb5449c7faabbd4c1b71adfe84c386b943a163f.tar.xz
freeipa-ddb5449c7faabbd4c1b71adfe84c386b943a163f.zip
Did some initial work for Context plugins
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r--ipalib/plugable.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index b0ba32b7e..9ddcb30f6 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -27,6 +27,7 @@ http://docs.python.org/ref/sequence-types.html
import re
import inspect
+import threading
import errors
from errors import check_type, check_isinstance
from config import Environment, Env
@@ -705,6 +706,25 @@ class Registrar(DictProxy):
self.__registered.add(klass)
+class LazyContext(object):
+ """
+ On-demand creation of thread-local context attributes.
+ """
+
+ def __init__(self, api):
+ self.__api = api
+ self.__context = threading.local()
+
+ def __getattr__(self, name):
+ if name not in self.__context.__dict__:
+ if name not in self.__api.Context:
+ raise AttributeError('no Context plugin for %r' % name)
+ value = self.__api.Context[name].get_value()
+ self.__context.__dict__[name] = value
+ return self.__context.__dict__[name]
+
+
+
class API(DictProxy):
"""
Dynamic API object through which `Plugin` instances are accessed.
@@ -715,6 +735,7 @@ class API(DictProxy):
self.__done = set()
self.register = Registrar(*allowed)
self.env = Env()
+ self.context = LazyContext(self)
super(API, self).__init__(self.__d)
def __doing(self, name):