libentry 1.11.1__py3-none-any.whl → 1.11.3__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.
- libentry/api.py +41 -49
- {libentry-1.11.1.dist-info → libentry-1.11.3.dist-info}/METADATA +1 -1
- {libentry-1.11.1.dist-info → libentry-1.11.3.dist-info}/RECORD +7 -7
- {libentry-1.11.1.dist-info → libentry-1.11.3.dist-info}/LICENSE +0 -0
- {libentry-1.11.1.dist-info → libentry-1.11.3.dist-info}/WHEEL +0 -0
- {libentry-1.11.1.dist-info → libentry-1.11.3.dist-info}/top_level.txt +0 -0
- {libentry-1.11.1.dist-info → libentry-1.11.3.dist-info}/zip-safe +0 -0
libentry/api.py
CHANGED
@@ -12,10 +12,9 @@ __all__ = [
|
|
12
12
|
|
13
13
|
import os
|
14
14
|
from dataclasses import dataclass, field
|
15
|
-
from typing import Any, Callable, Iterable, List, Literal, Mapping, Optional, Tuple
|
15
|
+
from typing import Any, Callable, Iterable, List, Literal, Mapping, Optional, Tuple
|
16
16
|
|
17
17
|
import requests
|
18
|
-
from pydantic import BaseModel
|
19
18
|
|
20
19
|
from libentry import json
|
21
20
|
|
@@ -129,15 +128,40 @@ def list_api_info(obj) -> List[Tuple[Callable, APIInfo]]:
|
|
129
128
|
return api_list
|
130
129
|
|
131
130
|
|
131
|
+
def _load_json_or_str(text: str):
|
132
|
+
try:
|
133
|
+
return json.loads(text)
|
134
|
+
except ValueError:
|
135
|
+
return text
|
136
|
+
|
137
|
+
|
132
138
|
class ServiceError(RuntimeError):
|
133
139
|
|
134
|
-
def __init__(self,
|
135
|
-
|
136
|
-
|
137
|
-
|
140
|
+
def __init__(self, text: str):
|
141
|
+
err = _load_json_or_str(text)
|
142
|
+
if isinstance(err, dict):
|
143
|
+
if "message" in err:
|
144
|
+
self.message = err.get("message")
|
145
|
+
self.error = err.get("error")
|
146
|
+
self.traceback = err.get("traceback")
|
147
|
+
else:
|
148
|
+
self.message = str(err)
|
149
|
+
self.error = ""
|
150
|
+
self.traceback = None
|
151
|
+
else:
|
152
|
+
self.message = err
|
153
|
+
self.error = ""
|
154
|
+
self.traceback = None
|
138
155
|
|
139
156
|
def __str__(self):
|
140
|
-
|
157
|
+
lines = []
|
158
|
+
if self.message:
|
159
|
+
lines += [self.message, "\n\n"]
|
160
|
+
if self.error:
|
161
|
+
lines += ["This is caused by server side error ", self.error, ".\n"]
|
162
|
+
if self.traceback:
|
163
|
+
lines += ["Below is the stacktrace:\n", self.traceback.rstrip()]
|
164
|
+
return "".join(lines)
|
141
165
|
|
142
166
|
|
143
167
|
class APIClient:
|
@@ -170,21 +194,19 @@ class APIClient:
|
|
170
194
|
response = requests.get(api_url, headers=self.headers, verify=self.verify, timeout=timeout)
|
171
195
|
|
172
196
|
if response.status_code != 200:
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
else:
|
177
|
-
raise ServiceError(str(err), "UnknownError", "")
|
197
|
+
text = response.text
|
198
|
+
response.close()
|
199
|
+
raise ServiceError(text)
|
178
200
|
|
179
201
|
try:
|
180
|
-
return
|
202
|
+
return _load_json_or_str(response.text)
|
181
203
|
finally:
|
182
204
|
response.close()
|
183
205
|
|
184
206
|
def post(
|
185
207
|
self,
|
186
208
|
path: str,
|
187
|
-
json_data: Mapping = None,
|
209
|
+
json_data: Optional[Mapping] = None,
|
188
210
|
stream=False,
|
189
211
|
timeout=60,
|
190
212
|
chunk_delimiter: str = "\n\n",
|
@@ -203,11 +225,9 @@ class APIClient:
|
|
203
225
|
timeout=timeout
|
204
226
|
)
|
205
227
|
if response.status_code != 200:
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
else:
|
210
|
-
raise ServiceError(str(err), "UnknownError", "")
|
228
|
+
text = response.text
|
229
|
+
response.close()
|
230
|
+
raise ServiceError(text)
|
211
231
|
|
212
232
|
if stream:
|
213
233
|
if chunk_delimiter is None:
|
@@ -222,7 +242,7 @@ class APIClient:
|
|
222
242
|
)
|
223
243
|
else:
|
224
244
|
try:
|
225
|
-
return
|
245
|
+
return _load_json_or_str(response.text)
|
226
246
|
finally:
|
227
247
|
response.close()
|
228
248
|
|
@@ -250,34 +270,6 @@ class APIClient:
|
|
250
270
|
else:
|
251
271
|
continue
|
252
272
|
|
253
|
-
yield
|
273
|
+
yield _load_json_or_str(chunk)
|
254
274
|
finally:
|
255
275
|
response.close()
|
256
|
-
|
257
|
-
@staticmethod
|
258
|
-
def _load_json(text: str):
|
259
|
-
try:
|
260
|
-
return json.loads(text)
|
261
|
-
except ValueError:
|
262
|
-
return text
|
263
|
-
|
264
|
-
def __getattr__(self, item: str):
|
265
|
-
return MethodProxy(self, item)
|
266
|
-
|
267
|
-
|
268
|
-
class MethodProxy:
|
269
|
-
|
270
|
-
def __init__(self, client: APIClient, url: str):
|
271
|
-
self.client = client
|
272
|
-
self.url = url
|
273
|
-
|
274
|
-
def __call__(self, request: Optional[Union[Mapping, BaseModel]] = None, **kwargs):
|
275
|
-
if request is None:
|
276
|
-
request = kwargs
|
277
|
-
elif isinstance(request, BaseModel):
|
278
|
-
request = request.model_dump()
|
279
|
-
for k, v in kwargs.items():
|
280
|
-
if isinstance(v, BaseModel):
|
281
|
-
v = v.model_dump()
|
282
|
-
request[k] = v
|
283
|
-
return self.client.post(self.url, request)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
libentry/__init__.py,sha256=rDBip9M1Xb1N4wMKE1ni_DldrQbkRjp8DxPkTp3K2qo,170
|
2
|
-
libentry/api.py,sha256=
|
2
|
+
libentry/api.py,sha256=m0j9aGPD4ewJdeQkooUoNJeTbrAtqlpSscmy3gfOTYw,7921
|
3
3
|
libentry/argparse.py,sha256=Bk11H4WRKxcjMlSd0mjWj1T4NWh0JW5eA7TX3C21IoE,10116
|
4
4
|
libentry/dataclasses.py,sha256=AQV2PuxplJCwGZ5HKX72U-z-POUhTdy3XtpEK9KNIGQ,4541
|
5
5
|
libentry/executor.py,sha256=cTV0WxJi0nU1TP-cOwmeodN8DD6L1691M2HIQsJtGrU,6582
|
@@ -14,9 +14,9 @@ libentry/service/list.py,sha256=ElHWhTgShGOhaxMUEwVbMXos0NQKjHsODboiQ-3AMwE,1397
|
|
14
14
|
libentry/service/running.py,sha256=FrPJoJX6wYxcHIysoatAxhW3LajCCm0Gx6l7__6sULQ,5105
|
15
15
|
libentry/service/start.py,sha256=mZT7b9rVULvzy9GTZwxWnciCHgv9dbGN2JbxM60OMn4,1270
|
16
16
|
libentry/service/stop.py,sha256=wOpwZgrEJ7QirntfvibGq-XsTC6b3ELhzRW2zezh-0s,1187
|
17
|
-
libentry-1.11.
|
18
|
-
libentry-1.11.
|
19
|
-
libentry-1.11.
|
20
|
-
libentry-1.11.
|
21
|
-
libentry-1.11.
|
22
|
-
libentry-1.11.
|
17
|
+
libentry-1.11.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
18
|
+
libentry-1.11.3.dist-info/METADATA,sha256=oNzYKmc3HwT6ZGKaT-EHVKzEGj99lYQJvXQmNVVJDkc,500
|
19
|
+
libentry-1.11.3.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
|
20
|
+
libentry-1.11.3.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
|
21
|
+
libentry-1.11.3.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
22
|
+
libentry-1.11.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|