libentry 1.17__py3-none-any.whl → 1.18__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 CHANGED
@@ -166,6 +166,9 @@ class ServiceError(RuntimeError):
166
166
  return "".join(lines)
167
167
 
168
168
 
169
+ ErrorCallback = Callable[[Exception], None]
170
+
171
+
169
172
  class APIClient:
170
173
 
171
174
  def __init__(
@@ -195,29 +198,41 @@ class APIClient:
195
198
  self,
196
199
  method: str,
197
200
  url: str,
198
- num_trials: int = 5,
199
- retry_factor: float = 2,
200
- timeout: float = 5,
201
+ num_trials: int,
202
+ timeout: float,
203
+ interval: float,
204
+ retry_factor: float,
205
+ on_error: Optional[ErrorCallback] = None,
201
206
  **kwargs
202
207
  ):
203
208
  err = None
204
- for _ in range(num_trials):
209
+ for i in range(num_trials):
205
210
  try:
206
- return requests.request(method, url, timeout=timeout, **kwargs)
211
+ return requests.request(
212
+ method=method,
213
+ url=url,
214
+ timeout=timeout * (1 + i * retry_factor),
215
+ **kwargs
216
+ )
207
217
  except requests.Timeout as e:
208
218
  err = e
219
+ if callable(on_error):
220
+ on_error(e)
209
221
  except requests.ConnectionError as e:
210
222
  err = e
211
- sleep(timeout)
212
- timeout *= retry_factor
223
+ if callable(on_error):
224
+ on_error(e)
225
+ sleep(interval)
213
226
  raise err
214
227
 
215
228
  def get(
216
229
  self,
217
230
  path: Optional[str] = None, *,
218
231
  num_trials: int = 5,
219
- retry_factor: float = 2,
220
- timeout: float = 15
232
+ timeout: float = 15,
233
+ interval: float = 1,
234
+ retry_factor: float = 0.5,
235
+ on_error: Optional[ErrorCallback] = None
221
236
  ):
222
237
  full_url = urljoin(self.base_url, path)
223
238
  response = self._request(
@@ -226,8 +241,10 @@ class APIClient:
226
241
  headers=self.headers,
227
242
  verify=self.verify,
228
243
  num_trials=num_trials,
244
+ timeout=timeout,
245
+ interval=interval,
229
246
  retry_factor=retry_factor,
230
- timeout=timeout
247
+ on_error=on_error
231
248
  )
232
249
 
233
250
  if response.status_code != 200:
@@ -247,8 +264,10 @@ class APIClient:
247
264
  stream: bool = False,
248
265
  exhaust_stream: bool = False,
249
266
  num_trials: int = 5,
250
- retry_factor: float = 2,
251
267
  timeout: float = 15,
268
+ interval: float = 1,
269
+ retry_factor: float = 0.5,
270
+ on_error: Optional[ErrorCallback] = None,
252
271
  chunk_delimiter: str = "\n\n",
253
272
  chunk_prefix: str = None,
254
273
  chunk_suffix: str = None,
@@ -267,8 +286,10 @@ class APIClient:
267
286
  verify=self.verify,
268
287
  stream=stream,
269
288
  num_trials=num_trials,
289
+ timeout=timeout,
290
+ interval=interval,
270
291
  retry_factor=retry_factor,
271
- timeout=timeout
292
+ on_error=on_error
272
293
  )
273
294
  if response.status_code != 200:
274
295
  text = response.text
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libentry
3
- Version: 1.17
3
+ Version: 1.18
4
4
  Summary: Entries for experimental utilities.
5
5
  Home-page: https://github.com/XoriieInpottn/libentry
6
6
  Author: xi
@@ -1,5 +1,5 @@
1
1
  libentry/__init__.py,sha256=rDBip9M1Xb1N4wMKE1ni_DldrQbkRjp8DxPkTp3K2qo,170
2
- libentry/api.py,sha256=zvW4YugZ7k0wmVVFTnOYHgNqWQPf8zTTPYOnED-iUJM,10097
2
+ libentry/api.py,sha256=LqTa8T8Oh8z5BybzrgtdC0HhMXWL2-DZPdOdBHb6Vl0,10753
3
3
  libentry/argparse.py,sha256=NxzXV-jBN51ReZsNs5aeyOfzwYQ5A5nJ95rWoa-FYCs,10415
4
4
  libentry/dataclasses.py,sha256=AQV2PuxplJCwGZ5HKX72U-z-POUhTdy3XtpEK9KNIGQ,4541
5
5
  libentry/executor.py,sha256=cTV0WxJi0nU1TP-cOwmeodN8DD6L1691M2HIQsJtGrU,6582
@@ -15,9 +15,9 @@ libentry/service/list.py,sha256=ElHWhTgShGOhaxMUEwVbMXos0NQKjHsODboiQ-3AMwE,1397
15
15
  libentry/service/running.py,sha256=FrPJoJX6wYxcHIysoatAxhW3LajCCm0Gx6l7__6sULQ,5105
16
16
  libentry/service/start.py,sha256=mZT7b9rVULvzy9GTZwxWnciCHgv9dbGN2JbxM60OMn4,1270
17
17
  libentry/service/stop.py,sha256=wOpwZgrEJ7QirntfvibGq-XsTC6b3ELhzRW2zezh-0s,1187
18
- libentry-1.17.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
19
- libentry-1.17.dist-info/METADATA,sha256=6kVrTOffjfB4RzkedsLggG0DVy8la9fIx2c3iP7cuAw,791
20
- libentry-1.17.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
21
- libentry-1.17.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
22
- libentry-1.17.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
23
- libentry-1.17.dist-info/RECORD,,
18
+ libentry-1.18.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
19
+ libentry-1.18.dist-info/METADATA,sha256=3LKED9qfL_-_CvMdtfNW2YnoK1LBDdnQxN7Bf2_ZsKE,791
20
+ libentry-1.18.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
21
+ libentry-1.18.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
22
+ libentry-1.18.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
23
+ libentry-1.18.dist-info/RECORD,,