omlish 0.0.0.dev469__py3-none-any.whl → 0.0.0.dev470__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.
omlish/__about__.py CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev469'
2
- __revision__ = 'efea836fe350fa24e6b724d30d414b2d87ee1341'
1
+ __version__ = '0.0.0.dev470'
2
+ __revision__ = '967906fd30a40d061ede9f7aeda9dad0ec608508'
3
3
 
4
4
 
5
5
  #
omlish/http/all.py CHANGED
@@ -7,16 +7,15 @@ with _lang.auto_proxy_init(globals()):
7
7
  from .clients.asyncs import ( # noqa
8
8
  AsyncStreamHttpResponse,
9
9
 
10
- async_close_response,
11
- async_closing_response,
12
- async_read_response,
10
+ async_close_http_client_response,
11
+ async_closing_http_client_response,
12
+ async_read_http_client_response,
13
13
 
14
14
  AsyncHttpClient,
15
15
  )
16
16
 
17
17
  from .clients.base import ( # noqa
18
18
  DEFAULT_ENCODING,
19
-
20
19
  is_success_status,
21
20
 
22
21
  HttpRequest,
@@ -24,8 +23,12 @@ with _lang.auto_proxy_init(globals()):
24
23
  BaseHttpResponse,
25
24
  HttpResponse,
26
25
 
26
+ HttpClientContext,
27
+
27
28
  HttpClientError,
28
29
  HttpStatusError,
30
+
31
+ BaseHttpClient,
29
32
  )
30
33
 
31
34
  from .clients.default import ( # noqa
@@ -42,18 +45,35 @@ with _lang.auto_proxy_init(globals()):
42
45
 
43
46
  from .clients.httpx import ( # noqa
44
47
  HttpxHttpClient,
48
+
49
+ HttpxAsyncHttpClient,
50
+ )
51
+
52
+ from .clients.middleware import ( # noqa
53
+ HttpClientMiddleware,
54
+ AbstractMiddlewareHttpClient,
55
+
56
+ MiddlewareHttpClient,
57
+ MiddlewareAsyncHttpClient,
58
+
59
+ TooManyRedirectsHttpClientError,
60
+ RedirectHandlingHttpClientMiddleware,
45
61
  )
46
62
 
47
63
  from .clients.sync import ( # noqa
48
64
  StreamHttpResponse,
49
65
 
50
- close_response,
51
- closing_response,
52
- read_response,
66
+ close_http_client_response,
67
+ closing_http_client_response,
68
+ read_http_client_response,
53
69
 
54
70
  HttpClient,
55
71
  )
56
72
 
73
+ from .clients.syncasync import ( # noqa
74
+ SyncAsyncHttpClient,
75
+ )
76
+
57
77
  from .clients.urllib import ( # noqa
58
78
  UrllibHttpClient,
59
79
  )
@@ -57,13 +57,13 @@ class AsyncStreamHttpResponse(BaseHttpResponse):
57
57
 
58
58
  async def close(self) -> None:
59
59
  if (c := self._closer) is not None:
60
- await c()
60
+ await c() # noqa
61
61
 
62
62
 
63
63
  #
64
64
 
65
65
 
66
- async def async_close_response(resp: BaseHttpResponse) -> None:
66
+ async def async_close_http_client_response(resp: BaseHttpResponse) -> None:
67
67
  if isinstance(resp, HttpResponse):
68
68
  pass
69
69
 
@@ -75,7 +75,7 @@ async def async_close_response(resp: BaseHttpResponse) -> None:
75
75
 
76
76
 
77
77
  @contextlib.asynccontextmanager
78
- async def async_closing_response(resp: BaseHttpResponseT) -> ta.AsyncGenerator[BaseHttpResponseT, None]:
78
+ async def async_closing_http_client_response(resp: BaseHttpResponseT) -> ta.AsyncGenerator[BaseHttpResponseT, None]:
79
79
  if isinstance(resp, HttpResponse):
80
80
  yield resp
81
81
  return
@@ -90,7 +90,7 @@ async def async_closing_response(resp: BaseHttpResponseT) -> ta.AsyncGenerator[B
90
90
  raise TypeError(resp)
91
91
 
92
92
 
93
- async def async_read_response(resp: BaseHttpResponse) -> HttpResponse:
93
+ async def async_read_http_client_response(resp: BaseHttpResponse) -> HttpResponse:
94
94
  if isinstance(resp, HttpResponse):
95
95
  return resp
96
96
 
@@ -121,12 +121,12 @@ class AsyncHttpClient(BaseHttpClient, Abstract):
121
121
  context: ta.Optional[HttpClientContext] = None,
122
122
  check: bool = False,
123
123
  ) -> HttpResponse:
124
- async with async_closing_response(await self.stream_request(
124
+ async with async_closing_http_client_response(await self.stream_request(
125
125
  req,
126
126
  context=context,
127
127
  check=check,
128
128
  )) as resp:
129
- return await async_read_response(resp)
129
+ return await async_read_http_client_response(resp)
130
130
 
131
131
  async def stream_request(
132
132
  self,
@@ -146,10 +146,10 @@ class AsyncHttpClient(BaseHttpClient, Abstract):
146
146
  cause = resp.underlying
147
147
  else:
148
148
  cause = None
149
- raise HttpStatusError(await async_read_response(resp)) from cause # noqa
149
+ raise HttpStatusError(await async_read_http_client_response(resp)) from cause # noqa
150
150
 
151
151
  except Exception:
152
- await async_close_response(resp)
152
+ await async_close_http_client_response(resp)
153
153
  raise
154
154
 
155
155
  return resp
@@ -23,7 +23,7 @@ from .base import HttpClientError
23
23
  from .base import HttpRequest
24
24
  from .sync import HttpClient
25
25
  from .sync import StreamHttpResponse
26
- from .sync import close_response
26
+ from .sync import close_http_client_response
27
27
 
28
28
 
29
29
  BaseHttpClientT = ta.TypeVar('BaseHttpClientT', bound=BaseHttpClient)
@@ -84,6 +84,9 @@ class AbstractMiddlewareHttpClient(Abstract, ta.Generic[BaseHttpClientT]):
84
84
  return resp
85
85
 
86
86
 
87
+ #
88
+
89
+
87
90
  class MiddlewareHttpClient(AbstractMiddlewareHttpClient[HttpClient], HttpClient):
88
91
  def _stream_request(self, ctx: HttpClientContext, req: HttpRequest) -> StreamHttpResponse:
89
92
  while True:
@@ -95,7 +98,7 @@ class MiddlewareHttpClient(AbstractMiddlewareHttpClient[HttpClient], HttpClient)
95
98
  out = self._process_response(ctx, req, resp)
96
99
 
97
100
  if isinstance(out, HttpRequest):
98
- close_response(resp)
101
+ close_http_client_response(resp)
99
102
  req = out
100
103
  continue
101
104
 
@@ -106,7 +109,7 @@ class MiddlewareHttpClient(AbstractMiddlewareHttpClient[HttpClient], HttpClient)
106
109
  raise TypeError(out) # noqa
107
110
 
108
111
  except Exception:
109
- close_response(resp)
112
+ close_http_client_response(resp)
110
113
  raise
111
114
 
112
115
  raise RuntimeError
@@ -57,13 +57,13 @@ class StreamHttpResponse(BaseHttpResponse):
57
57
 
58
58
  def close(self) -> None:
59
59
  if (c := self._closer) is not None:
60
- c()
60
+ c() # noqa
61
61
 
62
62
 
63
63
  #
64
64
 
65
65
 
66
- def close_response(resp: BaseHttpResponse) -> None:
66
+ def close_http_client_response(resp: BaseHttpResponse) -> None:
67
67
  if isinstance(resp, HttpResponse):
68
68
  pass
69
69
 
@@ -75,7 +75,7 @@ def close_response(resp: BaseHttpResponse) -> None:
75
75
 
76
76
 
77
77
  @contextlib.contextmanager
78
- def closing_response(resp: BaseHttpResponseT) -> ta.Iterator[BaseHttpResponseT]:
78
+ def closing_http_client_response(resp: BaseHttpResponseT) -> ta.Iterator[BaseHttpResponseT]:
79
79
  if isinstance(resp, HttpResponse):
80
80
  yield resp
81
81
  return
@@ -88,7 +88,7 @@ def closing_response(resp: BaseHttpResponseT) -> ta.Iterator[BaseHttpResponseT]:
88
88
  raise TypeError(resp)
89
89
 
90
90
 
91
- def read_response(resp: BaseHttpResponse) -> HttpResponse:
91
+ def read_http_client_response(resp: BaseHttpResponse) -> HttpResponse:
92
92
  if isinstance(resp, HttpResponse):
93
93
  return resp
94
94
 
@@ -119,12 +119,12 @@ class HttpClient(BaseHttpClient, Abstract):
119
119
  context: ta.Optional[HttpClientContext] = None,
120
120
  check: bool = False,
121
121
  ) -> HttpResponse:
122
- with closing_response(self.stream_request(
122
+ with closing_http_client_response(self.stream_request(
123
123
  req,
124
124
  context=context,
125
125
  check=check,
126
126
  )) as resp:
127
- return read_response(resp)
127
+ return read_http_client_response(resp)
128
128
 
129
129
  def stream_request(
130
130
  self,
@@ -144,10 +144,10 @@ class HttpClient(BaseHttpClient, Abstract):
144
144
  cause = resp.underlying
145
145
  else:
146
146
  cause = None
147
- raise HttpStatusError(read_response(resp)) from cause # noqa
147
+ raise HttpStatusError(read_http_client_response(resp)) from cause # noqa
148
148
 
149
149
  except Exception:
150
- close_response(resp)
150
+ close_http_client_response(resp)
151
151
  raise
152
152
 
153
153
  return resp
@@ -0,0 +1,43 @@
1
+ # ruff: noqa: UP043 UP045
2
+ # @omlish-lite
3
+ import dataclasses as dc
4
+
5
+ from .asyncs import AsyncHttpClient
6
+ from .asyncs import AsyncStreamHttpResponse
7
+ from .base import HttpClientContext
8
+ from .base import HttpRequest
9
+ from .sync import HttpClient
10
+ from .sync import StreamHttpResponse
11
+
12
+
13
+ ##
14
+
15
+
16
+ class SyncAsyncHttpClient(AsyncHttpClient):
17
+ def __init__(self, client: HttpClient) -> None:
18
+ super().__init__()
19
+
20
+ self._client = client
21
+
22
+ @dc.dataclass(frozen=True)
23
+ class _StreamAdapter:
24
+ ul: StreamHttpResponse
25
+
26
+ async def read1(self, /, n: int = -1) -> bytes:
27
+ return self.ul.stream.read1(n)
28
+
29
+ async def close(self) -> None:
30
+ self.ul.close()
31
+
32
+ async def _stream_request(self, ctx: HttpClientContext, req: HttpRequest) -> AsyncStreamHttpResponse:
33
+ resp = self._client.stream_request(req, context=ctx)
34
+ return AsyncStreamHttpResponse(
35
+ status=resp.status,
36
+ headers=resp.headers,
37
+ request=req,
38
+ underlying=resp,
39
+ **(dict( # type: ignore
40
+ stream=(adapter := self._StreamAdapter(resp)),
41
+ _closer=adapter.close,
42
+ ) if resp.has_data else {}),
43
+ )
@@ -75,6 +75,7 @@ def build_kwargs_target(
75
75
  skip_args: int = 0,
76
76
  skip_kwargs: ta.Iterable[str] | None = None,
77
77
  raw_optional: bool = False,
78
+ non_strict: bool = False,
78
79
  ) -> KwargsTarget:
79
80
  if isinstance(obj, KwargsTarget):
80
81
  return obj
@@ -93,11 +94,15 @@ def build_kwargs_target(
93
94
  continue
94
95
 
95
96
  if p.annotation is inspect.Signature.empty:
97
+ if non_strict:
98
+ continue
96
99
  if p.default is not inspect.Parameter.empty:
97
100
  raise KeyError(f'{obj}, {p.name}')
98
101
  continue
99
102
 
100
103
  if p.kind not in (inspect.Parameter.POSITIONAL_OR_KEYWORD, inspect.Parameter.KEYWORD_ONLY):
104
+ if non_strict:
105
+ continue
101
106
  raise TypeError(sig)
102
107
 
103
108
  ann = p.annotation
@@ -122,7 +127,8 @@ def build_kwargs_target(
122
127
  k = dc.replace(k, tag=pt)
123
128
 
124
129
  if k in seen:
125
- raise ConflictingKeyError(k)
130
+ if not non_strict:
131
+ raise ConflictingKeyError(k)
126
132
  seen.add(k)
127
133
 
128
134
  kws.append(Kwarg(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: omlish
3
- Version: 0.0.0.dev469
3
+ Version: 0.0.0.dev470
4
4
  Summary: omlish
5
5
  Author: wrmsr
6
6
  License-Expression: BSD-3-Clause
@@ -1,5 +1,5 @@
1
1
  omlish/.omlish-manifests.json,sha256=FLw7xkPiSXuImZgqSP8BwrEib2R1doSzUPLUkc-QUIA,8410
2
- omlish/__about__.py,sha256=wZM9ZuSaoM8SiZeF10mGP-LGOru9blzTxb5CSTZOuRg,3611
2
+ omlish/__about__.py,sha256=V5Z8mEnP0BsV3oc2j2lgsvc5cs3Qd0cHG_3kv3gAQwI,3611
3
3
  omlish/__init__.py,sha256=SsyiITTuK0v74XpKV8dqNaCmjOlan1JZKrHQv5rWKPA,253
4
4
  omlish/c3.py,sha256=ZNIMl1kwg3qdei4DiUrJPQe5M81S1e76N-GuNSwLBAE,8683
5
5
  omlish/cached.py,sha256=MLap_p0rdGoDIMVhXVHm1tsbcWobJF0OanoodV03Ju8,542
@@ -304,7 +304,7 @@ omlish/graphs/dot/make.py,sha256=e-M1IEdh4kHEjJmBxpaEUPxvFLrm5uIXdGxjQZr2HRo,365
304
304
  omlish/graphs/dot/rendering.py,sha256=SGSpwswdFqsjEnznQDyryIsXE8bzPXSUFAJHlB2uT2Y,3655
305
305
  omlish/graphs/dot/utils.py,sha256=8cGKIdcM-w1q4ITUYyC0lnYwLqNWuH2OddmmbLxVgEo,806
306
306
  omlish/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
307
- omlish/http/all.py,sha256=vz3ji7BOFkXSPJX5K-p6zziHVhIqTVasYQrVl7fo_ko,1708
307
+ omlish/http/all.py,sha256=_SyJXPCk3s4FrYZ37pY3f4DI3ULmbwnR6J9hFd7thys,2219
308
308
  omlish/http/asgi.py,sha256=4r2Gw1ojwp2OVpwonof1p4GFRcseIJqPhpkQpLhM9Jw,3243
309
309
  omlish/http/consts.py,sha256=7BJ4D1MdIvqBcepkgCfBFHolgTwbOlqsOEiee_IjxOA,2289
310
310
  omlish/http/cookies.py,sha256=uuOYlHR6e2SC3GM41V0aozK10nef9tYg83Scqpn5-HM,6351
@@ -323,13 +323,14 @@ omlish/http/urls.py,sha256=dZBeQwf5ogKwsD_uCEei5EG_SbnHk-MzpX2FYLsfTgM,1774
323
323
  omlish/http/versions.py,sha256=Lwk6FztKH7c5zuc7NFWxPVULuLeeQp5-NFJInY6r-Zo,420
324
324
  omlish/http/wsgi.py,sha256=1JpfrY2JrQ0wrEVE0oLdQMWZw8Zcx0b4_9f3VmH4JKA,1070
325
325
  omlish/http/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
326
- omlish/http/clients/asyncs.py,sha256=bgqKf1CRfzFC4vKUXaJZvflU-yAeD1d7HirE1Rq5ni4,4335
326
+ omlish/http/clients/asyncs.py,sha256=YJKin04lXSrhn8tgs2gMEo8Fy4jWkPhy6ZaWi1fVnko,4427
327
327
  omlish/http/clients/base.py,sha256=bm3Oy2wuunSO3Rd2dxCmhHoZcQ8X9B5pkzaudbjZKvI,2810
328
328
  omlish/http/clients/default.py,sha256=fnz-pvPKHc7Kgft4XRwOZ6ZUUtt5D6ljuvOGAA8mgQw,5639
329
329
  omlish/http/clients/executor.py,sha256=A9LLTR3O_-_hH6HAB3hvf5uBv9SwLL5YOW3YWVb20Js,1580
330
330
  omlish/http/clients/httpx.py,sha256=8CVA9nNVKSkKcEynu34GxcbfVaz3PBA_UBx3-NFKDrw,4448
331
- omlish/http/clients/middleware.py,sha256=OVCRlcCLtnbftXmgJX8sugi7iIA1mauJD5dpmUcC1wU,5018
332
- omlish/http/clients/sync.py,sha256=a5ZUiTPxeIyVtvBQGYSobezKLA2aIfKr9iK6DzZRpYk,3966
331
+ omlish/http/clients/middleware.py,sha256=xnXlNN1MU4sUKtkhPzdpRQsRh9wpLf1r7OGKjqGzLWg,5058
332
+ omlish/http/clients/sync.py,sha256=zs6XzFHKwKhKuBwb6hJFaYOcBY-4QVEsa0udFOoU0QM,4058
333
+ omlish/http/clients/syncasync.py,sha256=veVSD-uqOzePAUzhXOoJvMF6fHLOkzXYbviQ9x18l1k,1215
333
334
  omlish/http/clients/urllib.py,sha256=BwxlDEiJQZA6sogcqTtuog6WEK2OhVNLR70F50lXA9I,2764
334
335
  omlish/http/clients/coro/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
335
336
  omlish/http/clients/coro/sync.py,sha256=JCWSCsDP7rFBRQSxzB7WmBBwRdAfLFRGI-F_4f0jiPQ,5673
@@ -377,7 +378,7 @@ omlish/inject/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
377
378
  omlish/inject/impl/bindings.py,sha256=xSvUcoDz8NH-aNHPwBPEZsFg73K2WcF_A63npVbGt_k,420
378
379
  omlish/inject/impl/elements.py,sha256=qR06KaAjZMaQgdMBE6_tdrT7cWP1Ft0CFq71bnyp224,6265
379
380
  omlish/inject/impl/injector.py,sha256=tcPyq_747L12G3CT_rA9KU4l_gWlesX0uCDv3GJOZGY,8366
380
- omlish/inject/impl/inspect.py,sha256=UcCaQEhQfRINrY9Phz9UYKCuAg7HnZTqBJ2i-6j_O1A,3193
381
+ omlish/inject/impl/inspect.py,sha256=6emiBEyaVmH2m1U5Zv5VX7-f8Gor0VOQSUEqhlcT6VU,3366
381
382
  omlish/inject/impl/maysync.py,sha256=7GWjrvJStOx85BCvk8IJAmmkoGkChFAAi2h7j2pe6Qs,1207
382
383
  omlish/inject/impl/multis.py,sha256=5aKXnmSocwqu7y6WicvYX1-QGTz9iHubxRq9j0enlgk,2174
383
384
  omlish/inject/impl/origins.py,sha256=dgGdkoMN6I4DZrWjlpZYijeFsrF6Up1WPq_QSAgTtuQ,1676
@@ -838,9 +839,9 @@ omlish/typedvalues/marshal.py,sha256=2xqX6JllhtGpmeYkU7C-qzgU__0x-vd6CzYbAsocQlc
838
839
  omlish/typedvalues/of_.py,sha256=UXkxSj504WI2UrFlqdZJbu2hyDwBhL7XVrc2qdR02GQ,1309
839
840
  omlish/typedvalues/reflect.py,sha256=PAvKW6T4cW7u--iX80w3HWwZUS3SmIZ2_lQjT65uAyk,1026
840
841
  omlish/typedvalues/values.py,sha256=ym46I-q2QJ_6l4UlERqv3yj87R-kp8nCKMRph0xQ3UA,1307
841
- omlish-0.0.0.dev469.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
842
- omlish-0.0.0.dev469.dist-info/METADATA,sha256=wvn1a7zXW_oNIgIcizSM93cgAp7XOS14_aow1KXlkpA,18999
843
- omlish-0.0.0.dev469.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
844
- omlish-0.0.0.dev469.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
845
- omlish-0.0.0.dev469.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
846
- omlish-0.0.0.dev469.dist-info/RECORD,,
842
+ omlish-0.0.0.dev470.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
843
+ omlish-0.0.0.dev470.dist-info/METADATA,sha256=Peyq-X7o-fd7UGpjw1lWUeSRESH7QHk1xpR_bXoYscw,18999
844
+ omlish-0.0.0.dev470.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
845
+ omlish-0.0.0.dev470.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
846
+ omlish-0.0.0.dev470.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
847
+ omlish-0.0.0.dev470.dist-info/RECORD,,