from db.connection import Connection
class Holder:
def __init__(self, pool, internal = None, readonly = True):
self.pool = pool
self.internal = internal
self.readonly = readonly
def __enter__(self):
if not self.internal:
self.internal = self.pool.asquire(self.readonly)
self.connection = Connection(
self.pool,
internal = self.internal,
readonly = self.readonly )
return self.connection
def __exit__(self, _exc_type, _exc_value, _traceback):
self.connection.release()
self.pool.release(self.connection.internal, self.readonly)