label-studio-sdk 1.0.14__py3-none-any.whl → 1.0.15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of label-studio-sdk might be problematic. Click here for more details.
- label_studio_sdk/tokens/client_ext.py +51 -22
- {label_studio_sdk-1.0.14.dist-info → label_studio_sdk-1.0.15.dist-info}/METADATA +1 -1
- {label_studio_sdk-1.0.14.dist-info → label_studio_sdk-1.0.15.dist-info}/RECORD +5 -5
- {label_studio_sdk-1.0.14.dist-info → label_studio_sdk-1.0.15.dist-info}/LICENSE +0 -0
- {label_studio_sdk-1.0.14.dist-info → label_studio_sdk-1.0.15.dist-info}/WHEEL +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import threading
|
|
2
2
|
import typing
|
|
3
3
|
from datetime import datetime, timezone
|
|
4
|
-
import
|
|
4
|
+
import ssl
|
|
5
5
|
|
|
6
6
|
import httpx
|
|
7
7
|
import jwt
|
|
@@ -78,34 +78,63 @@ class TokensClientExt:
|
|
|
78
78
|
|
|
79
79
|
return self._access_token
|
|
80
80
|
|
|
81
|
+
def _get_client_params(self, existing_client: httpx.AsyncClient) -> dict:
|
|
82
|
+
"""Extract parameters from an existing client to create a new one.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
existing_client: The existing client to extract parameters from.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
dict: Parameters for creating a new client.
|
|
89
|
+
"""
|
|
90
|
+
return {
|
|
91
|
+
'auth': existing_client.auth,
|
|
92
|
+
'params': existing_client.params,
|
|
93
|
+
'headers': existing_client.headers,
|
|
94
|
+
'cookies': existing_client.cookies,
|
|
95
|
+
'timeout': existing_client.timeout,
|
|
96
|
+
'follow_redirects': existing_client.follow_redirects,
|
|
97
|
+
'max_redirects': existing_client.max_redirects,
|
|
98
|
+
'event_hooks': existing_client.event_hooks,
|
|
99
|
+
'base_url': existing_client.base_url,
|
|
100
|
+
'trust_env': existing_client.trust_env,
|
|
101
|
+
'default_encoding': existing_client._default_encoding,
|
|
102
|
+
'verify': existing_client._transport._pool._ssl_context.verify_mode != ssl.CERT_NONE,
|
|
103
|
+
'http1': existing_client._transport._pool._http1,
|
|
104
|
+
'http2': existing_client._transport._pool._http2,
|
|
105
|
+
'limits': httpx.Limits(
|
|
106
|
+
max_connections=existing_client._transport._pool._max_connections,
|
|
107
|
+
max_keepalive_connections=existing_client._transport._pool._max_keepalive_connections,
|
|
108
|
+
keepalive_expiry=existing_client._transport._pool._keepalive_expiry
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
81
112
|
def refresh(self) -> AccessTokenResponse:
|
|
82
113
|
"""Refresh the access token and return the token response."""
|
|
83
|
-
# We don't do this often, just use a separate sync httpx client for simplicity here
|
|
84
|
-
# (avoids complicated state management and sync vs async handling)
|
|
85
|
-
# Create a new client with the same parameters as the existing one
|
|
86
114
|
existing_client = self._client_wrapper.httpx_client.httpx_client
|
|
87
115
|
|
|
88
|
-
#
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if param_name != 'self': # Skip 'self' parameter
|
|
93
|
-
try:
|
|
94
|
-
value = getattr(existing_client, param_name, None)
|
|
95
|
-
if value is not None:
|
|
96
|
-
client_params[param_name] = value
|
|
97
|
-
except AttributeError:
|
|
98
|
-
continue
|
|
99
|
-
|
|
100
|
-
with httpx.Client(**client_params) as sync_client:
|
|
101
|
-
response = sync_client.request(
|
|
116
|
+
# For sync client, use it directly
|
|
117
|
+
if isinstance(existing_client, httpx.Client):
|
|
118
|
+
print(f"\nverify:{existing_client._transport._pool._ssl_context.verify_mode != ssl.CERT_NONE}")
|
|
119
|
+
response = existing_client.request(
|
|
102
120
|
method="POST",
|
|
103
121
|
url=f"{self._base_url}/api/token/refresh/",
|
|
104
122
|
json={"refresh": self._api_key},
|
|
105
123
|
headers={"Content-Type": "application/json"},
|
|
106
124
|
)
|
|
125
|
+
else:
|
|
126
|
+
# If an async client was used, get all parameters from the client to init a new sync client
|
|
127
|
+
client_params = self._get_client_params(existing_client)
|
|
128
|
+
|
|
129
|
+
with httpx.Client(**client_params) as sync_client:
|
|
130
|
+
response = sync_client.request(
|
|
131
|
+
method="POST",
|
|
132
|
+
url=f"{self._base_url}/api/token/refresh/",
|
|
133
|
+
json={"refresh": self._api_key},
|
|
134
|
+
headers={"Content-Type": "application/json"},
|
|
135
|
+
)
|
|
107
136
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
137
|
+
if response.status_code == 200:
|
|
138
|
+
return AccessTokenResponse.parse_obj(response.json())
|
|
139
|
+
else:
|
|
140
|
+
raise ApiError(status_code=response.status_code, body=response.json())
|
|
@@ -215,7 +215,7 @@ label_studio_sdk/tasks/types/tasks_list_request_fields.py,sha256=5YXxQgyzoaL0QjS
|
|
|
215
215
|
label_studio_sdk/tasks/types/tasks_list_response.py,sha256=j1pNluAWQOQ8-d9YXQyRQAefnrl8uLQEB7_L55Z8DME,1136
|
|
216
216
|
label_studio_sdk/tokens/__init__.py,sha256=FTtvy8EDg9nNNg9WCatVgKTRYV8-_v1roeGPAKoa_pw,65
|
|
217
217
|
label_studio_sdk/tokens/client.py,sha256=SvBcKXIsrTihMJC72Ifxv0U1N3gtLGz3JxqdXYA_hD4,19101
|
|
218
|
-
label_studio_sdk/tokens/client_ext.py,sha256=
|
|
218
|
+
label_studio_sdk/tokens/client_ext.py,sha256=Rma4ROcJPQOcBBGsA8Iteqk7WrbW7DTU381Ay5pJMiY,6134
|
|
219
219
|
label_studio_sdk/types/__init__.py,sha256=fQykjzHpX04ftslk5I_hWSJQ_H9Kd8XJAmSv18EVOIc,8905
|
|
220
220
|
label_studio_sdk/types/access_token_response.py,sha256=RV9FqkIiFR_9kmKueB-KiqjVyneiqUkMVueAlk5fUyc,624
|
|
221
221
|
label_studio_sdk/types/annotation.py,sha256=AnHm2VjMasWZsaNXVSUzLYbpYrmM4NPZgWQh7WGa6ZQ,3157
|
|
@@ -364,7 +364,7 @@ label_studio_sdk/workspaces/members/client.py,sha256=IVM52Yq_9zMQ3TUHT0AkZ5BTQ9a
|
|
|
364
364
|
label_studio_sdk/workspaces/members/types/__init__.py,sha256=ZIa_rd7d6K9ZITjTU6fptyGgvjNDySksJ7Rbn4wyhD4,252
|
|
365
365
|
label_studio_sdk/workspaces/members/types/members_create_response.py,sha256=7Hp5FSWm4xR5ZOEmEIglq5HYtM9KWZZBDp87jw7jYFg,668
|
|
366
366
|
label_studio_sdk/workspaces/members/types/members_list_response_item.py,sha256=DIc5DJoVahI9olBis_iFgOJrAf05m2fCE8g4R5ZeDko,712
|
|
367
|
-
label_studio_sdk-1.0.
|
|
368
|
-
label_studio_sdk-1.0.
|
|
369
|
-
label_studio_sdk-1.0.
|
|
370
|
-
label_studio_sdk-1.0.
|
|
367
|
+
label_studio_sdk-1.0.15.dist-info/LICENSE,sha256=ymVrFcHiJGjHeY30NWZgdV-xzNEtfuC63oK9ZeMDjhs,11341
|
|
368
|
+
label_studio_sdk-1.0.15.dist-info/METADATA,sha256=Ct3zUaMfhUAHG0IuTDHQ3jCjtD0HcPVxN0Ocj-JPajI,6033
|
|
369
|
+
label_studio_sdk-1.0.15.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
370
|
+
label_studio_sdk-1.0.15.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|