Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
    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)))
Пример #4
0
    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)))
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
    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)
Пример #8
0
    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)