Skip to content

Commit a86d7d6

Browse files
committed
Update CacheControl to 0.13.1.
1 parent a64df68 commit a86d7d6

File tree

12 files changed

+149
-176
lines changed

12 files changed

+149
-176
lines changed

src/pip/_vendor/cachecontrol/__init__.py

+1-1
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.0"
11+
__version__ = "0.13.1"
1212

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

src/pip/_vendor/cachecontrol/_cmd.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2015 Eric Larson
22
#
33
# SPDX-License-Identifier: Apache-2.0
4+
from __future__ import annotations
45

56
import logging
67
from argparse import ArgumentParser
@@ -36,7 +37,7 @@ def get_session() -> requests.Session:
3637
return sess
3738

3839

39-
def get_args() -> "Namespace":
40+
def get_args() -> Namespace:
4041
parser = ArgumentParser()
4142
parser.add_argument("url", help="The URL to try and cache")
4243
return parser.parse_args()
@@ -53,7 +54,7 @@ def main() -> None:
5354
setup_logging()
5455

5556
# try setting the cache
56-
cache_controller: "CacheController" = (
57+
cache_controller: CacheController = (
5758
sess.cache_controller # type: ignore[attr-defined]
5859
)
5960
cache_controller.cache_response(resp.request, resp.raw)

src/pip/_vendor/cachecontrol/adapter.py

+23-28
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# SPDX-FileCopyrightText: 2015 Eric Larson
22
#
33
# SPDX-License-Identifier: Apache-2.0
4+
from __future__ import annotations
45

56
import functools
67
import types
78
import zlib
8-
from typing import TYPE_CHECKING, Any, Collection, Mapping, Optional, Tuple, Type, Union
9+
from typing import TYPE_CHECKING, Any, Collection, Mapping
910

1011
from pip._vendor.requests.adapters import HTTPAdapter
1112

@@ -27,16 +28,16 @@ class CacheControlAdapter(HTTPAdapter):
2728

2829
def __init__(
2930
self,
30-
cache: Optional["BaseCache"] = None,
31+
cache: BaseCache | None = None,
3132
cache_etags: bool = True,
32-
controller_class: Optional[Type[CacheController]] = None,
33-
serializer: Optional["Serializer"] = None,
34-
heuristic: Optional["BaseHeuristic"] = None,
35-
cacheable_methods: Optional[Collection[str]] = None,
33+
controller_class: type[CacheController] | None = None,
34+
serializer: Serializer | None = None,
35+
heuristic: BaseHeuristic | None = None,
36+
cacheable_methods: Collection[str] | None = None,
3637
*args: Any,
3738
**kw: Any,
3839
) -> None:
39-
super(CacheControlAdapter, self).__init__(*args, **kw)
40+
super().__init__(*args, **kw)
4041
self.cache = DictCache() if cache is None else cache
4142
self.heuristic = heuristic
4243
self.cacheable_methods = cacheable_methods or ("GET",)
@@ -48,16 +49,14 @@ def __init__(
4849

4950
def send(
5051
self,
51-
request: "PreparedRequest",
52+
request: PreparedRequest,
5253
stream: bool = False,
53-
timeout: Union[None, float, Tuple[float, float], Tuple[float, None]] = None,
54-
verify: Union[bool, str] = True,
55-
cert: Union[
56-
None, bytes, str, Tuple[Union[bytes, str], Union[bytes, str]]
57-
] = None,
58-
proxies: Optional[Mapping[str, str]] = None,
59-
cacheable_methods: Optional[Collection[str]] = None,
60-
) -> "Response":
54+
timeout: None | float | tuple[float, float] | tuple[float, None] = None,
55+
verify: bool | str = True,
56+
cert: (None | bytes | str | tuple[bytes | str, bytes | str]) = None,
57+
proxies: Mapping[str, str] | None = None,
58+
cacheable_methods: Collection[str] | None = None,
59+
) -> Response:
6160
"""
6261
Send a request. Use the request information to see if it
6362
exists in the cache and cache the response if we need to and can.
@@ -74,19 +73,17 @@ def send(
7473
# check for etags and add headers if appropriate
7574
request.headers.update(self.controller.conditional_headers(request))
7675

77-
resp = super(CacheControlAdapter, self).send(
78-
request, stream, timeout, verify, cert, proxies
79-
)
76+
resp = super().send(request, stream, timeout, verify, cert, proxies)
8077

8178
return resp
8279

8380
def build_response(
8481
self,
85-
request: "PreparedRequest",
86-
response: "HTTPResponse",
82+
request: PreparedRequest,
83+
response: HTTPResponse,
8784
from_cache: bool = False,
88-
cacheable_methods: Optional[Collection[str]] = None,
89-
) -> "Response":
85+
cacheable_methods: Collection[str] | None = None,
86+
) -> Response:
9087
"""
9188
Build a response by making a request or using the cache.
9289
@@ -137,7 +134,7 @@ def build_response(
137134
if response.chunked:
138135
super_update_chunk_length = response._update_chunk_length # type: ignore[attr-defined]
139136

140-
def _update_chunk_length(self: "HTTPResponse") -> None:
137+
def _update_chunk_length(self: HTTPResponse) -> None:
141138
super_update_chunk_length()
142139
if self.chunk_left == 0:
143140
self._fp._close() # type: ignore[attr-defined]
@@ -146,9 +143,7 @@ def _update_chunk_length(self: "HTTPResponse") -> None:
146143
_update_chunk_length, response
147144
)
148145

149-
resp: "Response" = super( # type: ignore[no-untyped-call]
150-
CacheControlAdapter, self
151-
).build_response(request, response)
146+
resp: Response = super().build_response(request, response) # type: ignore[no-untyped-call]
152147

153148
# See if we should invalidate the cache.
154149
if request.method in self.invalidating_methods and resp.ok:
@@ -163,4 +158,4 @@ def _update_chunk_length(self: "HTTPResponse") -> None:
163158

164159
def close(self) -> None:
165160
self.cache.close()
166-
super(CacheControlAdapter, self).close() # type: ignore[no-untyped-call]
161+
super().close() # type: ignore[no-untyped-call]

src/pip/_vendor/cachecontrol/cache.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
The cache object API for implementing caches. The default is a thread
77
safe in-memory dictionary.
88
"""
9+
from __future__ import annotations
10+
911
from threading import Lock
10-
from typing import IO, TYPE_CHECKING, MutableMapping, Optional, Union
12+
from typing import IO, TYPE_CHECKING, MutableMapping
1113

1214
if TYPE_CHECKING:
1315
from datetime import datetime
1416

1517

16-
class BaseCache(object):
17-
def get(self, key: str) -> Optional[bytes]:
18+
class BaseCache:
19+
def get(self, key: str) -> bytes | None:
1820
raise NotImplementedError()
1921

2022
def set(
21-
self, key: str, value: bytes, expires: Optional[Union[int, "datetime"]] = None
23+
self, key: str, value: bytes, expires: int | datetime | None = None
2224
) -> None:
2325
raise NotImplementedError()
2426

@@ -30,15 +32,15 @@ def close(self) -> None:
3032

3133

3234
class DictCache(BaseCache):
33-
def __init__(self, init_dict: Optional[MutableMapping[str, bytes]] = None) -> None:
35+
def __init__(self, init_dict: MutableMapping[str, bytes] | None = None) -> None:
3436
self.lock = Lock()
3537
self.data = init_dict or {}
3638

37-
def get(self, key: str) -> Optional[bytes]:
39+
def get(self, key: str) -> bytes | None:
3840
return self.data.get(key, None)
3941

4042
def set(
41-
self, key: str, value: bytes, expires: Optional[Union[int, "datetime"]] = None
43+
self, key: str, value: bytes, expires: int | datetime | None = None
4244
) -> None:
4345
with self.lock:
4446
self.data.update({key: value})
@@ -65,7 +67,7 @@ class SeparateBodyBaseCache(BaseCache):
6567
def set_body(self, key: str, body: bytes) -> None:
6668
raise NotImplementedError()
6769

68-
def get_body(self, key: str) -> Optional["IO[bytes]"]:
70+
def get_body(self, key: str) -> IO[bytes] | None:
6971
"""
7072
Return the body as file-like object.
7173
"""

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# SPDX-FileCopyrightText: 2015 Eric Larson
22
#
33
# SPDX-License-Identifier: Apache-2.0
4+
from __future__ import annotations
45

56
import hashlib
67
import os
78
from textwrap import dedent
8-
from typing import IO, TYPE_CHECKING, Optional, Type, Union
9+
from typing import IO, TYPE_CHECKING
910

1011
from pip._vendor.cachecontrol.cache import BaseCache, SeparateBodyBaseCache
1112
from pip._vendor.cachecontrol.controller import CacheController
@@ -16,7 +17,7 @@
1617
from filelock import BaseFileLock
1718

1819

19-
def _secure_open_write(filename: str, fmode: int) -> "IO[bytes]":
20+
def _secure_open_write(filename: str, fmode: int) -> IO[bytes]:
2021
# We only want to write to this file, so open it in write only mode
2122
flags = os.O_WRONLY
2223

@@ -39,7 +40,7 @@ def _secure_open_write(filename: str, fmode: int) -> "IO[bytes]":
3940
# there
4041
try:
4142
os.remove(filename)
42-
except (IOError, OSError):
43+
except OSError:
4344
# The file must not exist already, so we can just skip ahead to opening
4445
pass
4546

@@ -66,7 +67,7 @@ def __init__(
6667
forever: bool = False,
6768
filemode: int = 0o0600,
6869
dirmode: int = 0o0700,
69-
lock_class: Optional[Type["BaseFileLock"]] = None,
70+
lock_class: type[BaseFileLock] | None = None,
7071
) -> None:
7172
try:
7273
if lock_class is None:
@@ -100,7 +101,7 @@ def _fn(self, name: str) -> str:
100101
parts = list(hashed[:5]) + [hashed]
101102
return os.path.join(self.directory, *parts)
102103

103-
def get(self, key: str) -> Optional[bytes]:
104+
def get(self, key: str) -> bytes | None:
104105
name = self._fn(key)
105106
try:
106107
with open(name, "rb") as fh:
@@ -110,7 +111,7 @@ def get(self, key: str) -> Optional[bytes]:
110111
return None
111112

112113
def set(
113-
self, key: str, value: bytes, expires: Optional[Union[int, "datetime"]] = None
114+
self, key: str, value: bytes, expires: int | datetime | None = None
114115
) -> None:
115116
name = self._fn(key)
116117
self._write(name, value)
@@ -122,7 +123,7 @@ def _write(self, path: str, data: bytes) -> None:
122123
# Make sure the directory exists
123124
try:
124125
os.makedirs(os.path.dirname(path), self.dirmode)
125-
except (IOError, OSError):
126+
except OSError:
126127
pass
127128

128129
with self.lock_class(path + ".lock"):
@@ -155,7 +156,7 @@ class SeparateBodyFileCache(_FileCacheMixin, SeparateBodyBaseCache):
155156
peak memory usage.
156157
"""
157158

158-
def get_body(self, key: str) -> Optional["IO[bytes]"]:
159+
def get_body(self, key: str) -> IO[bytes] | None:
159160
name = self._fn(key) + ".body"
160161
try:
161162
return open(name, "rb")

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# SPDX-FileCopyrightText: 2015 Eric Larson
22
#
33
# SPDX-License-Identifier: Apache-2.0
4+
from __future__ import annotations
45

5-
from __future__ import division
66

77
from datetime import datetime, timezone
8-
from typing import TYPE_CHECKING, Optional, Union
8+
from typing import TYPE_CHECKING
99

1010
from pip._vendor.cachecontrol.cache import BaseCache
1111

@@ -14,14 +14,14 @@
1414

1515

1616
class RedisCache(BaseCache):
17-
def __init__(self, conn: "Redis[bytes]") -> None:
17+
def __init__(self, conn: Redis[bytes]) -> None:
1818
self.conn = conn
1919

20-
def get(self, key: str) -> Optional[bytes]:
20+
def get(self, key: str) -> bytes | None:
2121
return self.conn.get(key)
2222

2323
def set(
24-
self, key: str, value: bytes, expires: Optional[Union[int, datetime]] = None
24+
self, key: str, value: bytes, expires: int | datetime | None = None
2525
) -> None:
2626
if not expires:
2727
self.conn.set(key, value)

0 commit comments

Comments
 (0)