From a7b44eaab5b59b7a0ed16fe6ed72a7e8e8456b36 Mon Sep 17 00:00:00 2001 From: Jesus Lara Date: Fri, 10 Jan 2025 23:43:53 +0100 Subject: [PATCH] repair _dsn_template on some drivers --- asyncdb/drivers/cassandra.py | 21 +++++++++++---------- asyncdb/drivers/delta.py | 1 + asyncdb/drivers/hazel.py | 2 ++ asyncdb/drivers/jdbc.py | 2 ++ asyncdb/drivers/mcache.py | 1 + asyncdb/drivers/memcache.py | 1 + asyncdb/drivers/mssql.py | 3 ++- asyncdb/drivers/oracle.py | 2 +- asyncdb/drivers/rethink.py | 1 + asyncdb/drivers/scylladb.py | 1 + asyncdb/drivers/sql.py | 2 ++ asyncdb/drivers/sqlserver.py | 1 + asyncdb/version.py | 2 +- 13 files changed, 27 insertions(+), 13 deletions(-) diff --git a/asyncdb/drivers/cassandra.py b/asyncdb/drivers/cassandra.py index 0ecc32c9..b2743955 100644 --- a/asyncdb/drivers/cassandra.py +++ b/asyncdb/drivers/cassandra.py @@ -50,6 +50,7 @@ def record_factory(colnames, rows): class cassandra(InitDriver): _provider = "cassandra" _syntax = "cql" + _dsn_template = "cassandra://{username}:{password}@{host}:{port}/{database}" def __init__(self, loop: asyncio.AbstractEventLoop = None, params: dict = None, **kwargs): self.hosts: list = [] @@ -102,16 +103,16 @@ async def connection(self, keyspace=None): self._connected = False self._cluster = None try: - try: - if self.params["ssl"] is not None: - ssl_opts = { - "ca_certs": self.params["ssl"]["certfile"], - "ssl_version": PROTOCOL_TLSv1, - "keyfile": self.params["ssl"]["userkey"], - "certfile": self.params["ssl"]["usercert"], - } - except KeyError: - ssl_opts = {} + if self.params["ssl"] is not None: + ssl_opts = { + "ca_certs": self.params["ssl"]["certfile"], + "ssl_version": PROTOCOL_TLSv1, + "keyfile": self.params["ssl"]["userkey"], + "certfile": self.params["ssl"]["usercert"], + } + except KeyError: + ssl_opts = {} + try: if self.whitelist: policy = WhiteListRoundRobinPolicy(self.whitelist) else: diff --git a/asyncdb/drivers/delta.py b/asyncdb/drivers/delta.py index 66e92f08..88fcfae1 100644 --- a/asyncdb/drivers/delta.py +++ b/asyncdb/drivers/delta.py @@ -34,6 +34,7 @@ class delta(InitDriver): _provider = "delta" _syntax = "nosql" + _dsn_template = "" # DeltaTable DSN template, not used in this driver. def __init__(self, loop: asyncio.AbstractEventLoop = None, params: dict = None, **kwargs) -> None: diff --git a/asyncdb/drivers/hazel.py b/asyncdb/drivers/hazel.py index 6d24c78f..3d822401 100644 --- a/asyncdb/drivers/hazel.py +++ b/asyncdb/drivers/hazel.py @@ -72,6 +72,8 @@ def get_class_id(self): class hazel(InitDriver): _provider = "hazelcast" _syntax = "sql" + _dsn_template = "" + def __init__(self, dsn: str = None, loop: asyncio.AbstractEventLoop = None, params: dict = None, **kwargs): self._test_query = None diff --git a/asyncdb/drivers/jdbc.py b/asyncdb/drivers/jdbc.py index 1e85a83d..642b8e24 100644 --- a/asyncdb/drivers/jdbc.py +++ b/asyncdb/drivers/jdbc.py @@ -22,6 +22,8 @@ class jdbc(SQLDriver, DatabaseBackend, ModelBackend): _provider = "JDBC" _syntax = "sql" + _dsn_template: str = "" + def __init__(self, dsn: str = "", loop: asyncio.AbstractEventLoop = None, params: dict = None, **kwargs) -> None: self._test_query = "SELECT 1" diff --git a/asyncdb/drivers/mcache.py b/asyncdb/drivers/mcache.py index 56d29a88..104ee2a5 100644 --- a/asyncdb/drivers/mcache.py +++ b/asyncdb/drivers/mcache.py @@ -19,6 +19,7 @@ class mcache(InitDriver): _provider = "memcache" _syntax = "nosql" _behaviors = {"tcp_nodelay": True, "ketama": True} + _dsn_template = "" # Memcached DSN template, not used in this driver. def __init__(self, loop: asyncio.AbstractEventLoop = None, params: dict = None, **kwargs) -> None: super(mcache, self).__init__(loop=loop, params=params, **kwargs) diff --git a/asyncdb/drivers/memcache.py b/asyncdb/drivers/memcache.py index 2c92c3b4..152ec21f 100644 --- a/asyncdb/drivers/memcache.py +++ b/asyncdb/drivers/memcache.py @@ -16,6 +16,7 @@ class memcachePool(BasePool): """ Pool-based version of Memcached connector. """ + _dsn_template = "" # Memcached DSN template, not used in this driver. def __init__(self, dsn: str = "", loop: asyncio.AbstractEventLoop = None, params: dict = None, **kwargs) -> None: self._dsn = None diff --git a/asyncdb/drivers/mssql.py b/asyncdb/drivers/mssql.py index 2f2ddbeb..11f2fc8b 100644 --- a/asyncdb/drivers/mssql.py +++ b/asyncdb/drivers/mssql.py @@ -37,6 +37,8 @@ class mssql(SQLDriver, DBCursorBackend): _syntax = "sql" _test_query = "SELECT 1 as one" _charset: str = "UTF8" + _dsn_template: str = '' + def __init__(self, dsn: str = "", loop: asyncio.AbstractEventLoop = None, params: dict = None, **kwargs) -> None: self._dsn = "" @@ -44,7 +46,6 @@ def __init__(self, dsn: str = "", loop: asyncio.AbstractEventLoop = None, params self._version: str = None self.application_name = os.getenv("APP_NAME", "NAV") self._server_settings: dict = [] - self._connected: bool = False try: self.tds_version = kwargs["tds_version"] del kwargs["tds_version"] diff --git a/asyncdb/drivers/oracle.py b/asyncdb/drivers/oracle.py index 0a58937c..f8f88479 100644 --- a/asyncdb/drivers/oracle.py +++ b/asyncdb/drivers/oracle.py @@ -32,6 +32,7 @@ class oracle(SQLDriver): _provider = "oracle" _syntax = "sql" + _dsn_template: str = "{host}:{port}/{database}" def __init__(self, dsn: str = "", loop: asyncio.AbstractEventLoop = None, params: dict = None, **kwargs) -> None: """ @@ -51,7 +52,6 @@ def __init__(self, dsn: str = "", loop: asyncio.AbstractEventLoop = None, params """ self._test_query = "SELECT 1 FROM dual" _starttime = datetime.now() - self._dsn = "{host}:{port}/{database}" self._database = None self.application_name = os.getenv("APP_NAME", "ASYNCDB") if params: diff --git a/asyncdb/drivers/rethink.py b/asyncdb/drivers/rethink.py index b57b092c..5925c32e 100644 --- a/asyncdb/drivers/rethink.py +++ b/asyncdb/drivers/rethink.py @@ -87,6 +87,7 @@ async def fetch_all(self) -> Iterable[dict]: class rethink(InitDriver, DBCursorBackend): _provider = "rethink" _syntax = "rql" + _dsn_template: str = '' def __init__(self, loop: asyncio.AbstractEventLoop = None, params: dict = None, **kwargs): self.conditions = {} diff --git a/asyncdb/drivers/scylladb.py b/asyncdb/drivers/scylladb.py index cbfb03c0..3236e718 100644 --- a/asyncdb/drivers/scylladb.py +++ b/asyncdb/drivers/scylladb.py @@ -73,6 +73,7 @@ def record_factory(colnames, rows): class scylladb(InitDriver, ModelBackend): _provider = "scylladb" _syntax = "cql" + _dsn_template: str = '' def __init__(self, loop: asyncio.AbstractEventLoop = None, params: dict = None, **kwargs): self.hosts: list = [] diff --git a/asyncdb/drivers/sql.py b/asyncdb/drivers/sql.py index 13fb8cc2..3d83b31c 100644 --- a/asyncdb/drivers/sql.py +++ b/asyncdb/drivers/sql.py @@ -37,6 +37,8 @@ class SQLDriver(BaseDBDriver): _syntax = "sql" _test_query = "SELECT 1" + _dsn_template: str = "" + def __init__(self, dsn: str = "", loop: asyncio.AbstractEventLoop = None, params: dict = None, **kwargs) -> None: self._query_raw = "SELECT {fields} FROM {table} {where_cond}" diff --git a/asyncdb/drivers/sqlserver.py b/asyncdb/drivers/sqlserver.py index 1216ddbf..95d71ca1 100644 --- a/asyncdb/drivers/sqlserver.py +++ b/asyncdb/drivers/sqlserver.py @@ -53,6 +53,7 @@ class sqlserver(mssql): """ _provider = "sqlserver" + _dsn_template: str = '' def __init__(self, dsn: str = "", loop: asyncio.AbstractEventLoop = None, params: dict = None, **kwargs) -> None: try: diff --git a/asyncdb/version.py b/asyncdb/version.py index 8b667cf1..18f8f81d 100644 --- a/asyncdb/version.py +++ b/asyncdb/version.py @@ -3,7 +3,7 @@ __title__ = "asyncdb" __description__ = "Library for Asynchronous data source connections \ Collection of asyncio drivers." -__version__ = "2.10.1" +__version__ = "2.10.2" __copyright__ = "Copyright (c) 2020-2024 Jesus Lara" __author__ = "Jesus Lara" __author_email__ = "jesuslarag@gmail.com"