libentry 1.11.8__py3-none-any.whl → 1.11.10__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
@@ -217,7 +217,7 @@ class APIClient:
217
217
  path: str,
218
218
  num_trials: int = 5,
219
219
  retry_factor: float = 2,
220
- timeout: float = 5
220
+ timeout: float = 15
221
221
  ):
222
222
  api_url = urljoin(self.base_url, path)
223
223
  response = self._request(
@@ -248,7 +248,7 @@ class APIClient:
248
248
  exhaust_stream: bool = False,
249
249
  num_trials: int = 5,
250
250
  retry_factor: float = 2,
251
- timeout: float = 5,
251
+ timeout: float = 15,
252
252
  chunk_delimiter: str = "\n\n",
253
253
  chunk_prefix: str = None,
254
254
  chunk_suffix: str = None,
@@ -256,10 +256,8 @@ class APIClient:
256
256
  ):
257
257
  full_url = urljoin(self.base_url, path)
258
258
 
259
- headers = self.headers
260
- if stream:
261
- headers = {**headers}
262
- headers["Accept"] = headers["Accept"] + "-stream"
259
+ headers = {**self.headers}
260
+ headers["Accept"] = headers["Accept"] + f"; stream={int(stream)}"
263
261
  data = json.dumps(json_data) if json_data is not None else None
264
262
  response = self._request(
265
263
  "post",
libentry/service/flask.py CHANGED
@@ -6,6 +6,7 @@ __all__ = [
6
6
  ]
7
7
 
8
8
  import asyncio
9
+ import re
9
10
  import traceback
10
11
  from inspect import signature
11
12
  from types import GeneratorType
@@ -32,8 +33,8 @@ class JSONDumper:
32
33
  if self.api_info.stream_prefix is not None:
33
34
  yield self.api_info.stream_prefix
34
35
 
35
- if self.api_info.chunk_delimiter is not None:
36
- yield self.api_info.chunk_delimiter
36
+ if self.api_info.chunk_delimiter is not None:
37
+ yield self.api_info.chunk_delimiter
37
38
 
38
39
  try:
39
40
  it = iter(response)
@@ -59,6 +60,7 @@ class JSONDumper:
59
60
  except Exception as e:
60
61
  if isinstance(e, (SystemExit, KeyboardInterrupt)):
61
62
  raise e
63
+
62
64
  if self.api_info.error_prefix is not None:
63
65
  yield self.api_info.error_prefix
64
66
 
@@ -70,12 +72,15 @@ class JSONDumper:
70
72
  if self.api_info.stream_suffix is not None:
71
73
  yield self.api_info.stream_suffix
72
74
 
73
- if self.api_info.chunk_delimiter is not None:
74
- yield self.api_info.chunk_delimiter
75
+ if self.api_info.chunk_delimiter is not None:
76
+ yield self.api_info.chunk_delimiter
75
77
 
76
78
  if return_value is not None:
77
79
  yield self.dump(return_value)
78
80
 
81
+ if self.api_info.chunk_delimiter is not None:
82
+ yield self.api_info.chunk_delimiter
83
+
79
84
  @staticmethod
80
85
  def dump(response) -> str:
81
86
  if response is None:
@@ -144,9 +149,6 @@ class FlaskWrapper:
144
149
  self.input_schema = value.annotation
145
150
 
146
151
  def __call__(self):
147
- print("*" * 10)
148
- print(request.headers)
149
- print("*" * 10)
150
152
  if request.method == "POST":
151
153
  input_json = json.loads(request.data) if request.data else {}
152
154
  elif request.method == "GET":
@@ -170,30 +172,50 @@ class FlaskWrapper:
170
172
  raise e
171
173
  return self.app.error(self.dumper.dump_error(e))
172
174
 
173
- stream = request.headers.get("Accept", "").endswith("-stream")
174
- if stream:
175
- if not isinstance(response, (GeneratorType, range)):
176
- response = [response]
177
- return self.app.ok(
178
- self.dumper.dump_stream(response),
179
- mimetype=self.api_info.mime_type
180
- )
175
+ stream = None
176
+ accept = request.headers.get("Accept", "")
177
+ for param in accept.split(";"):
178
+ match = re.search(r"^\s*stream=(.+)$", param)
179
+ if match:
180
+ stream = match.group(1)
181
+ stream = stream in {"1", "true", "True"}
182
+ break
183
+
184
+ if stream is not None:
185
+ if stream:
186
+ if not isinstance(response, (GeneratorType, range)):
187
+ response = [response]
188
+ return self.app.ok(
189
+ self.dumper.dump_stream(response),
190
+ mimetype=self.api_info.mime_type
191
+ )
192
+ else:
193
+ if isinstance(response, (GeneratorType, range)):
194
+ output = []
195
+ it = iter(response)
196
+ while True:
197
+ try:
198
+ output.append(next(it))
199
+ except StopIteration as e:
200
+ if e.value is not None:
201
+ output.append(e.value)
202
+ break
203
+ response = output
204
+ return self.app.ok(
205
+ self.dumper.dump(response),
206
+ mimetype=self.api_info.mime_type
207
+ )
181
208
  else:
182
209
  if isinstance(response, (GeneratorType, range)):
183
- output = []
184
- it = iter(response)
185
- while True:
186
- try:
187
- output.append(next(it))
188
- except StopIteration as e:
189
- if e.value is not None:
190
- output.append(e.value)
191
- break
192
- response = output
193
- return self.app.ok(
194
- self.dumper.dump(response),
195
- mimetype=self.api_info.mime_type
196
- )
210
+ return self.app.ok(
211
+ self.dumper.dump_stream(response),
212
+ mimetype=self.api_info.mime_type
213
+ )
214
+ else:
215
+ return self.app.ok(
216
+ self.dumper.dump(response),
217
+ mimetype=self.api_info.mime_type
218
+ )
197
219
 
198
220
 
199
221
  class CustomGenerateJsonSchema(GenerateJsonSchema):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libentry
3
- Version: 1.11.8
3
+ Version: 1.11.10
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=arv2CfcZA3XfwyNh_V2NZD16_GIKGSPliwPgvdPjIuk,10066
2
+ libentry/api.py,sha256=BWPeeHEgExWt0NOejH6v76baDLv4OxMoBqi1KsdaDeU,10031
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
@@ -10,14 +10,14 @@ libentry/server.py,sha256=gYPoZXd0umlDYZf-6ZV0_vJadg3YQvnLDc6JFDJh9jc,1503
10
10
  libentry/start_service.py,sha256=Mm0HRwikW1KcDsnkK_Jo2QlNqe5BBBgMqtGd9jZxX1o,1902
11
11
  libentry/service/__init__.py,sha256=1oLL20yLB1GL9IbFiZD8OReDqiCpFr-yetIR6x1cNkI,23
12
12
  libentry/service/common.py,sha256=OVaW2afgKA6YqstJmtnprBCqQEUZEWotZ6tHavmJJeU,42
13
- libentry/service/flask.py,sha256=A8BJ4EMgRLwOVknnhuQYaceCEONcIl5RQnTQ2Q1qyW8,10809
13
+ libentry/service/flask.py,sha256=x3R_DJElxxWkuaO4zY5A0ze0y5diUgsfHMwsyvMKtnE,11643
14
14
  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.11.8.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
19
- libentry-1.11.8.dist-info/METADATA,sha256=6FeQU10fPl7lFCmX6l1P5754bnaiFBUbeqPw1d7bXwU,500
20
- libentry-1.11.8.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
21
- libentry-1.11.8.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
22
- libentry-1.11.8.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
23
- libentry-1.11.8.dist-info/RECORD,,
18
+ libentry-1.11.10.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
19
+ libentry-1.11.10.dist-info/METADATA,sha256=07AZ2hkh4xxZEaN9Yz5eun-_SnfttEcmAGWarWJWxXY,501
20
+ libentry-1.11.10.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
21
+ libentry-1.11.10.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
22
+ libentry-1.11.10.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
23
+ libentry-1.11.10.dist-info/RECORD,,