hishel 0.0.30__py3-none-any.whl → 0.0.32__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 CHANGED
@@ -14,4 +14,4 @@ def install_cache() -> None: # pragma: no cover
14
14
  httpx.Client = CacheClient # type: ignore
15
15
 
16
16
 
17
- __version__ = "0.0.30"
17
+ __version__ = "0.0.32"
@@ -227,10 +227,13 @@ class AsyncFileStorage(AsyncBaseStorage):
227
227
  async with self._lock:
228
228
  with os.scandir(self._base_path) as entries:
229
229
  for entry in entries:
230
- if entry.is_file():
231
- age = time.time() - entry.stat().st_mtime
232
- if age > self._ttl:
233
- os.unlink(entry.path)
230
+ try:
231
+ if entry.is_file():
232
+ age = time.time() - entry.stat().st_mtime
233
+ if age > self._ttl:
234
+ os.unlink(entry.path)
235
+ except FileNotFoundError: # pragma: no cover
236
+ pass
234
237
 
235
238
 
236
239
  class AsyncSQLiteStorage(AsyncBaseStorage):
@@ -374,8 +377,8 @@ class AsyncSQLiteStorage(AsyncBaseStorage):
374
377
  return self._serializer.loads(cached_response)
375
378
 
376
379
  async def aclose(self) -> None: # pragma: no cover
377
- assert self._connection
378
- await self._connection.close()
380
+ if self._connection is not None:
381
+ await self._connection.close()
379
382
 
380
383
  async def _remove_expired_caches(self) -> None:
381
384
  assert self._connection
hishel/_controller.py CHANGED
@@ -79,8 +79,10 @@ def get_heuristic_freshness(response: Response, clock: "BaseClock") -> int:
79
79
 
80
80
 
81
81
  def get_age(response: Response, clock: "BaseClock") -> int:
82
- if not header_presents(response.headers, b"date"): # pragma: no cover
83
- raise RuntimeError("The `Date` header is missing in the response.")
82
+ if not header_presents(response.headers, b"date"):
83
+ # If the response does not have a date header, then it is impossible to calculate the age.
84
+ # Instead of raising an exception, we return infinity to be sure that the response is not considered fresh.
85
+ return float("inf") # type: ignore
84
86
 
85
87
  date = parse_date(extract_header_values_decoded(response.headers, b"date")[0])
86
88
 
@@ -149,9 +151,6 @@ class Controller:
149
151
  method = request.method.decode("ascii")
150
152
  force_cache = request.extensions.get("force_cache", None)
151
153
 
152
- if force_cache if force_cache is not None else self._force_cache:
153
- return True
154
-
155
154
  if response.status not in self._cacheable_status_codes:
156
155
  return False
157
156
 
@@ -162,6 +161,9 @@ class Controller:
162
161
  if method not in self._cacheable_methods:
163
162
  return False
164
163
 
164
+ if force_cache if force_cache is not None else self._force_cache:
165
+ return True
166
+
165
167
  response_cache_control = parse_cache_control(extract_header_values_decoded(response.headers, b"cache-control"))
166
168
  request_cache_control = parse_cache_control(extract_header_values_decoded(request.headers, b"cache-control"))
167
169
 
hishel/_sync/_storages.py CHANGED
@@ -227,10 +227,13 @@ class FileStorage(BaseStorage):
227
227
  with self._lock:
228
228
  with os.scandir(self._base_path) as entries:
229
229
  for entry in entries:
230
- if entry.is_file():
231
- age = time.time() - entry.stat().st_mtime
232
- if age > self._ttl:
233
- os.unlink(entry.path)
230
+ try:
231
+ if entry.is_file():
232
+ age = time.time() - entry.stat().st_mtime
233
+ if age > self._ttl:
234
+ os.unlink(entry.path)
235
+ except FileNotFoundError: # pragma: no cover
236
+ pass
234
237
 
235
238
 
236
239
  class SQLiteStorage(BaseStorage):
@@ -374,8 +377,8 @@ class SQLiteStorage(BaseStorage):
374
377
  return self._serializer.loads(cached_response)
375
378
 
376
379
  def close(self) -> None: # pragma: no cover
377
- assert self._connection
378
- self._connection.close()
380
+ if self._connection is not None:
381
+ self._connection.close()
379
382
 
380
383
  def _remove_expired_caches(self) -> None:
381
384
  assert self._connection
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: hishel
3
- Version: 0.0.30
3
+ Version: 0.0.32
4
4
  Summary: Persistent cache implementation for httpx and httpcore
5
5
  Project-URL: Homepage, https://hishel.com
6
6
  Project-URL: Source, https://github.com/karpetrosyan/hishel
@@ -175,6 +175,16 @@ Help us grow and continue developing good software for you ❤️
175
175
 
176
176
  # Changelog
177
177
 
178
+ ## 0.0.32 (27th Sep, 2024)
179
+
180
+ - Don't raise an exception if the `Date` header is not present. (#273)
181
+
182
+ ## 0.0.31 (22nd Sep, 2024)
183
+
184
+ - Ignore file not found error when cleaning up a file storage. (#264)
185
+ - Fix `AssertionError` on `client.close()` when use SQLiteStorage. (#269)
186
+ - Fix ignored flags when use `force_cache`. (#271)
187
+
178
188
  ## 0.0.30 (12th July, 2024)
179
189
 
180
190
  - Fix cache update on revalidation response with content (rfc9111 section 4.3.3) (#239)
@@ -1,5 +1,5 @@
1
- hishel/__init__.py,sha256=vDMrMrHiyMMr2z2_oc3HOjU8ZKDKx5t0b-U9lfo-IBg,369
2
- hishel/_controller.py,sha256=W5ad2herTHmMQ9dkUe6kcfc_AIpBID3CtwW1xh2aTpc,15875
1
+ hishel/__init__.py,sha256=H002jQK0-tviX35x2lvz1TftDXsTEb4zDBh4h9PHABY,369
2
+ hishel/_controller.py,sha256=se09qx7f_xR3T-oQvvmICrv3oIgQcYMiCXyRh2OADOM,16038
3
3
  hishel/_exceptions.py,sha256=qbg55RNlzwhv5JreWY9Zog_zmmiKdn5degtqJKijuRs,198
4
4
  hishel/_files.py,sha256=7J5uX7Nnzd7QQWfYuDGh8v6XGLG3eUDBjoJZ4aTaY1c,2228
5
5
  hishel/_headers.py,sha256=TWuHi7sRoeS2xxdNGujKmqWtgncUqfhNGCgHKYpRU-I,7329
@@ -13,15 +13,15 @@ hishel/_async/__init__.py,sha256=_oAltH4emAtUF7_9SSxz_KKGYzSXL34o_EGgGvoPG7E,187
13
13
  hishel/_async/_client.py,sha256=AkVSSbNTTHmK0gX6PRYVQ-3aDbuCX2Im4VKbLkwLiBU,1101
14
14
  hishel/_async/_mock.py,sha256=995v9p5xiw3svGSOJATkLMqwodlhZhcwmGygLHM2VFw,1515
15
15
  hishel/_async/_pool.py,sha256=li-921qyGzrV7SVUOUlMI0KE7IRsupSkE5iApzxmgqk,8175
16
- hishel/_async/_storages.py,sha256=1VAuUaXGFPzYEuj0LgR644k1V0w3pgqVeCAvEhGA8Y8,28550
16
+ hishel/_async/_storages.py,sha256=SPWifKGSGAFP2wMFoxZf5weZFbuVgHFciyglY6Hb6fc,28699
17
17
  hishel/_async/_transports.py,sha256=moeH-eQLJHkMp83NnScgsQTSQntDCR1_4A1ByZ_fXjk,11174
18
18
  hishel/_sync/__init__.py,sha256=_oAltH4emAtUF7_9SSxz_KKGYzSXL34o_EGgGvoPG7E,187
19
19
  hishel/_sync/_client.py,sha256=O-gwm9DsveKtSFUfqdbBB-3I1FmXr5rE-uQ7X5frwDA,1060
20
20
  hishel/_sync/_mock.py,sha256=im88tZr-XhP9BpzvIt3uOjndAlNcJvFP7Puv3H-6lKU,1430
21
21
  hishel/_sync/_pool.py,sha256=VcAknzyAL2i4-zcyE2fOTmTjfBZ2wkBVNYTvSw0OjVQ,7940
22
- hishel/_sync/_storages.py,sha256=NCV5kaQ4z-4L0TKS7HEpWSPHdf5NLytmFB04TMPXnc0,27760
22
+ hishel/_sync/_storages.py,sha256=RYzYXqnv0o2JO3RoEmlEUp0yOg_ungXfz4dLN7UTpIQ,27909
23
23
  hishel/_sync/_transports.py,sha256=G3_8SdPwlnrHZRvE1gqFLE4oZadVqNgg5mvxghDMih0,10838
24
- hishel-0.0.30.dist-info/METADATA,sha256=ec6bxYRQ1Ona8399QWoiGr1rimdCLhH8CfzEPqolwP0,11248
25
- hishel-0.0.30.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
26
- hishel-0.0.30.dist-info/licenses/LICENSE,sha256=1qQj7pE0V2O9OIedvyOgLGLvZLaPd3nFEup3IBEOZjQ,1493
27
- hishel-0.0.30.dist-info/RECORD,,
24
+ hishel-0.0.32.dist-info/METADATA,sha256=7YzjYw0A7BojC44b7J7IKqxd_1_-crwZJiKsNwViil0,11578
25
+ hishel-0.0.32.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
26
+ hishel-0.0.32.dist-info/licenses/LICENSE,sha256=1qQj7pE0V2O9OIedvyOgLGLvZLaPd3nFEup3IBEOZjQ,1493
27
+ hishel-0.0.32.dist-info/RECORD,,