summaryrefslogtreecommitdiffstats
path: root/ipalib/request.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-01-23 15:49:16 -0700
committerRob Crittenden <rcritten@redhat.com>2009-02-03 15:29:03 -0500
commitf7375bb6090f32c3feb3d71e196ed01ee19fecc8 (patch)
treef80054b751d6bcace55e90f60a8ffb72c6afc6fe /ipalib/request.py
parente0b00d598147f294c88b3cfb1b2218fe4381792a (diff)
downloadfreeipa-f7375bb6090f32c3feb3d71e196ed01ee19fecc8.tar.gz
freeipa-f7375bb6090f32c3feb3d71e196ed01ee19fecc8.tar.xz
freeipa-f7375bb6090f32c3feb3d71e196ed01ee19fecc8.zip
Added stuff for managing connections and new Executioner backend base class
Diffstat (limited to 'ipalib/request.py')
-rw-r--r--ipalib/request.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/ipalib/request.py b/ipalib/request.py
index 6ad7ad35f..812e526d6 100644
--- a/ipalib/request.py
+++ b/ipalib/request.py
@@ -25,6 +25,7 @@ Per-request thread-local data.
import threading
import locale
import gettext
+from base import ReadOnly, lock
from constants import OVERRIDE_ERROR
@@ -32,6 +33,38 @@ from constants import OVERRIDE_ERROR
context = threading.local()
+class Connection(ReadOnly):
+ """
+ Base class for connection objects stored on `request.context`.
+ """
+
+ def __init__(self, *args, **kw):
+ self.conn = self.create(*args, **kw)
+ lock(self)
+
+ def create(self, *args, **kw):
+ """
+ Create and return the connection (implement in subclass).
+ """
+ raise NotImplementedError('%s.create()' % self.__class__.__name__)
+
+ def close(self):
+ """
+ Close the connection (implement in subclass).
+ """
+ raise NotImplementedError('%s.close()' % self.__class__.__name__)
+
+
+def destroy_context():
+ """
+ Delete all attributes on thread-local `request.context`.
+ """
+ for (name, value) in context.__dict__.items():
+ if isinstance(value, Connection):
+ value.close()
+ delattr(context, name)
+
+
def ugettext(message):
if hasattr(context, 'ugettext'):
return context.ugettext(message)