Skip to content

Commit 58bb802

Browse files
author
wilmeryan
committed
bump urllib3==1.26.5
1 parent b6356e8 commit 58bb802

File tree

3 files changed

+104
-26
lines changed

3 files changed

+104
-26
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
requests==2.26.0
2-
urllib3==1.26.0
2+
urllib3==1.26.5

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"Programming Language :: Python :: 3.7",
1717
"Topic :: Scientific/Engineering :: Artificial Intelligence",
1818
],
19-
install_requires=["requests>=2.26.0", "urllib3>=1.26.0"],
19+
install_requires=["requests>=2.26.0", "urllib3>=1.26.5"],
2020
)

sypht/client.py

Lines changed: 102 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ def _create_session(self):
7575
return requests.Session()
7676

7777
def _authenticate_v2(self, endpoint, client_id, client_secret, audience):
78-
basic_auth_slug = b64encode((client_id + ":" + client_secret).encode("utf-8")).decode(
79-
"utf-8"
80-
)
78+
basic_auth_slug = b64encode(
79+
(client_id + ":" + client_secret).encode("utf-8")
80+
).decode("utf-8")
8181
result = self.requests.post(
8282
endpoint,
8383
headers={
@@ -95,7 +95,9 @@ def _authenticate_v2(self, endpoint, client_id, client_secret, audience):
9595
return result["access_token"], result["expires_in"]
9696

9797
def _authenticate_v1(self, endpoint, client_id, client_secret, audience):
98-
endpoint = endpoint or os.environ.get("SYPHT_AUTH_ENDPOINT", SYPHT_LEGACY_AUTH_ENDPOINT)
98+
endpoint = endpoint or os.environ.get(
99+
"SYPHT_AUTH_ENDPOINT", SYPHT_LEGACY_AUTH_ENDPOINT
100+
)
99101
result = self.requests.post(
100102
endpoint,
101103
data={
@@ -107,14 +109,19 @@ def _authenticate_v1(self, endpoint, client_id, client_secret, audience):
107109
).json()
108110

109111
if result.get("error_description"):
110-
raise Exception("Authentication failed: {}".format(result["error_description"]))
112+
raise Exception(
113+
"Authentication failed: {}".format(result["error_description"])
114+
)
111115

112116
return result["access_token"], result["expires_in"]
113117

114118
@staticmethod
115119
def _parse_response(response):
116120
if 200 <= response.status_code < 300:
117-
return response.json()
121+
try:
122+
return response.json()
123+
except json.decoder.JSONDecodeError:
124+
return response.text
118125
else:
119126
raise Exception(
120127
"Request failed with status code ({}): {}".format(
@@ -211,13 +218,17 @@ def upload(
211218

212219
if "fileId" not in result:
213220
raise Exception(
214-
"Upload failed with response: {}".format("\n" + json.dumps(result, indent=2))
221+
"Upload failed with response: {}".format(
222+
"\n" + json.dumps(result, indent=2)
223+
)
215224
)
216225

217226
return result["fileId"]
218227

219228
def run_workflow(self, workflow, inputs, step=None, endpoint=None, headers=None):
220-
endpoint = urljoin(endpoint or self.base_endpoint, f"workflows/{workflow}/invoke")
229+
endpoint = urljoin(
230+
endpoint or self.base_endpoint, f"workflows/{workflow}/invoke"
231+
)
221232
headers = headers or {}
222233
headers = self._get_headers(**headers)
223234
return self._parse_response(
@@ -237,19 +248,26 @@ def get_validation_rules(self, company_id=None, rules_id=None, endpoint=None):
237248
company_id = company_id or self.company_id
238249
endpoint = urljoin(
239250
endpoint or self.base_endpoint,
240-
f"workflows/rules/{company_id}/{rules_id}",
251+
f"workflows/{company_id}/rules/{rules_id}",
241252
)
242253
headers = self._get_headers()
243254
headers["Accept"] = "application/json"
244255
headers["Content-Type"] = "application/json"
245256
return self._parse_response(self.requests.get(endpoint, headers=headers))
246257

247-
def set_validation_rules(self, validation_rules=None, schema=True, company_id=None, rules_id=None, endpoint=None):
258+
def set_validation_rules(
259+
self,
260+
validation_rules=None,
261+
schema=True,
262+
company_id=None,
263+
rules_id=None,
264+
endpoint=None,
265+
):
248266
data = {"data": validation_rules, "schema": schema}
249267
company_id = company_id or self.company_id
250268
endpoint = urljoin(
251269
endpoint or self.base_endpoint,
252-
f"workflows/rules/{company_id}/{rules_id}",
270+
f"workflows/{company_id}/rules/{rules_id}",
253271
)
254272
headers = self._get_headers()
255273
headers["Accept"] = "application/json"
@@ -262,7 +280,43 @@ def delete_validation_rules(self, company_id=None, rules_id=None, endpoint=None)
262280
company_id = company_id or self.company_id
263281
endpoint = urljoin(
264282
endpoint or self.base_endpoint,
265-
f"workflows/rules/{company_id}/{rules_id}",
283+
f"workflows/{company_id}/rules/{rules_id}",
284+
)
285+
headers = self._get_headers()
286+
headers["Accept"] = "application/json"
287+
headers["Content-Type"] = "application/json"
288+
return self._parse_response(self.requests.delete(endpoint, headers=headers))
289+
290+
def get_workflow_data(self, company_id=None, data_key=None, endpoint=None):
291+
company_id = company_id or self.company_id
292+
endpoint = urljoin(
293+
endpoint or self.base_endpoint,
294+
f"workflows/{company_id}/data/{data_key}",
295+
)
296+
headers = self._get_headers()
297+
headers["Accept"] = "application/json"
298+
headers["Content-Type"] = "application/json"
299+
return self._parse_response(self.requests.get(endpoint, headers=headers))
300+
301+
def put_workflow_data(self, data, data_key, company_id=None, endpoint=None):
302+
data = {"data": data}
303+
company_id = company_id or self.company_id
304+
endpoint = urljoin(
305+
endpoint or self.base_endpoint,
306+
f"workflows/{company_id}/data/{data_key}",
307+
)
308+
headers = self._get_headers()
309+
headers["Accept"] = "application/json"
310+
headers["Content-Type"] = "application/json"
311+
return self._parse_response(
312+
self.requests.put(endpoint, data=json.dumps(data), headers=headers)
313+
)
314+
315+
def delete_workflow_data(self, rules_id=None, company_id=None, endpoint=None):
316+
company_id = company_id or self.company_id
317+
endpoint = urljoin(
318+
endpoint or self.base_endpoint,
319+
f"workflows/{company_id}/rules/{rules_id}",
266320
)
267321
headers = self._get_headers()
268322
headers["Accept"] = "application/json"
@@ -286,7 +340,9 @@ def get_file(self, file_id, endpoint=None, headers=None):
286340
return self._parse_response(self.requests.get(endpoint, headers=headers))
287341

288342
def get_file_data(self, file_id, endpoint=None, headers=None):
289-
endpoint = urljoin(endpoint or self.base_endpoint, f"app/docs/{file_id}/download")
343+
endpoint = urljoin(
344+
endpoint or self.base_endpoint, f"app/docs/{file_id}/download"
345+
)
290346
headers = headers or {}
291347
headers = self._get_headers(**headers)
292348
response = self.requests.get(endpoint, headers=headers)
@@ -355,9 +411,13 @@ def get_annotations_for_docs(self, doc_ids, endpoint=None):
355411
headers = self._get_headers()
356412
headers["Accept"] = "application/json"
357413
headers["Content-Type"] = "application/json"
358-
return self._parse_response(self.requests.post(endpoint, data=body, headers=headers))
414+
return self._parse_response(
415+
self.requests.post(endpoint, data=body, headers=headers)
416+
)
359417

360-
def set_company_annotations(self, doc_id, annotations, company_id=None, endpoint=None):
418+
def set_company_annotations(
419+
self, doc_id, annotations, company_id=None, endpoint=None
420+
):
361421
data = {
362422
"origin": "external",
363423
"fields": [
@@ -435,7 +495,9 @@ def set_files_for_tag(self, tag, file_ids, company_id=None, endpoint=None):
435495
headers["Accept"] = "application/json"
436496
headers["Content-Type"] = "application/json"
437497
return self._parse_response(
438-
self.requests.put(endpoint, data=json.dumps({"docs": file_ids}), headers=headers)
498+
self.requests.put(
499+
endpoint, data=json.dumps({"docs": file_ids}), headers=headers
500+
)
439501
)
440502

441503
def add_files_to_tag(self, tag, file_ids, company_id=None, endpoint=None):
@@ -448,7 +510,9 @@ def add_files_to_tag(self, tag, file_ids, company_id=None, endpoint=None):
448510
headers["Accept"] = "application/json"
449511
headers["Content-Type"] = "application/json"
450512
return self._parse_response(
451-
self.requests.patch(endpoint, data=json.dumps({"docs": file_ids}), headers=headers)
513+
self.requests.patch(
514+
endpoint, data=json.dumps({"docs": file_ids}), headers=headers
515+
)
452516
)
453517

454518
def remove_file_from_tag(self, file_id, tag, company_id=None, endpoint=None):
@@ -483,7 +547,9 @@ def set_tags_for_file(self, file_id, tags, company_id=None, endpoint=None):
483547
headers["Accept"] = "application/json"
484548
headers["Content-Type"] = "application/json"
485549
return self._parse_response(
486-
self.requests.put(endpoint, data=json.dumps({"tags": tags}), headers=headers)
550+
self.requests.put(
551+
endpoint, data=json.dumps({"tags": tags}), headers=headers
552+
)
487553
)
488554

489555
def add_tags_to_file(self, file_id, tags, company_id=None, endpoint=None):
@@ -496,7 +562,9 @@ def add_tags_to_file(self, file_id, tags, company_id=None, endpoint=None):
496562
headers["Accept"] = "application/json"
497563
headers["Content-Type"] = "application/json"
498564
return self._parse_response(
499-
self.requests.patch(endpoint, data=json.dumps({"tags": tags}), headers=headers)
565+
self.requests.patch(
566+
endpoint, data=json.dumps({"tags": tags}), headers=headers
567+
)
500568
)
501569

502570
def get_entity(self, entity_id, entity_type, company_id=None, endpoint=None):
@@ -540,7 +608,9 @@ def get_many_entities(self, entity_type, entities, company_id=None, endpoint=Non
540608
self.requests.post(endpoint, data=json.dumps(entities), headers=headers)
541609
)
542610

543-
def list_entities(self, entity_type, company_id=None, page=None, limit=None, endpoint=None):
611+
def list_entities(
612+
self, entity_type, company_id=None, page=None, limit=None, endpoint=None
613+
):
544614
"""Get list of entity_ids by pagination."""
545615
company_id = company_id or self.company_id
546616
entity_type = quote_plus(entity_type)
@@ -556,9 +626,13 @@ def list_entities(self, entity_type, company_id=None, page=None, limit=None, end
556626
params["page"] = page
557627
if limit:
558628
params["limit"] = int(limit)
559-
return self._parse_response(self.requests.get(endpoint, headers=headers, params=params))
629+
return self._parse_response(
630+
self.requests.get(endpoint, headers=headers, params=params)
631+
)
560632

561-
def get_all_entity_ids(self, entity_type, verbose=True, company_id=None, endpoint=None):
633+
def get_all_entity_ids(
634+
self, entity_type, verbose=True, company_id=None, endpoint=None
635+
):
562636
"""Get all entity_ids for specified entity_type.
563637
564638
Returns list of objects if verbose (by default):
@@ -641,7 +715,9 @@ def set_many_entities(
641715
for batch in _iter_chunked_sequence(entities, batch_size):
642716
responses.append(
643717
self._parse_response(
644-
self.requests.post(endpoint, data=json.dumps(batch), headers=headers)
718+
self.requests.post(
719+
endpoint, data=json.dumps(batch), headers=headers
720+
)
645721
)
646722
)
647723
return responses
@@ -674,7 +750,9 @@ def update_specification(self, specification, endpoint=None):
674750
headers["Accept"] = "application/json"
675751
headers["Content-Type"] = "application/json"
676752
return self._parse_response(
677-
self.requests.post(endpoint, data=json.dumps(specification), headers=headers)
753+
self.requests.post(
754+
endpoint, data=json.dumps(specification), headers=headers
755+
)
678756
)
679757

680758
def submit_task(

0 commit comments

Comments
 (0)