cecil 0.0.14__py3-none-any.whl → 0.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 cecil might be problematic. Click here for more details.
- cecil/__init__.py +1 -0
- cecil/client.py +26 -8
- cecil/errors.py +62 -0
- {cecil-0.0.14.dist-info → cecil-0.0.15.dist-info}/METADATA +1 -1
- cecil-0.0.15.dist-info/RECORD +8 -0
- cecil-0.0.14.dist-info/RECORD +0 -7
- {cecil-0.0.14.dist-info → cecil-0.0.15.dist-info}/WHEEL +0 -0
- {cecil-0.0.14.dist-info → cecil-0.0.15.dist-info}/licenses/LICENSE.txt +0 -0
cecil/__init__.py
CHANGED
cecil/client.py
CHANGED
|
@@ -6,6 +6,13 @@ import snowflake.connector
|
|
|
6
6
|
from pydantic import BaseModel
|
|
7
7
|
from requests import auth
|
|
8
8
|
|
|
9
|
+
from .errors import (
|
|
10
|
+
Error,
|
|
11
|
+
_handle_bad_request,
|
|
12
|
+
_handle_not_found,
|
|
13
|
+
_handle_unprocessable_entity,
|
|
14
|
+
)
|
|
15
|
+
|
|
9
16
|
from .models import (
|
|
10
17
|
AOI,
|
|
11
18
|
AOICreate,
|
|
@@ -21,7 +28,7 @@ from .models import (
|
|
|
21
28
|
)
|
|
22
29
|
|
|
23
30
|
# TODO: find a way to get this version from __about__.py
|
|
24
|
-
SDK_VERSION = "0.0.
|
|
31
|
+
SDK_VERSION = "0.0.15"
|
|
25
32
|
|
|
26
33
|
# TODO: Documentation (Google style)
|
|
27
34
|
# TODO: Add HTTP retries
|
|
@@ -135,14 +142,25 @@ class Client:
|
|
|
135
142
|
r.raise_for_status()
|
|
136
143
|
return r.json()
|
|
137
144
|
|
|
138
|
-
except requests.exceptions.ConnectionError
|
|
139
|
-
raise
|
|
145
|
+
except requests.exceptions.ConnectionError:
|
|
146
|
+
raise Error("failed to connect to the Cecil Platform")
|
|
140
147
|
except requests.exceptions.HTTPError as err:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
148
|
+
match err.response.status_code:
|
|
149
|
+
case 400:
|
|
150
|
+
_handle_bad_request(err.response)
|
|
151
|
+
case 401:
|
|
152
|
+
raise Error("unauthorised")
|
|
153
|
+
case 404:
|
|
154
|
+
_handle_not_found(err.response)
|
|
155
|
+
case 422:
|
|
156
|
+
_handle_unprocessable_entity(err.response)
|
|
157
|
+
case 500:
|
|
158
|
+
raise Error("internal server error")
|
|
159
|
+
case _:
|
|
160
|
+
raise Error(
|
|
161
|
+
f"request failed with code {err.response.status_code}",
|
|
162
|
+
err.response.text,
|
|
163
|
+
)
|
|
146
164
|
|
|
147
165
|
def _get(self, url: str, **kwargs) -> Dict:
|
|
148
166
|
return self._request(method="get", url=url, **kwargs)
|
cecil/errors.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Error(Exception):
|
|
5
|
+
def __init__(self, message: str, details=None):
|
|
6
|
+
self.message = message
|
|
7
|
+
self.details = details
|
|
8
|
+
|
|
9
|
+
if self.details is not None:
|
|
10
|
+
super().__init__(f"{self.message} \n{json.dumps(self.details, indent=2)}")
|
|
11
|
+
return
|
|
12
|
+
|
|
13
|
+
super().__init__(self.message)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _format_json_key(value: str):
|
|
17
|
+
return "".join(["_" + i.lower() if i.isupper() else i for i in value]).lstrip("_")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _is_json(value: str):
|
|
21
|
+
try:
|
|
22
|
+
json.loads(value)
|
|
23
|
+
return True
|
|
24
|
+
except ValueError:
|
|
25
|
+
return False
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _handle_bad_request(response):
|
|
29
|
+
if not _is_json(response.text):
|
|
30
|
+
raise Error("bad request")
|
|
31
|
+
|
|
32
|
+
details = {}
|
|
33
|
+
for key, value in response.json().items():
|
|
34
|
+
details[_format_json_key(key)] = value
|
|
35
|
+
|
|
36
|
+
raise Error("bad request", details)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _handle_not_found(response):
|
|
40
|
+
if not _is_json(response.text):
|
|
41
|
+
raise Error("resource not found")
|
|
42
|
+
|
|
43
|
+
details = {}
|
|
44
|
+
for key, value in response.json().items():
|
|
45
|
+
details[_format_json_key(key)] = value
|
|
46
|
+
|
|
47
|
+
raise Error("resource not found", details)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _handle_unprocessable_entity(response):
|
|
51
|
+
if not _is_json(response.text):
|
|
52
|
+
raise Error(f"failed to process request")
|
|
53
|
+
|
|
54
|
+
res_body = response.json()
|
|
55
|
+
if "params" not in res_body:
|
|
56
|
+
raise Error(f"failed to process request")
|
|
57
|
+
|
|
58
|
+
details = {}
|
|
59
|
+
for key, value in res_body["params"].items():
|
|
60
|
+
details[_format_json_key(key)] = value
|
|
61
|
+
|
|
62
|
+
raise Error(f"failed to process request", details)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
cecil/__init__.py,sha256=9-O5DAnOHvBuzPAjkK10GiOnCY9rb4SW1k0CIrHorr0,53
|
|
2
|
+
cecil/client.py,sha256=4ft1FL6KePfleTf-oepi10yRJ3RdVeZ0qNRdFyLm6c8,5783
|
|
3
|
+
cecil/errors.py,sha256=r9NNRtv_oO_hblnh-VOlAf767cJqmlnbJfHB63OA_zY,1538
|
|
4
|
+
cecil/models.py,sha256=6p9AedCDdkK-ptK2r5pc9AKG8rgZHw-YYDvRgXPAQqI,2544
|
|
5
|
+
cecil-0.0.15.dist-info/METADATA,sha256=wnQowxMqcWRjlNsThxwypFnck_TuDDFmNCzZr34_Y54,2677
|
|
6
|
+
cecil-0.0.15.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
7
|
+
cecil-0.0.15.dist-info/licenses/LICENSE.txt,sha256=mUexcmfYx3bG1VIzAdQTOf_NzStYw6-QkKVdUY_d4i4,1066
|
|
8
|
+
cecil-0.0.15.dist-info/RECORD,,
|
cecil-0.0.14.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
cecil/__init__.py,sha256=MF64bwUCd4sm3dvcxZnkb4ujHtxT_KeuXdD0nVieEt4,27
|
|
2
|
-
cecil/client.py,sha256=86TRdEGdxgO5nmoKpxdIIU6xeR9EjcOht7ZcKg7tInI,5237
|
|
3
|
-
cecil/models.py,sha256=6p9AedCDdkK-ptK2r5pc9AKG8rgZHw-YYDvRgXPAQqI,2544
|
|
4
|
-
cecil-0.0.14.dist-info/METADATA,sha256=xzTRj3FnDLmzk9pA11-YI3xBMMGKJ7p1e6rZlxO4YVw,2677
|
|
5
|
-
cecil-0.0.14.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
6
|
-
cecil-0.0.14.dist-info/licenses/LICENSE.txt,sha256=mUexcmfYx3bG1VIzAdQTOf_NzStYw6-QkKVdUY_d4i4,1066
|
|
7
|
-
cecil-0.0.14.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|