Skip to content

Commit c757d52

Browse files
authored
Merge pull request #13269 from ichard26/25.1-vendoring
2 parents 2d77214 + 740069b commit c757d52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+254
-277
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.2

news/certifi.vendor.rst

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

news/pygments.vendor.rst

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

src/pip/_vendor/cachecontrol/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
__author__ = "Eric Larson"
1111
__email__ = "[email protected]"
12-
__version__ = "0.14.1"
12+
__version__ = "0.14.2"
1313

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

src/pip/_vendor/cachecontrol/adapter.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import functools
77
import types
8+
import weakref
89
import zlib
910
from typing import TYPE_CHECKING, Any, Collection, Mapping
1011

@@ -128,19 +129,25 @@ def build_response( # type: ignore[override]
128129
response._fp = CallbackFileWrapper( # type: ignore[assignment]
129130
response._fp, # type: ignore[arg-type]
130131
functools.partial(
131-
self.controller.cache_response, request, response
132+
self.controller.cache_response, request, weakref.ref(response)
132133
),
133134
)
134135
if response.chunked:
135-
super_update_chunk_length = response._update_chunk_length
136+
super_update_chunk_length = response.__class__._update_chunk_length
136137

137-
def _update_chunk_length(self: HTTPResponse) -> None:
138-
super_update_chunk_length()
138+
def _update_chunk_length(
139+
weak_self: weakref.ReferenceType[HTTPResponse],
140+
) -> None:
141+
self = weak_self()
142+
if self is None:
143+
return
144+
145+
super_update_chunk_length(self)
139146
if self.chunk_left == 0:
140147
self._fp._close() # type: ignore[union-attr]
141148

142-
response._update_chunk_length = types.MethodType( # type: ignore[method-assign]
143-
_update_chunk_length, response
149+
response._update_chunk_length = functools.partial( # type: ignore[method-assign]
150+
_update_chunk_length, weakref.ref(response)
144151
)
145152

146153
resp: Response = super().build_response(request, response)

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

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import hashlib
77
import os
8+
import tempfile
89
from textwrap import dedent
910
from typing import IO, TYPE_CHECKING
1011
from pathlib import Path
@@ -18,47 +19,6 @@
1819
from filelock import BaseFileLock
1920

2021

21-
def _secure_open_write(filename: str, fmode: int) -> IO[bytes]:
22-
# We only want to write to this file, so open it in write only mode
23-
flags = os.O_WRONLY
24-
25-
# os.O_CREAT | os.O_EXCL will fail if the file already exists, so we only
26-
# will open *new* files.
27-
# We specify this because we want to ensure that the mode we pass is the
28-
# mode of the file.
29-
flags |= os.O_CREAT | os.O_EXCL
30-
31-
# Do not follow symlinks to prevent someone from making a symlink that
32-
# we follow and insecurely open a cache file.
33-
if hasattr(os, "O_NOFOLLOW"):
34-
flags |= os.O_NOFOLLOW
35-
36-
# On Windows we'll mark this file as binary
37-
if hasattr(os, "O_BINARY"):
38-
flags |= os.O_BINARY
39-
40-
# Before we open our file, we want to delete any existing file that is
41-
# there
42-
try:
43-
os.remove(filename)
44-
except OSError:
45-
# The file must not exist already, so we can just skip ahead to opening
46-
pass
47-
48-
# Open our file, the use of os.O_CREAT | os.O_EXCL will ensure that if a
49-
# race condition happens between the os.remove and this line, that an
50-
# error will be raised. Because we utilize a lockfile this should only
51-
# happen if someone is attempting to attack us.
52-
fd = os.open(filename, flags, fmode)
53-
try:
54-
return os.fdopen(fd, "wb")
55-
56-
except:
57-
# An error occurred wrapping our FD in a file object
58-
os.close(fd)
59-
raise
60-
61-
6222
class _FileCacheMixin:
6323
"""Shared implementation for both FileCache variants."""
6424

@@ -122,15 +82,18 @@ def _write(self, path: str, data: bytes) -> None:
12282
Safely write the data to the given path.
12383
"""
12484
# Make sure the directory exists
125-
try:
126-
os.makedirs(os.path.dirname(path), self.dirmode)
127-
except OSError:
128-
pass
85+
dirname = os.path.dirname(path)
86+
os.makedirs(dirname, self.dirmode, exist_ok=True)
12987

13088
with self.lock_class(path + ".lock"):
13189
# Write our actual file
132-
with _secure_open_write(path, self.filemode) as fh:
133-
fh.write(data)
90+
(fd, name) = tempfile.mkstemp(dir=dirname)
91+
try:
92+
os.write(fd, data)
93+
finally:
94+
os.close(fd)
95+
os.chmod(name, self.filemode)
96+
os.replace(name, path)
13497

13598
def _delete(self, key: str, suffix: str) -> None:
13699
name = self._fn(key) + suffix

src/pip/_vendor/cachecontrol/controller.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import logging
1313
import re
1414
import time
15+
import weakref
1516
from email.utils import parsedate_tz
1617
from typing import TYPE_CHECKING, Collection, Mapping
1718

@@ -323,7 +324,7 @@ def _cache_set(
323324
def cache_response(
324325
self,
325326
request: PreparedRequest,
326-
response: HTTPResponse,
327+
response_or_ref: HTTPResponse | weakref.ReferenceType[HTTPResponse],
327328
body: bytes | None = None,
328329
status_codes: Collection[int] | None = None,
329330
) -> None:
@@ -332,6 +333,16 @@ def cache_response(
332333
333334
This assumes a requests Response object.
334335
"""
336+
if isinstance(response_or_ref, weakref.ReferenceType):
337+
response = response_or_ref()
338+
if response is None:
339+
# The weakref can be None only in case the user used streamed request
340+
# and did not consume or close it, and holds no reference to requests.Response.
341+
# In such case, we don't want to cache the response.
342+
return
343+
else:
344+
response = response_or_ref
345+
335346
# From httplib2: Don't cache 206's since we aren't going to
336347
# handle byte range requests
337348
cacheable_status_codes = status_codes or self.cacheable_status_codes

src/pip/_vendor/certifi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .core import contents, where
22

33
__all__ = ["contents", "where"]
4-
__version__ = "2024.08.30"
4+
__version__ = "2025.01.31"

0 commit comments

Comments
 (0)