Ported xmlclient to subclass from Connectible

This commit is contained in:
Jason Gerard DeRose
2009-01-23 18:02:32 -07:00
committed by Rob Crittenden
parent 0a3ae60038
commit 66b6029e40
5 changed files with 105 additions and 110 deletions

View File

@@ -26,7 +26,7 @@ import threading
import locale
import gettext
from base import ReadOnly, lock
from constants import OVERRIDE_ERROR
from constants import OVERRIDE_ERROR, CALLABLE_ERROR
# Thread-local storage of most per-request information
@@ -38,22 +38,15 @@ class Connection(ReadOnly):
Base class for connection objects stored on `request.context`.
"""
def __init__(self, *args, **kw):
self.conn = self.create(*args, **kw)
def __init__(self, conn, disconnect):
self.conn = conn
if not callable(disconnect):
raise TypeError(
CALLABLE_ERROR % ('disconnect', disconnect, type(disconnect))
)
self.disconnect = disconnect
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():
"""
@@ -61,7 +54,7 @@ def destroy_context():
"""
for (name, value) in context.__dict__.items():
if isinstance(value, Connection):
value.close()
value.disconnect()
delattr(context, name)