@@ -132,7 +132,8 @@ def __init__(self,
132
132
:param log_communication_on_error: Log socket communication when an error (status_code of HTTP Response) is
133
133
detected. Default is not to do this.
134
134
:param max_tries: Max tries for BACKOFF. Default is 2.
135
- :param abstract_api: Set all parameters by copying them from another instance. Overrides all other parameters.
135
+ :param abstract_api: Set all parameters by copying them from the instance given by this parameter. Overrides
136
+ all other parameters.
136
137
"""
137
138
self ._root_url = getattr (abstract_api , '_root_url' , root_url )
138
139
self ._session = getattr (abstract_api , '_session' , session )
@@ -671,6 +672,8 @@ class GraphConnectionHandler(AbstractAPI):
671
672
672
673
_pool_block = False
673
674
675
+ _version_info : dict = None
676
+
674
677
def __init__ (self ,
675
678
root_url : str = None ,
676
679
raise_exceptions : bool = True ,
@@ -683,7 +686,8 @@ def __init__(self,
683
686
log_communication_on_error : bool = None ,
684
687
max_tries : int = None ,
685
688
pool_maxsize : int = None ,
686
- pool_block : bool = None ):
689
+ pool_block : bool = None ,
690
+ connection_handler = None ):
687
691
"""
688
692
Constructor
689
693
@@ -720,7 +724,11 @@ def __init__(self,
720
724
Default is 10. *pool_maxsize* is ignored when *_session* is set.
721
725
:param pool_block: Block any connections that exceed the pool_maxsize. Default is False: Allow more connections,
722
726
but do not cache them. See requests.adapters.HTTPAdapter. *pool_block* is ignored when *_session* is set.
727
+ :param connection_handler: Copy parameters from this already existing connection handler. Overrides all other
728
+ parameters.
723
729
"""
730
+ root_url = getattr (connection_handler , '_root_url' , root_url )
731
+
724
732
if not root_url :
725
733
raise ValueError ("'root_url' must not be empty." )
726
734
@@ -732,19 +740,24 @@ def __init__(self,
732
740
session = requests .Session ()
733
741
session .mount (root_url , adapter )
734
742
735
- super ().__init__ (root_url = root_url ,
736
- session = session ,
737
- raise_exceptions = raise_exceptions ,
738
- proxies = proxies ,
739
- timeout = timeout ,
740
- headers = headers ,
741
- client_name = client_name ,
742
- ssl_config = ssl_config ,
743
- log_communication_on_error = log_communication_on_error ,
744
- max_tries = max_tries )
743
+ super ().__init__ (
744
+ root_url = root_url ,
745
+ 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
755
+ )
756
+
757
+ self .custom_endpoints = getattr (connection_handler , '_custom_endpoints' , custom_endpoints )
758
+ self ._version_info = getattr (connection_handler , '_version_info' , None )
745
759
746
- self ._version_info = None
747
- self .custom_endpoints = custom_endpoints
760
+ self .get_version ()
748
761
749
762
@staticmethod
750
763
def _remove_slash (endpoint : str ) -> str :
@@ -840,13 +853,14 @@ def _construct_result(_endpoint: str, _protocol: str) -> Tuple[
840
853
# REST API operations
841
854
###############################################################################################################
842
855
843
- def get_version (self ) -> dict :
856
+ def get_version (self , force_update : bool = False ) -> dict :
844
857
"""
845
858
HIRO REST query API: `GET self._endpoint + '/api/version'`
846
859
860
+ :param force_update: Force updating the internal cache with version_info via API request.
847
861
:return: The result payload
848
862
"""
849
- if not self ._version_info :
863
+ if not self ._version_info or force_update :
850
864
url = self ._root_url + '/api/version'
851
865
self ._version_info = self .get (url )
852
866
@@ -857,14 +871,11 @@ def get_version(self) -> dict:
857
871
# TokenApiHandler classes
858
872
###################################################################################################################
859
873
860
- class AbstractTokenApiHandler (AbstractAPI ):
874
+ class AbstractTokenApiHandler (GraphConnectionHandler ):
861
875
"""
862
876
Root class for all TokenApiHandler classes. This adds token handling.
863
877
"""
864
878
865
- _connection_handler : GraphConnectionHandler
866
- """Reference to an GraphConnectionHandler containing version information and requests.Session"""
867
-
868
879
def __init__ (self ,
869
880
root_url : str = None ,
870
881
raise_exceptions : bool = True ,
@@ -917,11 +928,12 @@ def __init__(self,
917
928
:param pool_block: Block any connections that exceed the pool_maxsize. Default is False: Allow more connections,
918
929
but do not cache them. See requests.adapters.HTTPAdapter. *pool_block* is ignored when
919
930
*connection_handler* is set and already contains a _session.
920
- :param connection_handler: Use an already existing connection handler. This feature allows for several distinct
921
- TokenApiHandlers to operate on the same connection without querying unnecessary version information for
922
- each or building their own requests.Sessions. Overrides all other parameters.
931
+ :param connection_handler: Copy all parameters from this already existing connection handler. This feature
932
+ allows for several distinct TokenApiHandlers to operate on the same connection without querying
933
+ unnecessary version information for each or building their own requests.Sessions. Overrides all other
934
+ parameters.
923
935
"""
924
- self . _connection_handler = connection_handler or GraphConnectionHandler (
936
+ super (). __init__ (
925
937
root_url = root_url ,
926
938
raise_exceptions = raise_exceptions ,
927
939
proxies = proxies ,
@@ -933,30 +945,10 @@ def __init__(self,
933
945
log_communication_on_error = log_communication_on_error ,
934
946
max_tries = max_tries ,
935
947
pool_maxsize = pool_maxsize ,
936
- pool_block = pool_block
948
+ pool_block = pool_block ,
949
+ connection_handler = connection_handler
937
950
)
938
951
939
- super ().__init__ (abstract_api = self ._connection_handler )
940
-
941
- ###############################################################################################################
942
- # Access connection handler
943
- ###############################################################################################################
944
-
945
- def get_api_endpoint_of (self , api_name : str ) -> str :
946
- return self ._connection_handler .get_api_endpoint_of (api_name )
947
-
948
- def get_websocket_config (self , api_name : str ) -> Tuple [
949
- str ,
950
- str ,
951
- Optional [str ],
952
- Optional [int ],
953
- Optional [dict ]
954
- ]:
955
- return self ._connection_handler .get_websocket_config (api_name )
956
-
957
- def get_version (self ):
958
- return self ._connection_handler .get_version ()
959
-
960
952
###############################################################################################################
961
953
# Token handling
962
954
###############################################################################################################
@@ -1049,9 +1041,10 @@ def __init__(self,
1049
1041
:param pool_block: Block any connections that exceed the pool_maxsize. Default is False: Allow more connections,
1050
1042
but do not cache them. See requests.adapters.HTTPAdapter. *pool_block* is ignored when
1051
1043
*connection_handler* is set and already contains a _session.
1052
- :param connection_handler: Use an already existing connection handler. This feature allows for several distinct
1053
- TokenApiHandlers to operate on the same connection without querying unnecessary version information for
1054
- each or building their own requests.Sessions. Overrides all other connection specific parameters.
1044
+ :param connection_handler: Copy all parameters from this already existing connection handler. This feature
1045
+ allows for several distinct TokenApiHandlers to operate on the same connection without querying
1046
+ unnecessary version information for each or building their own requests.Sessions. Overrides all other
1047
+ parameters.
1055
1048
"""
1056
1049
super ().__init__ (
1057
1050
root_url = root_url ,
@@ -1132,9 +1125,10 @@ def __init__(self,
1132
1125
:param pool_block: Block any connections that exceed the pool_maxsize. Default is False: Allow more connections,
1133
1126
but do not cache them. See requests.adapters.HTTPAdapter. *pool_block* is ignored when
1134
1127
*connection_handler* is set and already contains a _session.
1135
- :param connection_handler: Use an already existing connection handler. This feature allows for several distinct
1136
- TokenApiHandlers to operate on the same connection without querying unnecessary version information for
1137
- each or building their own requests.Sessions. Overrides all other connection specific parameters.
1128
+ :param connection_handler: Copy all parameters from this already existing connection handler. This feature
1129
+ allows for several distinct TokenApiHandlers to operate on the same connection without querying
1130
+ unnecessary version information for each or building their own requests.Sessions. Overrides all other
1131
+ parameters.
1138
1132
"""
1139
1133
super ().__init__ (
1140
1134
root_url = root_url ,
@@ -1343,9 +1337,10 @@ def __init__(self,
1343
1337
:param pool_block: Block any connections that exceed the pool_maxsize. Default is False: Allow more connections,
1344
1338
but do not cache them. See requests.adapters.HTTPAdapter. *pool_block* is ignored when
1345
1339
*connection_handler* is set and already contains a _session.
1346
- :param connection_handler: Use an already existing connection handler. This feature allows for several distinct
1347
- TokenApiHandlers to operate on the same connection without querying unnecessary version information for
1348
- each or building their own requests.Sessions. Overrides all other connection specific parameters.
1340
+ :param connection_handler: Copy all parameters from this already existing connection handler. This feature
1341
+ allows for several distinct TokenApiHandlers to operate on the same connection without querying
1342
+ unnecessary version information for each or building their own requests.Sessions. Overrides all other
1343
+ parameters.
1349
1344
"""
1350
1345
super ().__init__ (
1351
1346
root_url = root_url ,
0 commit comments