Skip to content

Commit bb59e12

Browse files
author
wilmeryan
committed
blackify
1 parent 1109cf5 commit bb59e12

File tree

1 file changed

+19
-51
lines changed

1 file changed

+19
-51
lines changed

sypht/client.py

Lines changed: 19 additions & 51 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(
79-
(client_id + ":" + client_secret).encode("utf-8")
80-
).decode("utf-8")
78+
basic_auth_slug = b64encode((client_id + ":" + client_secret).encode("utf-8")).decode(
79+
"utf-8"
80+
)
8181
result = self.requests.post(
8282
endpoint,
8383
headers={
@@ -95,9 +95,7 @@ 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(
99-
"SYPHT_AUTH_ENDPOINT", SYPHT_LEGACY_AUTH_ENDPOINT
100-
)
98+
endpoint = endpoint or os.environ.get("SYPHT_AUTH_ENDPOINT", SYPHT_LEGACY_AUTH_ENDPOINT)
10199
result = self.requests.post(
102100
endpoint,
103101
data={
@@ -109,9 +107,7 @@ def _authenticate_v1(self, endpoint, client_id, client_secret, audience):
109107
).json()
110108

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

116112
return result["access_token"], result["expires_in"]
117113

@@ -218,17 +214,13 @@ def upload(
218214

219215
if "fileId" not in result:
220216
raise Exception(
221-
"Upload failed with response: {}".format(
222-
"\n" + json.dumps(result, indent=2)
223-
)
217+
"Upload failed with response: {}".format("\n" + json.dumps(result, indent=2))
224218
)
225219

226220
return result["fileId"]
227221

228222
def run_workflow(self, workflow, inputs, step=None, endpoint=None, headers=None):
229-
endpoint = urljoin(
230-
endpoint or self.base_endpoint, f"workflows/{workflow}/invoke"
231-
)
223+
endpoint = urljoin(endpoint or self.base_endpoint, f"workflows/{workflow}/invoke")
232224
headers = headers or {}
233225
headers = self._get_headers(**headers)
234226
return self._parse_response(
@@ -340,9 +332,7 @@ def get_file(self, file_id, endpoint=None, headers=None):
340332
return self._parse_response(self.requests.get(endpoint, headers=headers))
341333

342334
def get_file_data(self, file_id, endpoint=None, headers=None):
343-
endpoint = urljoin(
344-
endpoint or self.base_endpoint, f"app/docs/{file_id}/download"
345-
)
335+
endpoint = urljoin(endpoint or self.base_endpoint, f"app/docs/{file_id}/download")
346336
headers = headers or {}
347337
headers = self._get_headers(**headers)
348338
response = self.requests.get(endpoint, headers=headers)
@@ -411,13 +401,9 @@ def get_annotations_for_docs(self, doc_ids, endpoint=None):
411401
headers = self._get_headers()
412402
headers["Accept"] = "application/json"
413403
headers["Content-Type"] = "application/json"
414-
return self._parse_response(
415-
self.requests.post(endpoint, data=body, headers=headers)
416-
)
404+
return self._parse_response(self.requests.post(endpoint, data=body, headers=headers))
417405

418-
def set_company_annotations(
419-
self, doc_id, annotations, company_id=None, endpoint=None
420-
):
406+
def set_company_annotations(self, doc_id, annotations, company_id=None, endpoint=None):
421407
data = {
422408
"origin": "external",
423409
"fields": [
@@ -495,9 +481,7 @@ def set_files_for_tag(self, tag, file_ids, company_id=None, endpoint=None):
495481
headers["Accept"] = "application/json"
496482
headers["Content-Type"] = "application/json"
497483
return self._parse_response(
498-
self.requests.put(
499-
endpoint, data=json.dumps({"docs": file_ids}), headers=headers
500-
)
484+
self.requests.put(endpoint, data=json.dumps({"docs": file_ids}), headers=headers)
501485
)
502486

503487
def add_files_to_tag(self, tag, file_ids, company_id=None, endpoint=None):
@@ -510,9 +494,7 @@ def add_files_to_tag(self, tag, file_ids, company_id=None, endpoint=None):
510494
headers["Accept"] = "application/json"
511495
headers["Content-Type"] = "application/json"
512496
return self._parse_response(
513-
self.requests.patch(
514-
endpoint, data=json.dumps({"docs": file_ids}), headers=headers
515-
)
497+
self.requests.patch(endpoint, data=json.dumps({"docs": file_ids}), headers=headers)
516498
)
517499

518500
def remove_file_from_tag(self, file_id, tag, company_id=None, endpoint=None):
@@ -547,9 +529,7 @@ def set_tags_for_file(self, file_id, tags, company_id=None, endpoint=None):
547529
headers["Accept"] = "application/json"
548530
headers["Content-Type"] = "application/json"
549531
return self._parse_response(
550-
self.requests.put(
551-
endpoint, data=json.dumps({"tags": tags}), headers=headers
552-
)
532+
self.requests.put(endpoint, data=json.dumps({"tags": tags}), headers=headers)
553533
)
554534

555535
def add_tags_to_file(self, file_id, tags, company_id=None, endpoint=None):
@@ -562,9 +542,7 @@ def add_tags_to_file(self, file_id, tags, company_id=None, endpoint=None):
562542
headers["Accept"] = "application/json"
563543
headers["Content-Type"] = "application/json"
564544
return self._parse_response(
565-
self.requests.patch(
566-
endpoint, data=json.dumps({"tags": tags}), headers=headers
567-
)
545+
self.requests.patch(endpoint, data=json.dumps({"tags": tags}), headers=headers)
568546
)
569547

570548
def get_entity(self, entity_id, entity_type, company_id=None, endpoint=None):
@@ -608,9 +586,7 @@ def get_many_entities(self, entity_type, entities, company_id=None, endpoint=Non
608586
self.requests.post(endpoint, data=json.dumps(entities), headers=headers)
609587
)
610588

611-
def list_entities(
612-
self, entity_type, company_id=None, page=None, limit=None, endpoint=None
613-
):
589+
def list_entities(self, entity_type, company_id=None, page=None, limit=None, endpoint=None):
614590
"""Get list of entity_ids by pagination."""
615591
company_id = company_id or self.company_id
616592
entity_type = quote_plus(entity_type)
@@ -626,13 +602,9 @@ def list_entities(
626602
params["page"] = page
627603
if limit:
628604
params["limit"] = int(limit)
629-
return self._parse_response(
630-
self.requests.get(endpoint, headers=headers, params=params)
631-
)
605+
return self._parse_response(self.requests.get(endpoint, headers=headers, params=params))
632606

633-
def get_all_entity_ids(
634-
self, entity_type, verbose=True, company_id=None, endpoint=None
635-
):
607+
def get_all_entity_ids(self, entity_type, verbose=True, company_id=None, endpoint=None):
636608
"""Get all entity_ids for specified entity_type.
637609
638610
Returns list of objects if verbose (by default):
@@ -715,9 +687,7 @@ def set_many_entities(
715687
for batch in _iter_chunked_sequence(entities, batch_size):
716688
responses.append(
717689
self._parse_response(
718-
self.requests.post(
719-
endpoint, data=json.dumps(batch), headers=headers
720-
)
690+
self.requests.post(endpoint, data=json.dumps(batch), headers=headers)
721691
)
722692
)
723693
return responses
@@ -750,9 +720,7 @@ def update_specification(self, specification, endpoint=None):
750720
headers["Accept"] = "application/json"
751721
headers["Content-Type"] = "application/json"
752722
return self._parse_response(
753-
self.requests.post(
754-
endpoint, data=json.dumps(specification), headers=headers
755-
)
723+
self.requests.post(endpoint, data=json.dumps(specification), headers=headers)
756724
)
757725

758726
def submit_task(

0 commit comments

Comments
 (0)