hishel 1.0.0.dev1__py3-none-any.whl → 1.0.0.dev3__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.
- hishel/__init__.py +15 -14
- hishel/_async_cache.py +50 -37
- hishel/_async_httpx.py +243 -0
- hishel/_core/_headers.py +11 -1
- hishel/_core/_spec.py +184 -127
- hishel/_core/_storages/_async_base.py +71 -0
- hishel/_core/{_async/_storages/_sqlite.py → _storages/_async_sqlite.py} +95 -132
- hishel/_core/_storages/_packing.py +144 -0
- hishel/_core/_storages/_sync_base.py +71 -0
- hishel/_core/{_sync/_storages/_sqlite.py → _storages/_sync_sqlite.py} +95 -132
- hishel/_core/models.py +13 -26
- hishel/_sync_cache.py +50 -37
- hishel/_sync_httpx.py +243 -0
- hishel/_utils.py +48 -137
- hishel/asgi.py +400 -0
- hishel/fastapi.py +263 -0
- hishel/httpx.py +3 -326
- hishel/requests.py +25 -17
- {hishel-1.0.0.dev1.dist-info → hishel-1.0.0.dev3.dist-info}/METADATA +139 -27
- hishel-1.0.0.dev3.dist-info/RECORD +23 -0
- hishel/_core/__init__.py +0 -59
- hishel/_core/_base/_storages/_base.py +0 -272
- hishel/_core/_base/_storages/_packing.py +0 -165
- hishel-1.0.0.dev1.dist-info/RECORD +0 -19
- {hishel-1.0.0.dev1.dist-info → hishel-1.0.0.dev3.dist-info}/WHEEL +0 -0
- {hishel-1.0.0.dev1.dist-info → hishel-1.0.0.dev3.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
hishel/__init__.py,sha256=HqU6RUrtlvEMTo5i7WbdSJvYoLQiyqkMJVbXrefd6Ww,1566
|
|
2
|
+
hishel/_async_cache.py,sha256=He_wRJYMSy0aLinzlgQ76ohOos15Bbw3N2uu6cLGkZk,7216
|
|
3
|
+
hishel/_async_httpx.py,sha256=e8JO37K6fF4UZlTGeMpsmMJtLLhGfdWQNLIhPahlbkU,7894
|
|
4
|
+
hishel/_sync_cache.py,sha256=zYNrRoOeBUta-GO0yNRs7n-PQ4WglQLEzvbY5N9oZCU,6962
|
|
5
|
+
hishel/_sync_httpx.py,sha256=eQlIwb3RrJNV3CEqs3xGQJByVOO3C_DXK8W5x60HZlQ,7726
|
|
6
|
+
hishel/_utils.py,sha256=kD5ki4PKeYsNBMh3tAjsXggF2-_oeNz6aVlARxyl0H0,3842
|
|
7
|
+
hishel/asgi.py,sha256=mbYFJHQJCRE6w0KcZiSe9qIHHPgRFuCwAwg9haJoMWI,14983
|
|
8
|
+
hishel/fastapi.py,sha256=CVWCyXTxBPwG_XALo-Oldekv4lqMgH2-W-PPZ9rZjXg,10826
|
|
9
|
+
hishel/httpx.py,sha256=99a8X9COPiPHSgGW61O2uMWMZB7dY93Ty9DTCJ9C18Q,467
|
|
10
|
+
hishel/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
hishel/requests.py,sha256=Bi0_1O2xgFlWqG1g6OR1gpb5MY8CKJmgLPDEG6bhuXM,6533
|
|
12
|
+
hishel/_core/_headers.py,sha256=hGaT6o1F-gs1pm5RpdGb0IMQL3uJYDH1xpwJLy28Cys,17514
|
|
13
|
+
hishel/_core/_spec.py,sha256=yJsOmNU5dMXXBw80ZLnse9Tl4UGkHmiyyfjv1Q0eP9w,103871
|
|
14
|
+
hishel/_core/models.py,sha256=YBXpk5GRWsB8ppksehTaIDJ_V5KAENKspSj-kLvJUPY,5169
|
|
15
|
+
hishel/_core/_storages/_async_base.py,sha256=iZ6Mb30P0ho5h4UU5bgOrcsSMZ1427j9tht-tupZs68,2106
|
|
16
|
+
hishel/_core/_storages/_async_sqlite.py,sha256=QNo5oWnnHAU0rTPJJbE9d6__xG_jWrG3-atoyE2j3q0,15555
|
|
17
|
+
hishel/_core/_storages/_packing.py,sha256=mC8LMFQ5uPfFOgingKm2WKFO_DwcZ1OjTgI6xc0hfJI,3708
|
|
18
|
+
hishel/_core/_storages/_sync_base.py,sha256=qfOvcFY5qvrzSh4ztV2Trlxft-BF7An5SFsLlEb8EeE,2075
|
|
19
|
+
hishel/_core/_storages/_sync_sqlite.py,sha256=A-L6fDU1JvVDzHNzV396V3U3sFPLycrxSnD00DHrTvs,15048
|
|
20
|
+
hishel-1.0.0.dev3.dist-info/METADATA,sha256=CLK-XP376Y4IuDGQgYxzRhJhfoi9Z281HlZccTOVXqE,12884
|
|
21
|
+
hishel-1.0.0.dev3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
22
|
+
hishel-1.0.0.dev3.dist-info/licenses/LICENSE,sha256=1qQj7pE0V2O9OIedvyOgLGLvZLaPd3nFEup3IBEOZjQ,1493
|
|
23
|
+
hishel-1.0.0.dev3.dist-info/RECORD,,
|
hishel/_core/__init__.py
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
from hishel._core._async._storages._sqlite import AsyncSqliteStorage
|
|
2
|
-
from hishel._core._base._storages._base import (
|
|
3
|
-
AsyncBaseStorage as AsyncBaseStorage,
|
|
4
|
-
SyncBaseStorage as SyncBaseStorage,
|
|
5
|
-
)
|
|
6
|
-
from hishel._core._headers import Headers as Headers
|
|
7
|
-
from hishel._core._spec import (
|
|
8
|
-
AnyState as AnyState,
|
|
9
|
-
CacheMiss as CacheMiss,
|
|
10
|
-
CacheOptions as CacheOptions,
|
|
11
|
-
CouldNotBeStored as CouldNotBeStored,
|
|
12
|
-
FromCache as FromCache,
|
|
13
|
-
IdleClient as IdleClient,
|
|
14
|
-
NeedRevalidation as NeedRevalidation,
|
|
15
|
-
NeedToBeUpdated as NeedToBeUpdated,
|
|
16
|
-
State as State,
|
|
17
|
-
StoreAndUse as StoreAndUse,
|
|
18
|
-
create_idle_state as create_idle_state,
|
|
19
|
-
)
|
|
20
|
-
from hishel._core._sync._storages._sqlite import SyncSqliteStorage
|
|
21
|
-
from hishel._core.models import (
|
|
22
|
-
CompletePair as CompletePair,
|
|
23
|
-
IncompletePair as IncompletePair,
|
|
24
|
-
Pair as Pair,
|
|
25
|
-
PairMeta as PairMeta,
|
|
26
|
-
Request as Request,
|
|
27
|
-
Response,
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
__all__ = (
|
|
31
|
-
# New API
|
|
32
|
-
## States
|
|
33
|
-
"AnyState",
|
|
34
|
-
"IdleClient",
|
|
35
|
-
"CacheMiss",
|
|
36
|
-
"FromCache",
|
|
37
|
-
"NeedRevalidation",
|
|
38
|
-
"AnyState",
|
|
39
|
-
"CacheOptions",
|
|
40
|
-
"NeedToBeUpdated",
|
|
41
|
-
"State",
|
|
42
|
-
"StoreAndUse",
|
|
43
|
-
"CouldNotBeStored",
|
|
44
|
-
"create_idle_state",
|
|
45
|
-
## Models
|
|
46
|
-
"Request",
|
|
47
|
-
"Response",
|
|
48
|
-
"Pair",
|
|
49
|
-
"IncompletePair",
|
|
50
|
-
"CompletePair",
|
|
51
|
-
"PairMeta",
|
|
52
|
-
## Headers
|
|
53
|
-
"Headers",
|
|
54
|
-
## Storages
|
|
55
|
-
"SyncBaseStorage",
|
|
56
|
-
"AsyncBaseStorage",
|
|
57
|
-
"SyncSqliteStorage",
|
|
58
|
-
"AsyncSqliteStorage",
|
|
59
|
-
)
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import abc
|
|
4
|
-
import time
|
|
5
|
-
import typing as tp
|
|
6
|
-
import uuid
|
|
7
|
-
from abc import ABC
|
|
8
|
-
from pathlib import Path
|
|
9
|
-
|
|
10
|
-
from hishel._core.models import CompletePair, IncompletePair, Request, Response
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class SyncBaseStorage(ABC):
|
|
14
|
-
@abc.abstractmethod
|
|
15
|
-
def create_pair(
|
|
16
|
-
self,
|
|
17
|
-
request: Request,
|
|
18
|
-
id: uuid.UUID | None = None,
|
|
19
|
-
) -> IncompletePair:
|
|
20
|
-
"""
|
|
21
|
-
Store a request in the backend under the given key.
|
|
22
|
-
|
|
23
|
-
Args:
|
|
24
|
-
request: The request object to store.
|
|
25
|
-
|
|
26
|
-
Returns:
|
|
27
|
-
The created IncompletePair object representing the stored request.
|
|
28
|
-
|
|
29
|
-
Raises:
|
|
30
|
-
NotImplementedError: Must be implemented in subclasses.
|
|
31
|
-
"""
|
|
32
|
-
raise NotImplementedError()
|
|
33
|
-
|
|
34
|
-
@abc.abstractmethod
|
|
35
|
-
def add_response(self, pair_id: uuid.UUID, response: Response, key: str | bytes) -> CompletePair:
|
|
36
|
-
"""
|
|
37
|
-
Add a response to an existing request pair.
|
|
38
|
-
|
|
39
|
-
Args:
|
|
40
|
-
pair_id: The unique identifier of the request pair.
|
|
41
|
-
response: The response object to add.
|
|
42
|
-
key: The cache key associated with the request pair.
|
|
43
|
-
|
|
44
|
-
Returns:
|
|
45
|
-
The updated response object.
|
|
46
|
-
|
|
47
|
-
Raises:
|
|
48
|
-
NotImplementedError: Must be implemented in subclasses.
|
|
49
|
-
"""
|
|
50
|
-
raise NotImplementedError()
|
|
51
|
-
|
|
52
|
-
@abc.abstractmethod
|
|
53
|
-
def get_pairs(self, key: str) -> tp.List[CompletePair]:
|
|
54
|
-
"""
|
|
55
|
-
Retrieve all responses associated with a given key.
|
|
56
|
-
|
|
57
|
-
Args:
|
|
58
|
-
key: The unique identifier for the request pairs.
|
|
59
|
-
complete_only: If True, only return pairs with responses. If False,
|
|
60
|
-
only return pairs without responses. If None, return all pairs.
|
|
61
|
-
"""
|
|
62
|
-
raise NotImplementedError()
|
|
63
|
-
|
|
64
|
-
@abc.abstractmethod
|
|
65
|
-
def update_pair(
|
|
66
|
-
self,
|
|
67
|
-
id: uuid.UUID,
|
|
68
|
-
new_pair: tp.Union[CompletePair, tp.Callable[[CompletePair], CompletePair]],
|
|
69
|
-
) -> tp.Optional[CompletePair]:
|
|
70
|
-
"""
|
|
71
|
-
Update an existing request pair.
|
|
72
|
-
|
|
73
|
-
Args:
|
|
74
|
-
id: The unique identifier of the request pair to update.
|
|
75
|
-
new_pair: The new pair data or a callable that takes the current pair
|
|
76
|
-
and returns the updated pair.
|
|
77
|
-
"""
|
|
78
|
-
raise NotImplementedError()
|
|
79
|
-
|
|
80
|
-
@abc.abstractmethod
|
|
81
|
-
def remove(self, id: uuid.UUID) -> None:
|
|
82
|
-
"""
|
|
83
|
-
Remove a request pair from the storage.
|
|
84
|
-
|
|
85
|
-
Args:
|
|
86
|
-
id: The unique identifier of the request pair to remove.
|
|
87
|
-
"""
|
|
88
|
-
raise NotImplementedError()
|
|
89
|
-
|
|
90
|
-
def close(self) -> None:
|
|
91
|
-
"""
|
|
92
|
-
Close any resources held by the storage backend.
|
|
93
|
-
"""
|
|
94
|
-
pass
|
|
95
|
-
|
|
96
|
-
def is_soft_deleted(self, pair: IncompletePair | CompletePair) -> bool:
|
|
97
|
-
"""
|
|
98
|
-
Check if a pair is soft deleted based on its metadata.
|
|
99
|
-
|
|
100
|
-
Args:
|
|
101
|
-
pair: The request pair to check.
|
|
102
|
-
|
|
103
|
-
Returns:
|
|
104
|
-
True if the pair is soft deleted, False otherwise.
|
|
105
|
-
"""
|
|
106
|
-
return pair.meta.deleted_at is not None and pair.meta.deleted_at > 0
|
|
107
|
-
|
|
108
|
-
def is_safe_to_hard_delete(self, pair: IncompletePair | CompletePair) -> bool:
|
|
109
|
-
"""
|
|
110
|
-
Check if a pair is safe to hard delete based on its metadata.
|
|
111
|
-
|
|
112
|
-
If the pair has been soft deleted for more than 1 hour, it is considered safe to hard delete.
|
|
113
|
-
|
|
114
|
-
Args:
|
|
115
|
-
pair: The request pair to check.
|
|
116
|
-
|
|
117
|
-
Returns:
|
|
118
|
-
True if the pair is safe to hard delete, False otherwise.
|
|
119
|
-
"""
|
|
120
|
-
return bool(pair.meta.deleted_at is not None and (pair.meta.deleted_at + 3600 < time.time()))
|
|
121
|
-
|
|
122
|
-
@tp.overload
|
|
123
|
-
def mark_pair_as_deleted(self, pair: CompletePair) -> CompletePair: ...
|
|
124
|
-
@tp.overload
|
|
125
|
-
def mark_pair_as_deleted(self, pair: IncompletePair) -> IncompletePair: ...
|
|
126
|
-
def mark_pair_as_deleted(self, pair: CompletePair | IncompletePair) -> CompletePair | IncompletePair:
|
|
127
|
-
"""
|
|
128
|
-
Mark a pair as soft deleted by setting its deleted_at timestamp.
|
|
129
|
-
|
|
130
|
-
Args:
|
|
131
|
-
pair: The request pair to mark as deleted.
|
|
132
|
-
Returns:
|
|
133
|
-
The updated request pair with the deleted_at timestamp set.
|
|
134
|
-
"""
|
|
135
|
-
pair.meta.deleted_at = time.time()
|
|
136
|
-
return pair
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
class AsyncBaseStorage(ABC):
|
|
140
|
-
@abc.abstractmethod
|
|
141
|
-
async def create_pair(
|
|
142
|
-
self,
|
|
143
|
-
request: Request,
|
|
144
|
-
id: uuid.UUID | None = None,
|
|
145
|
-
) -> IncompletePair:
|
|
146
|
-
"""
|
|
147
|
-
Store a request in the backend under the given key.
|
|
148
|
-
|
|
149
|
-
Args:
|
|
150
|
-
request: The request object to store.
|
|
151
|
-
|
|
152
|
-
Returns:
|
|
153
|
-
The created IncompletePair object representing the stored request.
|
|
154
|
-
|
|
155
|
-
Raises:
|
|
156
|
-
NotImplementedError: Must be implemented in subclasses.
|
|
157
|
-
"""
|
|
158
|
-
raise NotImplementedError()
|
|
159
|
-
|
|
160
|
-
@abc.abstractmethod
|
|
161
|
-
async def add_response(self, pair_id: uuid.UUID, response: Response, key: str | bytes) -> CompletePair:
|
|
162
|
-
"""
|
|
163
|
-
Add a response to an existing request pair.
|
|
164
|
-
|
|
165
|
-
Args:
|
|
166
|
-
pair_id: The unique identifier of the request pair.
|
|
167
|
-
response: The response object to add.
|
|
168
|
-
key: The cache key associated with the request pair.
|
|
169
|
-
|
|
170
|
-
Returns:
|
|
171
|
-
The updated response object.
|
|
172
|
-
|
|
173
|
-
Raises:
|
|
174
|
-
NotImplementedError: Must be implemented in subclasses.
|
|
175
|
-
"""
|
|
176
|
-
raise NotImplementedError()
|
|
177
|
-
|
|
178
|
-
@abc.abstractmethod
|
|
179
|
-
async def get_pairs(self, key: str) -> tp.List[CompletePair]:
|
|
180
|
-
"""
|
|
181
|
-
Retrieve all responses associated with a given key.
|
|
182
|
-
|
|
183
|
-
Args:
|
|
184
|
-
key: The unique identifier for the request pairs.
|
|
185
|
-
"""
|
|
186
|
-
raise NotImplementedError()
|
|
187
|
-
|
|
188
|
-
@abc.abstractmethod
|
|
189
|
-
async def update_pair(
|
|
190
|
-
self,
|
|
191
|
-
id: uuid.UUID,
|
|
192
|
-
new_pair: tp.Union[CompletePair, tp.Callable[[CompletePair], CompletePair]],
|
|
193
|
-
) -> tp.Optional[CompletePair]:
|
|
194
|
-
"""
|
|
195
|
-
Update an existing request pair.
|
|
196
|
-
|
|
197
|
-
Args:
|
|
198
|
-
id: The unique identifier of the request pair to update.
|
|
199
|
-
new_pair: The new pair data or a callable that takes the current pair
|
|
200
|
-
and returns the updated pair.
|
|
201
|
-
"""
|
|
202
|
-
raise NotImplementedError()
|
|
203
|
-
|
|
204
|
-
@abc.abstractmethod
|
|
205
|
-
async def remove(self, id: uuid.UUID) -> None:
|
|
206
|
-
"""
|
|
207
|
-
Remove a request pair from the storage.
|
|
208
|
-
|
|
209
|
-
Args:
|
|
210
|
-
id: The unique identifier of the request pair to remove.
|
|
211
|
-
"""
|
|
212
|
-
raise NotImplementedError()
|
|
213
|
-
|
|
214
|
-
async def close(self) -> None:
|
|
215
|
-
"""
|
|
216
|
-
Close any resources held by the storage backend.
|
|
217
|
-
"""
|
|
218
|
-
pass
|
|
219
|
-
|
|
220
|
-
def is_soft_deleted(self, pair: IncompletePair | CompletePair) -> bool:
|
|
221
|
-
"""
|
|
222
|
-
Check if a pair is soft deleted based on its metadata.
|
|
223
|
-
|
|
224
|
-
Args:
|
|
225
|
-
pair: The request pair to check.
|
|
226
|
-
|
|
227
|
-
Returns:
|
|
228
|
-
True if the pair is soft deleted, False otherwise.
|
|
229
|
-
"""
|
|
230
|
-
return pair.meta.deleted_at is not None and pair.meta.deleted_at > 0
|
|
231
|
-
|
|
232
|
-
def is_safe_to_hard_delete(self, pair: IncompletePair | CompletePair) -> bool:
|
|
233
|
-
"""
|
|
234
|
-
Check if a pair is safe to hard delete based on its metadata.
|
|
235
|
-
|
|
236
|
-
If the pair has been soft deleted for more than 1 hour, it is considered safe to hard delete.
|
|
237
|
-
|
|
238
|
-
Args:
|
|
239
|
-
pair: The request pair to check.
|
|
240
|
-
|
|
241
|
-
Returns:
|
|
242
|
-
True if the pair is safe to hard delete, False otherwise.
|
|
243
|
-
"""
|
|
244
|
-
return bool(pair.meta.deleted_at is not None and (pair.meta.deleted_at + 3600 < time.time()))
|
|
245
|
-
|
|
246
|
-
@tp.overload
|
|
247
|
-
def mark_pair_as_deleted(self, pair: CompletePair) -> CompletePair: ...
|
|
248
|
-
@tp.overload
|
|
249
|
-
def mark_pair_as_deleted(self, pair: IncompletePair) -> IncompletePair: ...
|
|
250
|
-
def mark_pair_as_deleted(self, pair: CompletePair | IncompletePair) -> CompletePair | IncompletePair:
|
|
251
|
-
"""
|
|
252
|
-
Mark a pair as soft deleted by setting its deleted_at timestamp.
|
|
253
|
-
|
|
254
|
-
Args:
|
|
255
|
-
pair: The request pair to mark as deleted.
|
|
256
|
-
Returns:
|
|
257
|
-
The updated request pair with the deleted_at timestamp set.
|
|
258
|
-
"""
|
|
259
|
-
pair.meta.deleted_at = time.time()
|
|
260
|
-
return pair
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
def ensure_cache_dict(base_path: str | None = None) -> Path:
|
|
264
|
-
_base_path = Path(base_path) if base_path is not None else Path(".cache/hishel")
|
|
265
|
-
_gitignore_file = _base_path / ".gitignore"
|
|
266
|
-
|
|
267
|
-
_base_path.mkdir(parents=True, exist_ok=True)
|
|
268
|
-
|
|
269
|
-
if not _gitignore_file.is_file():
|
|
270
|
-
with open(_gitignore_file, "w", encoding="utf-8") as f:
|
|
271
|
-
f.write("# Automatically created by Hishel\n*")
|
|
272
|
-
return _base_path
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import uuid
|
|
4
|
-
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union, overload
|
|
5
|
-
|
|
6
|
-
import msgpack
|
|
7
|
-
from typing_extensions import Literal, cast
|
|
8
|
-
|
|
9
|
-
from hishel._core._headers import Headers
|
|
10
|
-
from hishel._core.models import PairMeta, Request, Response
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def filter_out_hishel_metadata(data: Mapping[str, Any]) -> dict[str, Any]:
|
|
14
|
-
return {k: v for k, v in data.items() if not k.startswith("hishel_")}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if TYPE_CHECKING:
|
|
18
|
-
from hishel import CompletePair, IncompletePair
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@overload
|
|
22
|
-
def pack(
|
|
23
|
-
value: "CompletePair" | "IncompletePair",
|
|
24
|
-
/,
|
|
25
|
-
kind: Literal["pair"],
|
|
26
|
-
) -> bytes: ...
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@overload
|
|
30
|
-
def pack(
|
|
31
|
-
value: uuid.UUID,
|
|
32
|
-
/,
|
|
33
|
-
kind: Literal["entry_db_key_index"],
|
|
34
|
-
) -> bytes: ...
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def pack(
|
|
38
|
-
value: Union["CompletePair", "IncompletePair", uuid.UUID],
|
|
39
|
-
/,
|
|
40
|
-
kind: Literal["pair", "entry_db_key_index"],
|
|
41
|
-
) -> bytes:
|
|
42
|
-
from hishel import CompletePair, IncompletePair
|
|
43
|
-
|
|
44
|
-
if kind == "entry_db_key_index":
|
|
45
|
-
assert isinstance(value, uuid.UUID)
|
|
46
|
-
return value.bytes
|
|
47
|
-
elif kind == "pair":
|
|
48
|
-
assert isinstance(value, (CompletePair, IncompletePair))
|
|
49
|
-
cache_key_dict = {"cache_key": value.cache_key} if isinstance(value, CompletePair) else {}
|
|
50
|
-
return cast(
|
|
51
|
-
bytes,
|
|
52
|
-
msgpack.packb(
|
|
53
|
-
{
|
|
54
|
-
"id": value.id.bytes,
|
|
55
|
-
"request": {
|
|
56
|
-
"method": value.request.method,
|
|
57
|
-
"url": value.request.url,
|
|
58
|
-
"headers": value.request.headers._headers,
|
|
59
|
-
"extra": filter_out_hishel_metadata(value.request.metadata),
|
|
60
|
-
},
|
|
61
|
-
"response": (
|
|
62
|
-
{
|
|
63
|
-
"status_code": value.response.status_code,
|
|
64
|
-
"headers": value.response.headers._headers,
|
|
65
|
-
"extra": filter_out_hishel_metadata(value.response.metadata),
|
|
66
|
-
}
|
|
67
|
-
)
|
|
68
|
-
if isinstance(value, CompletePair)
|
|
69
|
-
else None,
|
|
70
|
-
"meta": {
|
|
71
|
-
"created_at": value.meta.created_at,
|
|
72
|
-
"deleted_at": value.meta.deleted_at,
|
|
73
|
-
},
|
|
74
|
-
**cache_key_dict,
|
|
75
|
-
}
|
|
76
|
-
),
|
|
77
|
-
)
|
|
78
|
-
assert False, f"Unexpected kind: {kind}"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
@overload
|
|
82
|
-
def unpack(
|
|
83
|
-
value: bytes,
|
|
84
|
-
/,
|
|
85
|
-
kind: Literal["pair"],
|
|
86
|
-
) -> Union["CompletePair", "IncompletePair"]: ...
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
@overload
|
|
90
|
-
def unpack(
|
|
91
|
-
value: bytes,
|
|
92
|
-
/,
|
|
93
|
-
kind: Literal["entry_db_key_index"],
|
|
94
|
-
) -> uuid.UUID: ...
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
@overload
|
|
98
|
-
def unpack(
|
|
99
|
-
value: Optional[bytes],
|
|
100
|
-
/,
|
|
101
|
-
kind: Literal["pair"],
|
|
102
|
-
) -> Optional[Union["CompletePair", "IncompletePair"]]: ...
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
@overload
|
|
106
|
-
def unpack(
|
|
107
|
-
value: Optional[bytes],
|
|
108
|
-
/,
|
|
109
|
-
kind: Literal["entry_db_key_index"],
|
|
110
|
-
) -> Optional[uuid.UUID]: ...
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
def unpack(
|
|
114
|
-
value: Optional[bytes],
|
|
115
|
-
/,
|
|
116
|
-
kind: Literal["pair", "entry_db_key_index"],
|
|
117
|
-
) -> Union["CompletePair", "IncompletePair", uuid.UUID, None]:
|
|
118
|
-
from hishel import CompletePair, IncompletePair
|
|
119
|
-
|
|
120
|
-
if value is None:
|
|
121
|
-
return None
|
|
122
|
-
if kind == "entry_db_key_index":
|
|
123
|
-
return uuid.UUID(bytes=value)
|
|
124
|
-
elif kind == "pair":
|
|
125
|
-
data = msgpack.unpackb(value)
|
|
126
|
-
id = uuid.UUID(bytes=data["id"])
|
|
127
|
-
if data.get("response"):
|
|
128
|
-
return CompletePair(
|
|
129
|
-
id=id,
|
|
130
|
-
request=Request(
|
|
131
|
-
method=data["request"]["method"],
|
|
132
|
-
url=data["request"]["url"],
|
|
133
|
-
headers=Headers(data["request"]["headers"]),
|
|
134
|
-
metadata=data["request"]["extra"],
|
|
135
|
-
stream=iter([]),
|
|
136
|
-
),
|
|
137
|
-
response=(
|
|
138
|
-
Response(
|
|
139
|
-
status_code=data["response"]["status_code"],
|
|
140
|
-
headers=Headers(data["response"]["headers"]),
|
|
141
|
-
metadata=data["response"]["extra"],
|
|
142
|
-
stream=iter([]),
|
|
143
|
-
)
|
|
144
|
-
),
|
|
145
|
-
meta=PairMeta(
|
|
146
|
-
created_at=data["meta"]["created_at"],
|
|
147
|
-
deleted_at=data["meta"]["deleted_at"],
|
|
148
|
-
),
|
|
149
|
-
cache_key=data["cache_key"],
|
|
150
|
-
)
|
|
151
|
-
else:
|
|
152
|
-
return IncompletePair(
|
|
153
|
-
id=id,
|
|
154
|
-
request=Request(
|
|
155
|
-
method=data["request"]["method"],
|
|
156
|
-
url=data["request"]["url"],
|
|
157
|
-
headers=Headers(data["request"]["headers"]),
|
|
158
|
-
metadata=data["request"]["extra"],
|
|
159
|
-
stream=iter([]),
|
|
160
|
-
),
|
|
161
|
-
meta=PairMeta(
|
|
162
|
-
created_at=data["meta"]["created_at"],
|
|
163
|
-
deleted_at=data["meta"]["deleted_at"],
|
|
164
|
-
),
|
|
165
|
-
)
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
hishel/__init__.py,sha256=byj_IhCjFMaBcp6R8iyRlQV-3R4uTfH44PQzB4lVe1g,1447
|
|
2
|
-
hishel/_async_cache.py,sha256=gE5CygC7FG9htBMfxul7carRRNph8zcMlSoOcB_LNTY,6792
|
|
3
|
-
hishel/_sync_cache.py,sha256=lfkWHJFK527peESMaufjKSbXBriidc09tOwBwub2t34,6538
|
|
4
|
-
hishel/_utils.py,sha256=hQURFuNdS7sjHeVGu12MQzJewjFdnVrdOki3CjBfZvs,6162
|
|
5
|
-
hishel/httpx.py,sha256=vscNB426VIhh0f5qQVkGA_WpwVvaKxbI6gnsHrBA_D0,11226
|
|
6
|
-
hishel/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
hishel/requests.py,sha256=eiWcwCId04DucnquCsU12tj9cDZcn-cjZ9MYniVuNeo,6429
|
|
8
|
-
hishel/_core/__init__.py,sha256=byj_IhCjFMaBcp6R8iyRlQV-3R4uTfH44PQzB4lVe1g,1447
|
|
9
|
-
hishel/_core/_headers.py,sha256=ii4x2L6GoQFpqpgg28OtFh7p2DoM9mhE4q6CjW6xUWc,17473
|
|
10
|
-
hishel/_core/_spec.py,sha256=d2ZnTXttyT4zuVq9xHAO86VGJxAEBxD2a8WMyEgOuAo,102702
|
|
11
|
-
hishel/_core/models.py,sha256=5qwo1WifrDeZdXag7M5rh0hJuVsm1N-sF3UagQ5LcLc,5519
|
|
12
|
-
hishel/_core/_async/_storages/_sqlite.py,sha256=QPbNtNMA7vYjpt8bSPFIZ4u4c3UCH6eDfUWnH6WprTU,17787
|
|
13
|
-
hishel/_core/_base/_storages/_base.py,sha256=xLJGTBlFK8DVrQMgRMtGXJnYRUmNB-iYkk7S-BtMx8s,8516
|
|
14
|
-
hishel/_core/_base/_storages/_packing.py,sha256=NFMpSvYYTDBNkzwpjj5l4w-JOPLc19oAEDqDEQJ7VZI,4873
|
|
15
|
-
hishel/_core/_sync/_storages/_sqlite.py,sha256=kvAcV2FttZstWEfCczBxj30-PYdj1y9lzh0x3hNusKY,17210
|
|
16
|
-
hishel-1.0.0.dev1.dist-info/METADATA,sha256=IW6_UTqzUl-k8Pcyil_6brlEgd-gKomu1OyeZxrN3dU,9727
|
|
17
|
-
hishel-1.0.0.dev1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
18
|
-
hishel-1.0.0.dev1.dist-info/licenses/LICENSE,sha256=1qQj7pE0V2O9OIedvyOgLGLvZLaPd3nFEup3IBEOZjQ,1493
|
|
19
|
-
hishel-1.0.0.dev1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|