Added stuff for managing connections and new Executioner backend base class

This commit is contained in:
Jason Gerard DeRose
2009-02-03 15:29:03 -05:00
committed by Rob Crittenden
parent e0b00d5981
commit f7375bb609
4 changed files with 280 additions and 6 deletions
+33
View File
@@ -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)