Skip to content

Commit 4acaa3b

Browse files
committed
Better parameter passing in constructors
1 parent c2605bb commit 4acaa3b

File tree

1 file changed

+23
-139
lines changed

1 file changed

+23
-139
lines changed

src/hiro_graph_client/clientlib.py

+23-139
Original file line numberDiff line numberDiff line change
@@ -674,20 +674,17 @@ class GraphConnectionHandler(AbstractAPI):
674674

675675
_version_info: dict = None
676676

677+
_lock: threading.RLock
678+
"""Reentrant mutex for thread safety"""
679+
677680
def __init__(self,
678681
root_url: str = None,
679-
raise_exceptions: bool = True,
680-
proxies: dict = None,
681-
headers: dict = None,
682-
timeout: int = None,
683-
client_name: str = None,
684682
custom_endpoints: dict = None,
685-
ssl_config: SSLConfig = None,
686-
log_communication_on_error: bool = None,
687-
max_tries: int = None,
688683
pool_maxsize: int = None,
689684
pool_block: bool = None,
690-
connection_handler=None):
685+
connection_handler=None,
686+
*args,
687+
**kwargs):
691688
"""
692689
Constructor
693690
@@ -727,6 +724,8 @@ def __init__(self,
727724
:param connection_handler: Copy parameters from this already existing connection handler. Overrides all other
728725
parameters.
729726
"""
727+
self._lock = threading.RLock()
728+
730729
root_url = getattr(connection_handler, '_root_url', root_url)
731730

732731
if not root_url:
@@ -743,15 +742,8 @@ def __init__(self,
743742
super().__init__(
744743
root_url=root_url,
745744
session=session,
746-
raise_exceptions=raise_exceptions,
747-
proxies=proxies,
748-
timeout=timeout,
749-
headers=headers,
750-
client_name=client_name,
751-
ssl_config=ssl_config,
752-
log_communication_on_error=log_communication_on_error,
753-
max_tries=max_tries,
754-
abstract_api=connection_handler
745+
abstract_api=connection_handler,
746+
**kwargs
755747
)
756748

757749
self.custom_endpoints = getattr(connection_handler, '_custom_endpoints', custom_endpoints)
@@ -860,11 +852,12 @@ def get_version(self, force_update: bool = False) -> dict:
860852
:param force_update: Force updating the internal cache with version_info via API request.
861853
:return: The result payload
862854
"""
863-
if not self._version_info or force_update:
864-
url = self._root_url + '/api/version'
865-
self._version_info = self.get(url)
855+
with self._lock:
856+
if not self._version_info or force_update:
857+
url = self._root_url + '/api/version'
858+
self._version_info = self.get(url)
866859

867-
return self._version_info
860+
return self._version_info
868861

869862

870863
###################################################################################################################
@@ -876,20 +869,7 @@ class AbstractTokenApiHandler(GraphConnectionHandler):
876869
Root class for all TokenApiHandler classes. This adds token handling.
877870
"""
878871

879-
def __init__(self,
880-
root_url: str = None,
881-
raise_exceptions: bool = True,
882-
proxies: dict = None,
883-
headers: dict = None,
884-
timeout: int = None,
885-
client_name: str = None,
886-
custom_endpoints: dict = None,
887-
ssl_config: SSLConfig = None,
888-
log_communication_on_error: bool = None,
889-
max_tries: int = None,
890-
pool_maxsize: int = None,
891-
pool_block: bool = None,
892-
connection_handler: GraphConnectionHandler = None):
872+
def __init__(self, *args, **kwargs):
893873
"""
894874
Constructor
895875
@@ -933,21 +913,7 @@ def __init__(self,
933913
unnecessary version information for each or building their own requests.Sessions. Overrides all other
934914
parameters.
935915
"""
936-
super().__init__(
937-
root_url=root_url,
938-
raise_exceptions=raise_exceptions,
939-
proxies=proxies,
940-
headers=headers,
941-
timeout=timeout,
942-
client_name=client_name,
943-
custom_endpoints=custom_endpoints,
944-
ssl_config=ssl_config,
945-
log_communication_on_error=log_communication_on_error,
946-
max_tries=max_tries,
947-
pool_maxsize=pool_maxsize,
948-
pool_block=pool_block,
949-
connection_handler=connection_handler
950-
)
916+
super().__init__(*args, **kwargs)
951917

952918
###############################################################################################################
953919
# Token handling
@@ -1002,21 +968,7 @@ class FixedTokenApiHandler(AbstractTokenApiHandler):
1002968

1003969
_token: str
1004970

1005-
def __init__(self,
1006-
root_url: str = None,
1007-
token: str = None,
1008-
raise_exceptions: bool = True,
1009-
proxies: dict = None,
1010-
headers: dict = None,
1011-
timeout: int = 600,
1012-
client_name: str = None,
1013-
custom_endpoints: dict = None,
1014-
ssl_config: SSLConfig = None,
1015-
log_communication_on_error: bool = None,
1016-
max_tries: int = None,
1017-
pool_maxsize: int = None,
1018-
pool_block: bool = None,
1019-
connection_handler: GraphConnectionHandler = None):
971+
def __init__(self, token: str = None, *args, **kwargs):
1020972
"""
1021973
Constructor
1022974
@@ -1046,21 +998,7 @@ def __init__(self,
1046998
unnecessary version information for each or building their own requests.Sessions. Overrides all other
1047999
parameters.
10481000
"""
1049-
super().__init__(
1050-
root_url=root_url,
1051-
raise_exceptions=raise_exceptions,
1052-
proxies=proxies,
1053-
timeout=timeout,
1054-
headers=headers,
1055-
client_name=client_name,
1056-
custom_endpoints=custom_endpoints,
1057-
ssl_config=ssl_config,
1058-
log_communication_on_error=log_communication_on_error,
1059-
max_tries=max_tries,
1060-
pool_maxsize=pool_maxsize,
1061-
pool_block=pool_block,
1062-
connection_handler=connection_handler
1063-
)
1001+
super().__init__(*args, **kwargs)
10641002

10651003
self._token = token
10661004

@@ -1086,21 +1024,7 @@ class EnvironmentTokenApiHandler(AbstractTokenApiHandler):
10861024

10871025
_env_var: str
10881026

1089-
def __init__(self,
1090-
root_url: str = None,
1091-
env_var: str = 'HIRO_TOKEN',
1092-
raise_exceptions: bool = True,
1093-
proxies: dict = None,
1094-
headers: dict = None,
1095-
timeout: int = 600,
1096-
client_name: str = None,
1097-
custom_endpoints: dict = None,
1098-
ssl_config: SSLConfig = None,
1099-
log_communication_on_error: bool = None,
1100-
max_tries: int = None,
1101-
pool_maxsize: int = None,
1102-
pool_block: bool = None,
1103-
connection_handler: GraphConnectionHandler = None):
1027+
def __init__(self, env_var: str = 'HIRO_TOKEN', *args, **kwargs):
11041028
"""
11051029
Constructor
11061030
@@ -1130,21 +1054,7 @@ def __init__(self,
11301054
unnecessary version information for each or building their own requests.Sessions. Overrides all other
11311055
parameters.
11321056
"""
1133-
super().__init__(
1134-
root_url=root_url,
1135-
raise_exceptions=raise_exceptions,
1136-
proxies=proxies,
1137-
headers=headers,
1138-
timeout=timeout,
1139-
client_name=client_name,
1140-
custom_endpoints=custom_endpoints,
1141-
ssl_config=ssl_config,
1142-
log_communication_on_error=log_communication_on_error,
1143-
max_tries=max_tries,
1144-
pool_maxsize=pool_maxsize,
1145-
pool_block=pool_block,
1146-
connection_handler=connection_handler
1147-
)
1057+
super().__init__(*args, **kwargs)
11481058

11491059
self._env_var = env_var
11501060

@@ -1291,24 +1201,12 @@ class PasswordAuthTokenApiHandler(AbstractTokenApiHandler):
12911201
_secure_logging: bool = True
12921202

12931203
def __init__(self,
1294-
root_url: str = None,
12951204
username: str = None,
12961205
password: str = None,
12971206
client_id: str = None,
12981207
client_secret: str = None,
12991208
secure_logging: bool = True,
1300-
raise_exceptions: bool = True,
1301-
proxies: dict = None,
1302-
headers: dict = None,
1303-
timeout: int = 600,
1304-
client_name: str = None,
1305-
custom_endpoints: dict = None,
1306-
ssl_config: SSLConfig = None,
1307-
log_communication_on_error: bool = None,
1308-
max_tries: int = None,
1309-
pool_maxsize: int = None,
1310-
pool_block: bool = None,
1311-
connection_handler: GraphConnectionHandler = None):
1209+
*args, **kwargs):
13121210
"""
13131211
Constructor
13141212
@@ -1342,21 +1240,7 @@ def __init__(self,
13421240
unnecessary version information for each or building their own requests.Sessions. Overrides all other
13431241
parameters.
13441242
"""
1345-
super().__init__(
1346-
root_url=root_url,
1347-
raise_exceptions=raise_exceptions,
1348-
proxies=proxies,
1349-
headers=headers,
1350-
timeout=timeout,
1351-
client_name=client_name,
1352-
custom_endpoints=custom_endpoints,
1353-
ssl_config=ssl_config,
1354-
log_communication_on_error=log_communication_on_error,
1355-
max_tries=max_tries,
1356-
pool_maxsize=pool_maxsize,
1357-
pool_block=pool_block,
1358-
connection_handler=connection_handler
1359-
)
1243+
super().__init__(*args, **kwargs)
13601244

13611245
self._username = username
13621246
self._password = password

0 commit comments

Comments
 (0)