def get_driver(connection_string, *args, **kwargs): """Create driver's instance according to specified connection string""" # NOTE(ayelistratov) Backward compatibility with old Messaging notation # Remove after patching all OS services # NOTE(ishakhat) Raise exception when ParsedResult.scheme is empty if "://" not in connection_string: connection_string += "://" parsed_connection = urlparse.urlparse(connection_string) LOG.debug("String %s looks like a connection string, trying it.", connection_string) backend = parsed_connection.scheme # NOTE(toabctl): To be able to use the connection_string for as sqlalchemy # connection string, transform the backend to the correct driver # See https://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls if backend in ["mysql", "mysql+pymysql", "mysql+mysqldb", "postgresql", "postgresql+psycopg2"]: backend = "sqlalchemy" for driver in _utils.itersubclasses(Driver): if backend == driver.get_name(): return driver(connection_string, *args, **kwargs) raise ValueError("Driver not found for connection string: " "%s" % connection_string)
def get_driver(connection_string, *args, **kwargs): """Create driver's instance according to specified connection string""" # NOTE(ayelistratov) Backward compatibility with old Messaging notation # Remove after patching all OS services # NOTE(ishakhat) Raise exception when ParsedResult.scheme is empty if "://" not in connection_string: connection_string += "://" parsed_connection = urlparse.urlparse(connection_string) LOG.debug("String %s looks like a connection string, trying it.", connection_string) backend = parsed_connection.scheme # NOTE(toabctl): To be able to use the connection_string for as sqlalchemy # connection string, transform the backend to the correct driver # See https://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls if backend in [ "mysql", "mysql+pymysql", "mysql+mysqldb", "postgresql", "postgresql+psycopg2" ]: backend = "sqlalchemy" for driver in _utils.itersubclasses(Driver): if backend == driver.get_name(): return driver(connection_string, *args, **kwargs) raise ValueError("Driver not found for connection string: " "%s" % connection_string)
def test_itersubclasses(self): class A(object): pass class B(A): pass class C(A): pass class D(C): pass self.assertEqual([B, C, D], list(utils.itersubclasses(A))) class E(type): pass self.assertEqual([], list(utils.itersubclasses(E)))
def get_driver(connection_string, *args, **kwargs): """Create driver's instance according to specified connection string""" # NOTE(ayelistratov) Backward compatibility with old Messaging notation # Remove after patching all OS services # NOTE(ishakhat) Raise exception when ParsedResult.scheme is empty if "://" not in connection_string: connection_string += "://" parsed_connection = urlparse.urlparse(connection_string) LOG.debug("String %s looks like a connection string, trying it.", connection_string) backend = parsed_connection.scheme for driver in _utils.itersubclasses(Driver): if backend == driver.get_name(): return driver(connection_string, *args, **kwargs) raise ValueError("Driver not found for connection string: " "%s" % connection_string)
def factory(name, *args, **kwargs): for driver in utils.itersubclasses(Notifier): if name == driver.__name__: return driver(*args, **kwargs).notify raise TypeError("There is no driver, with name: %s" % name)