mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-09-03 20:52:56 -05:00
Added stuff for managing connections and new Executioner backend base class
This commit is contained in:
committed by
Rob Crittenden
parent
e0b00d5981
commit
f7375bb609
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user