Skip to content

Commit

Permalink
Using url.translate_connect_args for connection parameters translation
Browse files Browse the repository at this point in the history
  • Loading branch information
aadel committed Jul 25, 2024
1 parent 091dc7c commit 695d4b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
28 changes: 10 additions & 18 deletions src/sqlalchemy_solr/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, **kw):
self.port = None
self.server_path = None
self.collection = None
self.db = None
self.database = None
self.username = None
self.password = None
self.token = None
Expand All @@ -62,22 +62,18 @@ def __init__(self, **kw):

def create_connect_args(self, url):

url_port = url.port or 8047
qargs = {"host": url.host, "port": url_port}

db_parts = url.database.split("/")
db = ".".join(db_parts)
qargs = url.translate_connect_args()
qargs.update(url.query)

self.proto = "http://"
if "use_ssl" in url.query:
if url.query["use_ssl"] in [True, "True", "true"]:
self.proto = "https://"
if "use_ssl" in url.query and url.query["use_ssl"] in ["True", "true"]:
self.proto = "https://"

if "token" in url.query:
if url.query["token"] is not None:
self.token = url.query["token"]
if "token" in url.query and url.query["token"] is not None:
self.token = url.query["token"]

# Mapping server path and collection
db_parts = qargs["database"].split("/")
if db_parts[0]:
server_path = db_parts[0]
else:
Expand All @@ -92,7 +88,7 @@ def create_connect_args(self, url):
self.port = url.port or defaults.PORT
self.username = url.username
self.password = url.password
self.db = db
self.database = url.database
self.server_path = server_path
self.collection = collection

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

qargs.update(url.query)
qargs["db"] = db
qargs["server_path"] = server_path
qargs["collection"] = collection
qargs["username"] = url.username
qargs["password"] = url.password

return [], qargs
return ([], qargs)

def get_table_names(self, connection, schema=None, **kw):
local_payload = _PAYLOAD.copy()
Expand Down
18 changes: 13 additions & 5 deletions src/sqlalchemy_solr/solrdbapi/_solrdbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class Connection:
def __init__(
self,
host,
db,
database,
username,
password,
server_path,
Expand All @@ -303,7 +303,7 @@ def __init__(
):

self.host = host
self.db = db
self.database = database
self.username = username
self.password = password
self.server_path = server_path
Expand Down Expand Up @@ -356,7 +356,7 @@ def rollback(self):
def cursor(self):
return Cursor(
self.host,
self.db,
self.database,
self.username,
self.password,
self.server_path,
Expand All @@ -371,7 +371,7 @@ def cursor(self):
# pylint: disable=too-many-arguments
def connect(
host,
db,
database,
server_path,
collection,
port=defaults.PORT,
Expand Down Expand Up @@ -405,7 +405,15 @@ def connect(
raise DatabaseHTTPError(response.text, response.status_code)

return Connection(
host, db, username, password, server_path, collection, port, proto, session
host,
database,
username,
password,
server_path,
collection,
port,
proto,
session,
)


Expand Down

0 comments on commit 695d4b7

Please sign in to comment.