Skip to content

Commit 80ebc8a

Browse files
committed
Upgrade CacheControl to 0.14.0
1 parent f18bebd commit 80ebc8a

File tree

9 files changed

+27
-81
lines changed

9 files changed

+27
-81
lines changed

news/CacheControl.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade CacheControl to 0.14.0

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ distro = []
144144
setuptools = "pkg_resources"
145145

146146
[tool.vendoring.license.fallback-urls]
147-
CacheControl = "https://raw.githubusercontent.com/ionrock/cachecontrol/v0.12.6/LICENSE.txt"
148147
distlib = "https://bitbucket.org/pypa/distlib/raw/master/LICENSE.txt"
149148
webencodings = "https://github.com/SimonSapin/python-webencodings/raw/master/LICENSE"
150149

src/pip/_vendor/cachecontrol/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99
__author__ = "Eric Larson"
1010
__email__ = "[email protected]"
11-
__version__ = "0.13.1"
11+
__version__ = "0.14.0"
1212

1313
from pip._vendor.cachecontrol.adapter import CacheControlAdapter
1414
from pip._vendor.cachecontrol.controller import CacheController

src/pip/_vendor/cachecontrol/adapter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,21 @@ def build_response(
125125
else:
126126
# Wrap the response file with a wrapper that will cache the
127127
# 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]
130130
functools.partial(
131131
self.controller.cache_response, request, response
132132
),
133133
)
134134
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
136136

137137
def _update_chunk_length(self: HTTPResponse) -> None:
138138
super_update_chunk_length()
139139
if self.chunk_left == 0:
140-
self._fp._close() # type: ignore[attr-defined]
140+
self._fp._close() # type: ignore[union-attr]
141141

142-
response._update_chunk_length = types.MethodType( # type: ignore[attr-defined]
142+
response._update_chunk_length = types.MethodType( # type: ignore[method-assign]
143143
_update_chunk_length, response
144144
)
145145

src/pip/_vendor/cachecontrol/caches/file_cache.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import hashlib
77
import os
88
from textwrap import dedent
9-
from typing import IO, TYPE_CHECKING
9+
from typing import IO, TYPE_CHECKING, Union
10+
from pathlib import Path
1011

1112
from pip._vendor.cachecontrol.cache import BaseCache, SeparateBodyBaseCache
1213
from pip._vendor.cachecontrol.controller import CacheController
@@ -63,7 +64,7 @@ class _FileCacheMixin:
6364

6465
def __init__(
6566
self,
66-
directory: str,
67+
directory: str | Path,
6768
forever: bool = False,
6869
filemode: int = 0o0600,
6970
dirmode: int = 0o0700,
@@ -79,7 +80,7 @@ def __init__(
7980
"""
8081
NOTE: In order to use the FileCache you must have
8182
filelock installed. You can install it via pip:
82-
pip install filelock
83+
pip install cachecontrol[filecache]
8384
"""
8485
)
8586
raise ImportError(notice)

src/pip/_vendor/cachecontrol/controller.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ def _load_from_cache(self, request: PreparedRequest) -> HTTPResponse | None:
142142
"""
143143
Load a cached response, or return None if it's not available.
144144
"""
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+
145150
cache_url = request.url
146151
assert cache_url is not None
147152
cache_data = self.cache.get(cache_url)
@@ -480,7 +485,7 @@ def update_cached_response(
480485
cached_response.headers.update(
481486
{
482487
k: v
483-
for k, v in response.headers.items() # type: ignore[no-untyped-call]
488+
for k, v in response.headers.items()
484489
if k.lower() not in excluded_headers
485490
}
486491
)

src/pip/_vendor/cachecontrol/heuristics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def update_headers(self, response: HTTPResponse) -> dict[str, str]:
6868

6969
if "expires" not in response.headers:
7070
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]
7272
headers["expires"] = datetime_to_header(expires)
7373
headers["cache-control"] = "public"
7474
return headers

src/pip/_vendor/cachecontrol/serialize.py

Lines changed: 8 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ def dumps(
3232
# also update the response with a new file handler to be
3333
# sure it acts as though it was never read.
3434
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]
3636
response.length_remaining = len(body)
3737

3838
data = {
3939
"response": {
4040
"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()},
4242
"status": response.status,
4343
"version": response.version,
4444
"reason": str(response.reason),
@@ -72,31 +72,14 @@ def loads(
7272
if not data:
7373
return None
7474

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()):
9878
return None
9979

80+
data = data[5:]
81+
return self._loads_v4(request, data, body_file)
82+
10083
def prepare_response(
10184
self,
10285
request: PreparedRequest,
@@ -149,49 +132,6 @@ def prepare_response(
149132

150133
return HTTPResponse(body=body, preload_content=False, **cached["response"])
151134

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-
195135
def _loads_v4(
196136
self,
197137
request: PreparedRequest,

src/pip/_vendor/vendor.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CacheControl==0.13.1 # Make sure to update the license in pyproject.toml for this.
1+
CacheControl==0.14.0
22
colorama==0.4.6
33
distlib==0.3.8
44
distro==1.9.0

0 commit comments

Comments
 (0)