Exemplo n.º 1
0
def connect(connectString):
    if isinstance(connectString, basestring):
        connectString = ConnectString.parse(connectString)
    elif not isinstance(connectString, ConnectString):
        raise TypeError("Expected string or ConnectString object")
    driver = connectString.driver

    importRoot = os.path.dirname(__file__)
    moduleRoot = __name__
    addParts = ['drivers', driver]

    driverPath = os.path.join(importRoot, *addParts)
    for suffix in ('.py', '.pyc', '.so', 'module.so'):
        if os.path.exists(driverPath + suffix):
            break
    else:
        raise TypeError("Could not find database driver %r" % (driver,))

    moduleName = '.'.join([moduleRoot] + addParts)
    __import__(moduleName)

    for name, value in inspect.getmembers(sys.modules[moduleName]):
        if name.startswith('_') or not inspect.isclass(value):
            continue
        if issubclass(value, DatabaseConnection) and value.driver == driver:
            return value.connect(connectString)
    else:
        raise TypeError("Driver %r lacks a proper driver subclass" % (driver,))
Exemplo n.º 2
0
    def __init__(self, path, min=None):
        self.path = ConnectString.parse(path)
        self.pool_running = False
        self.shutdownID = None
        self.cleanupTask = None

        if min:
            self.min = min

        self.connections = set()
        self.connQueue = defer.DeferredQueue()

        from twisted.internet import reactor
        self.reactor = reactor