Skip to content

Commit 695d4b7

Browse files
committed
Using url.translate_connect_args for connection parameters translation
1 parent 091dc7c commit 695d4b7

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

src/sqlalchemy_solr/http.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, **kw):
5151
self.port = None
5252
self.server_path = None
5353
self.collection = None
54-
self.db = None
54+
self.database = None
5555
self.username = None
5656
self.password = None
5757
self.token = None
@@ -62,22 +62,18 @@ def __init__(self, **kw):
6262

6363
def create_connect_args(self, url):
6464

65-
url_port = url.port or 8047
66-
qargs = {"host": url.host, "port": url_port}
67-
68-
db_parts = url.database.split("/")
69-
db = ".".join(db_parts)
65+
qargs = url.translate_connect_args()
66+
qargs.update(url.query)
7067

7168
self.proto = "http://"
72-
if "use_ssl" in url.query:
73-
if url.query["use_ssl"] in [True, "True", "true"]:
74-
self.proto = "https://"
69+
if "use_ssl" in url.query and url.query["use_ssl"] in ["True", "true"]:
70+
self.proto = "https://"
7571

76-
if "token" in url.query:
77-
if url.query["token"] is not None:
78-
self.token = url.query["token"]
72+
if "token" in url.query and url.query["token"] is not None:
73+
self.token = url.query["token"]
7974

8075
# Mapping server path and collection
76+
db_parts = qargs["database"].split("/")
8177
if db_parts[0]:
8278
server_path = db_parts[0]
8379
else:
@@ -92,7 +88,7 @@ def create_connect_args(self, url):
9288
self.port = url.port or defaults.PORT
9389
self.username = url.username
9490
self.password = url.password
95-
self.db = db
91+
self.database = url.database
9692
self.server_path = server_path
9793
self.collection = collection
9894

@@ -109,14 +105,10 @@ def create_connect_args(self, url):
109105
# Utilize this session in other methods.
110106
self.session = session
111107

112-
qargs.update(url.query)
113-
qargs["db"] = db
114108
qargs["server_path"] = server_path
115109
qargs["collection"] = collection
116-
qargs["username"] = url.username
117-
qargs["password"] = url.password
118110

119-
return [], qargs
111+
return ([], qargs)
120112

121113
def get_table_names(self, connection, schema=None, **kw):
122114
local_payload = _PAYLOAD.copy()

src/sqlalchemy_solr/solrdbapi/_solrdbapi.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class Connection:
292292
def __init__(
293293
self,
294294
host,
295-
db,
295+
database,
296296
username,
297297
password,
298298
server_path,
@@ -303,7 +303,7 @@ def __init__(
303303
):
304304

305305
self.host = host
306-
self.db = db
306+
self.database = database
307307
self.username = username
308308
self.password = password
309309
self.server_path = server_path
@@ -356,7 +356,7 @@ def rollback(self):
356356
def cursor(self):
357357
return Cursor(
358358
self.host,
359-
self.db,
359+
self.database,
360360
self.username,
361361
self.password,
362362
self.server_path,
@@ -371,7 +371,7 @@ def cursor(self):
371371
# pylint: disable=too-many-arguments
372372
def connect(
373373
host,
374-
db,
374+
database,
375375
server_path,
376376
collection,
377377
port=defaults.PORT,
@@ -405,7 +405,15 @@ def connect(
405405
raise DatabaseHTTPError(response.text, response.status_code)
406406

407407
return Connection(
408-
host, db, username, password, server_path, collection, port, proto, session
408+
host,
409+
database,
410+
username,
411+
password,
412+
server_path,
413+
collection,
414+
port,
415+
proto,
416+
session,
409417
)
410418

411419

0 commit comments

Comments
 (0)