CacheControl 0.13.1__py3-none-any.whl → 0.14.0__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.
cachecontrol/__init__.py CHANGED
@@ -8,7 +8,7 @@ Make it easy to import from cachecontrol without long namespaces.
8
8
  """
9
9
  __author__ = "Eric Larson"
10
10
  __email__ = "eric@ionrock.org"
11
- __version__ = "0.13.1"
11
+ __version__ = "0.14.0"
12
12
 
13
13
  from cachecontrol.adapter import CacheControlAdapter
14
14
  from cachecontrol.controller import CacheController
cachecontrol/adapter.py CHANGED
@@ -125,21 +125,21 @@ class CacheControlAdapter(HTTPAdapter):
125
125
  else:
126
126
  # Wrap the response file with a wrapper that will cache the
127
127
  # response when the stream has been consumed.
128
- response._fp = CallbackFileWrapper( # type: ignore[attr-defined]
129
- response._fp, # type: ignore[attr-defined]
128
+ response._fp = CallbackFileWrapper( # type: ignore[assignment]
129
+ response._fp, # type: ignore[arg-type]
130
130
  functools.partial(
131
131
  self.controller.cache_response, request, response
132
132
  ),
133
133
  )
134
134
  if response.chunked:
135
- super_update_chunk_length = response._update_chunk_length # type: ignore[attr-defined]
135
+ super_update_chunk_length = response._update_chunk_length
136
136
 
137
137
  def _update_chunk_length(self: HTTPResponse) -> None:
138
138
  super_update_chunk_length()
139
139
  if self.chunk_left == 0:
140
- self._fp._close() # type: ignore[attr-defined]
140
+ self._fp._close() # type: ignore[union-attr]
141
141
 
142
- response._update_chunk_length = types.MethodType( # type: ignore[attr-defined]
142
+ response._update_chunk_length = types.MethodType( # type: ignore[method-assign]
143
143
  _update_chunk_length, response
144
144
  )
145
145
 
@@ -6,7 +6,8 @@ from __future__ import annotations
6
6
  import hashlib
7
7
  import os
8
8
  from textwrap import dedent
9
- from typing import IO, TYPE_CHECKING
9
+ from typing import IO, TYPE_CHECKING, Union
10
+ from pathlib import Path
10
11
 
11
12
  from cachecontrol.cache import BaseCache, SeparateBodyBaseCache
12
13
  from cachecontrol.controller import CacheController
@@ -63,7 +64,7 @@ class _FileCacheMixin:
63
64
 
64
65
  def __init__(
65
66
  self,
66
- directory: str,
67
+ directory: str | Path,
67
68
  forever: bool = False,
68
69
  filemode: int = 0o0600,
69
70
  dirmode: int = 0o0700,
@@ -79,7 +80,7 @@ class _FileCacheMixin:
79
80
  """
80
81
  NOTE: In order to use the FileCache you must have
81
82
  filelock installed. You can install it via pip:
82
- pip install filelock
83
+ pip install cachecontrol[filecache]
83
84
  """
84
85
  )
85
86
  raise ImportError(notice)
@@ -142,6 +142,11 @@ class CacheController:
142
142
  """
143
143
  Load a cached response, or return None if it's not available.
144
144
  """
145
+ # We do not support caching of partial content: so if the request contains a
146
+ # Range header then we don't want to load anything from the cache.
147
+ if "Range" in request.headers:
148
+ return None
149
+
145
150
  cache_url = request.url
146
151
  assert cache_url is not None
147
152
  cache_data = self.cache.get(cache_url)
@@ -480,7 +485,7 @@ class CacheController:
480
485
  cached_response.headers.update(
481
486
  {
482
487
  k: v
483
- for k, v in response.headers.items() # type: ignore[no-untyped-call]
488
+ for k, v in response.headers.items()
484
489
  if k.lower() not in excluded_headers
485
490
  }
486
491
  )
@@ -68,7 +68,7 @@ class OneDayCache(BaseHeuristic):
68
68
 
69
69
  if "expires" not in response.headers:
70
70
  date = parsedate(response.headers["date"])
71
- expires = expire_after(timedelta(days=1), date=datetime(*date[:6], tzinfo=timezone.utc)) # type: ignore[misc]
71
+ expires = expire_after(timedelta(days=1), date=datetime(*date[:6], tzinfo=timezone.utc)) # type: ignore[index,misc]
72
72
  headers["expires"] = datetime_to_header(expires)
73
73
  headers["cache-control"] = "public"
74
74
  return headers
cachecontrol/serialize.py CHANGED
@@ -32,13 +32,13 @@ class Serializer:
32
32
  # also update the response with a new file handler to be
33
33
  # sure it acts as though it was never read.
34
34
  body = response.read(decode_content=False)
35
- response._fp = io.BytesIO(body) # type: ignore[attr-defined]
35
+ response._fp = io.BytesIO(body) # type: ignore[assignment]
36
36
  response.length_remaining = len(body)
37
37
 
38
38
  data = {
39
39
  "response": {
40
40
  "body": body, # Empty bytestring if body is stored separately
41
- "headers": {str(k): str(v) for k, v in response.headers.items()}, # type: ignore[no-untyped-call]
41
+ "headers": {str(k): str(v) for k, v in response.headers.items()},
42
42
  "status": response.status,
43
43
  "version": response.version,
44
44
  "reason": str(response.reason),
@@ -72,31 +72,14 @@ class Serializer:
72
72
  if not data:
73
73
  return None
74
74
 
75
- # Determine what version of the serializer the data was serialized
76
- # with
77
- try:
78
- ver, data = data.split(b",", 1)
79
- except ValueError:
80
- ver = b"cc=0"
81
-
82
- # Make sure that our "ver" is actually a version and isn't a false
83
- # positive from a , being in the data stream.
84
- if ver[:3] != b"cc=":
85
- data = ver + data
86
- ver = b"cc=0"
87
-
88
- # Get the version number out of the cc=N
89
- verstr = ver.split(b"=", 1)[-1].decode("ascii")
90
-
91
- # Dispatch to the actual load method for the given version
92
- try:
93
- return getattr(self, f"_loads_v{verstr}")(request, data, body_file) # type: ignore[no-any-return]
94
-
95
- except AttributeError:
96
- # This is a version we don't have a loads function for, so we'll
97
- # just treat it as a miss and return None
75
+ # Previous versions of this library supported other serialization
76
+ # formats, but these have all been removed.
77
+ if not data.startswith(f"cc={self.serde_version},".encode()):
98
78
  return None
99
79
 
80
+ data = data[5:]
81
+ return self._loads_v4(request, data, body_file)
82
+
100
83
  def prepare_response(
101
84
  self,
102
85
  request: PreparedRequest,
@@ -149,49 +132,6 @@ class Serializer:
149
132
 
150
133
  return HTTPResponse(body=body, preload_content=False, **cached["response"])
151
134
 
152
- def _loads_v0(
153
- self,
154
- request: PreparedRequest,
155
- data: bytes,
156
- body_file: IO[bytes] | None = None,
157
- ) -> None:
158
- # The original legacy cache data. This doesn't contain enough
159
- # information to construct everything we need, so we'll treat this as
160
- # a miss.
161
- return None
162
-
163
- def _loads_v1(
164
- self,
165
- request: PreparedRequest,
166
- data: bytes,
167
- body_file: IO[bytes] | None = None,
168
- ) -> HTTPResponse | None:
169
- # The "v1" pickled cache format. This is no longer supported
170
- # for security reasons, so we treat it as a miss.
171
- return None
172
-
173
- def _loads_v2(
174
- self,
175
- request: PreparedRequest,
176
- data: bytes,
177
- body_file: IO[bytes] | None = None,
178
- ) -> HTTPResponse | None:
179
- # The "v2" compressed base64 cache format.
180
- # This has been removed due to age and poor size/performance
181
- # characteristics, so we treat it as a miss.
182
- return None
183
-
184
- def _loads_v3(
185
- self,
186
- request: PreparedRequest,
187
- data: bytes,
188
- body_file: IO[bytes] | None = None,
189
- ) -> None:
190
- # Due to Python 2 encoding issues, it's impossible to know for sure
191
- # exactly how to load v3 entries, thus we'll treat these as a miss so
192
- # that they get rewritten out as v4 entries.
193
- return None
194
-
195
135
  def _loads_v4(
196
136
  self,
197
137
  request: PreparedRequest,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CacheControl
3
- Version: 0.13.1
3
+ Version: 0.14.0
4
4
  Summary: httplib2 caching for requests
5
5
  Keywords: requests,http,caching,web
6
6
  Author-email: Eric Larson <ericlarson@ionrock.com>, Frost Ming <me@frostming.com>, William Woodruff <william@yossarian.net>
@@ -10,15 +10,15 @@ Classifier: Development Status :: 4 - Beta
10
10
  Classifier: Environment :: Web Environment
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
12
  Classifier: Operating System :: OS Independent
13
- Classifier: Programming Language :: Python :: 3.6
14
13
  Classifier: Programming Language :: Python :: 3.7
15
14
  Classifier: Programming Language :: Python :: 3.8
16
15
  Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
18
17
  Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
19
  Classifier: Topic :: Internet :: WWW/HTTP
20
20
  Requires-Dist: requests >= 2.16.0
21
- Requires-Dist: msgpack >= 0.5.2
21
+ Requires-Dist: msgpack >= 0.5.2, < 2.0.0
22
22
  Requires-Dist: CacheControl[filecache,redis] ; extra == "dev"
23
23
  Requires-Dist: build ; extra == "dev"
24
24
  Requires-Dist: mypy ; extra == "dev"
@@ -27,6 +27,8 @@ Requires-Dist: pytest-cov ; extra == "dev"
27
27
  Requires-Dist: pytest ; extra == "dev"
28
28
  Requires-Dist: cherrypy ; extra == "dev"
29
29
  Requires-Dist: sphinx ; extra == "dev"
30
+ Requires-Dist: furo ; extra == "dev"
31
+ Requires-Dist: sphinx-copybutton ; extra == "dev"
30
32
  Requires-Dist: black ; extra == "dev"
31
33
  Requires-Dist: types-redis ; extra == "dev"
32
34
  Requires-Dist: types-requests ; extra == "dev"
@@ -76,7 +78,7 @@ Quickstart
76
78
  sess = requests.session()
77
79
  cached_sess = CacheControl(sess)
78
80
 
79
- response = cached_sess.get('http://google.com')
81
+ response = cached_sess.get('https://google.com')
80
82
 
81
83
  If the URL contains any caching based headers, it will cache the
82
84
  result in a simple dictionary.
@@ -0,0 +1,18 @@
1
+ cachecontrol/__init__.py,sha256=SMGrJRpX7KUHcXGkaeWdDgI7dI1XAXzNPOir-i6KmcQ,640
2
+ cachecontrol/_cmd.py,sha256=4l2UbK9N85Vr_KTkF4LjvSlsr-TZnOXTfT2NODlIMtc,1672
3
+ cachecontrol/adapter.py,sha256=45loQAiioWqu4LMtMwtMOkfbxAgoQb3HVnsl-pmjouA,6247
4
+ cachecontrol/cache.py,sha256=OTQj72tUf8C1uEgczdl3Gc8vkldSzsTITKtDGKMx4z8,1952
5
+ cachecontrol/controller.py,sha256=Mn_xrzRWwvfU8iWvQJbsIyvhVSm9Rwlb69FeSGce90k,18503
6
+ cachecontrol/filewrapper.py,sha256=STttGmIPBvZzt2b51dUOwoWX5crcMCpKZOisM3f5BNc,4292
7
+ cachecontrol/heuristics.py,sha256=0FgcTfzFRQ9kUQFirhY3LOIg5wBWUsCBuxx_GGr_UuQ,4822
8
+ cachecontrol/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ cachecontrol/serialize.py,sha256=dP5k_UKYUAano6TKG9qlbKHbFMonz0AV_lYR3IFCGMg,5110
10
+ cachecontrol/wrapper.py,sha256=KyaQ4Bq1RqsX-zA4pXH62nmcU511ECIGn5gCvmNIj20,1328
11
+ cachecontrol/caches/__init__.py,sha256=3-BaJBXjdt-4iFbv-799XjzRBsd6zF9wOEqOdDuAAro,279
12
+ cachecontrol/caches/file_cache.py,sha256=ylcOG9re-vjxiBi6Dm_wNP-KyK_i0NIop1OqHMAz460,5382
13
+ cachecontrol/caches/redis_cache.py,sha256=94Qw4INGwjHcCDwMnOe0gbbcP2fttrlui-e1-Yutclw,1374
14
+ cachecontrol-0.14.0.dist-info/entry_points.txt,sha256=1NtpBDZSbqMMbkIxhMBtvQoF7c5Mmfd7EE9hBPG_sLs,54
15
+ cachecontrol-0.14.0.dist-info/LICENSE.txt,sha256=hu7uh74qQ_P_H1ZJb0UfaSQ5JvAl_tuwM2ZsMExMFhs,558
16
+ cachecontrol-0.14.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
17
+ cachecontrol-0.14.0.dist-info/METADATA,sha256=oLjmqL8HBxsz7qNjhDDhuRMaL_kfJbw4ED70tnNPCTk,3071
18
+ cachecontrol-0.14.0.dist-info/RECORD,,
@@ -1,18 +0,0 @@
1
- cachecontrol/__init__.py,sha256=-GucWqD2JAx5hnVD1bu0hNg4-CjvRBhch2KnwU6XRGA,640
2
- cachecontrol/_cmd.py,sha256=4l2UbK9N85Vr_KTkF4LjvSlsr-TZnOXTfT2NODlIMtc,1672
3
- cachecontrol/adapter.py,sha256=MqwP6wSMlKgBXWtuEmlyYIMIRv8fwCZfD9XN2venlRM,6284
4
- cachecontrol/cache.py,sha256=OTQj72tUf8C1uEgczdl3Gc8vkldSzsTITKtDGKMx4z8,1952
5
- cachecontrol/controller.py,sha256=tAyNCqaYZBwXotIieVpi8Z8tdJpg3peJOJ250yTUmRU,18312
6
- cachecontrol/filewrapper.py,sha256=STttGmIPBvZzt2b51dUOwoWX5crcMCpKZOisM3f5BNc,4292
7
- cachecontrol/heuristics.py,sha256=3bA6o4ZJLB8_0hrnuAxrzY2SW8N4QunLXPx6WTM25jM,4816
8
- cachecontrol/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- cachecontrol/serialize.py,sha256=NKpSJIFewDyaYp7LNUPZ2vGj0-OCK577YUCkEFrYVT4,7120
10
- cachecontrol/wrapper.py,sha256=KyaQ4Bq1RqsX-zA4pXH62nmcU511ECIGn5gCvmNIj20,1328
11
- cachecontrol/caches/__init__.py,sha256=3-BaJBXjdt-4iFbv-799XjzRBsd6zF9wOEqOdDuAAro,279
12
- cachecontrol/caches/file_cache.py,sha256=2iI-brN23Ci8x2jt8P3YvNPlWMuIiq3GWBCheXVKpgI,5328
13
- cachecontrol/caches/redis_cache.py,sha256=94Qw4INGwjHcCDwMnOe0gbbcP2fttrlui-e1-Yutclw,1374
14
- cachecontrol-0.13.1.dist-info/entry_points.txt,sha256=1NtpBDZSbqMMbkIxhMBtvQoF7c5Mmfd7EE9hBPG_sLs,54
15
- cachecontrol-0.13.1.dist-info/LICENSE.txt,sha256=hu7uh74qQ_P_H1ZJb0UfaSQ5JvAl_tuwM2ZsMExMFhs,558
16
- cachecontrol-0.13.1.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
17
- cachecontrol-0.13.1.dist-info/METADATA,sha256=Go06dZMWk57cNRnQjMpgACL1Pjz8HCZH1CmO0pJgsFk,2973
18
- cachecontrol-0.13.1.dist-info/RECORD,,