diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2009-01-23 18:02:32 -0700 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2009-02-03 15:29:03 -0500 |
commit | 66b6029e4058e1d29f35e4170423d127c2ebb2c4 (patch) | |
tree | fdc6655aee4267166166c512229402a2e17c3188 /ipalib/backend.py | |
parent | 0a3ae60038c7b672d83f24678e2d791b3cad443e (diff) | |
download | freeipa-66b6029e4058e1d29f35e4170423d127c2ebb2c4.tar.gz freeipa-66b6029e4058e1d29f35e4170423d127c2ebb2c4.tar.xz freeipa-66b6029e4058e1d29f35e4170423d127c2ebb2c4.zip |
Ported xmlclient to subclass from Connectible
Diffstat (limited to 'ipalib/backend.py')
-rw-r--r-- | ipalib/backend.py | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/ipalib/backend.py b/ipalib/backend.py index e286c5079..bb8d31012 100644 --- a/ipalib/backend.py +++ b/ipalib/backend.py @@ -36,26 +36,36 @@ class Backend(plugable.Plugin): class Connectible(Backend): - # Override in subclass: - connection_klass = None - def connect(self, *args, **kw): """ Create thread-local connection. """ if hasattr(context, self.name): raise StandardError( - "connection 'context.%s' already exists in thread %r" % ( + "connect: 'context.%s' already exists in thread %r" % ( self.name, threading.currentThread().getName() ) ) - if not issubclass(self.connection_klass, Connection): - raise ValueError( - '%s.connection_klass must be a request.Connection subclass' % self.name + conn = self.create_connection(*args, **kw) + setattr(context, self.name, Connection(conn, self.disconnect)) + assert self.conn is conn + self.info('Created connection context.%s' % self.name) + + def create_connection(self, *args, **kw): + raise NotImplementedError('%s.create_connection()' % self.name) + + def disconnect(self): + if not hasattr(context, self.name): + raise StandardError( + "disconnect: 'context.%s' does not exist in thread %r" % ( + self.name, threading.currentThread().getName() + ) ) - conn = self.connection_klass(*args, **kw) - setattr(context, self.name, conn) - assert self.conn is conn.conn + self.destroy_connection() + self.info('Destroyed connection context.%s' % self.name) + + def destroy_connection(self): + raise NotImplementedError('%s.destroy_connection()' % self.name) def isconnected(self): """ |