Skip to content

Commit

Permalink
Merge pull request #12670 from pradyunsg/vendoring-upgrade
Browse files Browse the repository at this point in the history
Upgrade various vendored dependencies
  • Loading branch information
pradyunsg committed May 4, 2024
2 parents bc84491 + d24ddc3 commit e8e592a
Show file tree
Hide file tree
Showing 42 changed files with 3,631 additions and 1,344 deletions.
1 change: 1 addition & 0 deletions news/CacheControl.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade CacheControl to 0.14.0
2 changes: 1 addition & 1 deletion news/idna.vendor.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Upgrade idna to 3.6
Upgrade idna to 3.7
2 changes: 1 addition & 1 deletion news/platformdirs.vendor.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Upgrade platformdirs to 4.2.0
Upgrade platformdirs to 4.2.1
1 change: 1 addition & 0 deletions news/pyparsing.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade pyparsing to 3.1.2
2 changes: 1 addition & 1 deletion news/rich.vendor.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Upgrade rich to 13.7.0
Upgrade rich to 13.7.1
2 changes: 1 addition & 1 deletion news/setuptools.vendor.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Upgrade setuptools to 69.1.1
Upgrade setuptools to 69.5.1
2 changes: 1 addition & 1 deletion news/typing_extensions.vendor.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Upgrade typing_extensions to 4.9.0
Upgrade typing_extensions to 4.11.0
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ distro = []
setuptools = "pkg_resources"

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

Expand Down
2 changes: 1 addition & 1 deletion src/pip/_vendor/cachecontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""
__author__ = "Eric Larson"
__email__ = "eric@ionrock.org"
__version__ = "0.13.1"
__version__ = "0.14.0"

from pip._vendor.cachecontrol.adapter import CacheControlAdapter
from pip._vendor.cachecontrol.controller import CacheController
Expand Down
10 changes: 5 additions & 5 deletions src/pip/_vendor/cachecontrol/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,21 @@ def build_response(
else:
# Wrap the response file with a wrapper that will cache the
# response when the stream has been consumed.
response._fp = CallbackFileWrapper( # type: ignore[attr-defined]
response._fp, # type: ignore[attr-defined]
response._fp = CallbackFileWrapper( # type: ignore[assignment]
response._fp, # type: ignore[arg-type]
functools.partial(
self.controller.cache_response, request, response
),
)
if response.chunked:
super_update_chunk_length = response._update_chunk_length # type: ignore[attr-defined]
super_update_chunk_length = response._update_chunk_length

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

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

Expand Down
7 changes: 4 additions & 3 deletions src/pip/_vendor/cachecontrol/caches/file_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import hashlib
import os
from textwrap import dedent
from typing import IO, TYPE_CHECKING
from typing import IO, TYPE_CHECKING, Union
from pathlib import Path

from pip._vendor.cachecontrol.cache import BaseCache, SeparateBodyBaseCache
from pip._vendor.cachecontrol.controller import CacheController
Expand Down Expand Up @@ -63,7 +64,7 @@ class _FileCacheMixin:

def __init__(
self,
directory: str,
directory: str | Path,
forever: bool = False,
filemode: int = 0o0600,
dirmode: int = 0o0700,
Expand All @@ -79,7 +80,7 @@ def __init__(
"""
NOTE: In order to use the FileCache you must have
filelock installed. You can install it via pip:
pip install filelock
pip install cachecontrol[filecache]
"""
)
raise ImportError(notice)
Expand Down
7 changes: 6 additions & 1 deletion src/pip/_vendor/cachecontrol/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ def _load_from_cache(self, request: PreparedRequest) -> HTTPResponse | None:
"""
Load a cached response, or return None if it's not available.
"""
# We do not support caching of partial content: so if the request contains a
# Range header then we don't want to load anything from the cache.
if "Range" in request.headers:
return None

cache_url = request.url
assert cache_url is not None
cache_data = self.cache.get(cache_url)
Expand Down Expand Up @@ -480,7 +485,7 @@ def update_cached_response(
cached_response.headers.update(
{
k: v
for k, v in response.headers.items() # type: ignore[no-untyped-call]
for k, v in response.headers.items()
if k.lower() not in excluded_headers
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_vendor/cachecontrol/heuristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def update_headers(self, response: HTTPResponse) -> dict[str, str]:

if "expires" not in response.headers:
date = parsedate(response.headers["date"])
expires = expire_after(timedelta(days=1), date=datetime(*date[:6], tzinfo=timezone.utc)) # type: ignore[misc]
expires = expire_after(timedelta(days=1), date=datetime(*date[:6], tzinfo=timezone.utc)) # type: ignore[index,misc]
headers["expires"] = datetime_to_header(expires)
headers["cache-control"] = "public"
return headers
Expand Down
76 changes: 8 additions & 68 deletions src/pip/_vendor/cachecontrol/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def dumps(
# also update the response with a new file handler to be
# sure it acts as though it was never read.
body = response.read(decode_content=False)
response._fp = io.BytesIO(body) # type: ignore[attr-defined]
response._fp = io.BytesIO(body) # type: ignore[assignment]
response.length_remaining = len(body)

data = {
"response": {
"body": body, # Empty bytestring if body is stored separately
"headers": {str(k): str(v) for k, v in response.headers.items()}, # type: ignore[no-untyped-call]
"headers": {str(k): str(v) for k, v in response.headers.items()},
"status": response.status,
"version": response.version,
"reason": str(response.reason),
Expand Down Expand Up @@ -72,31 +72,14 @@ def loads(
if not data:
return None

# Determine what version of the serializer the data was serialized
# with
try:
ver, data = data.split(b",", 1)
except ValueError:
ver = b"cc=0"

# Make sure that our "ver" is actually a version and isn't a false
# positive from a , being in the data stream.
if ver[:3] != b"cc=":
data = ver + data
ver = b"cc=0"

# Get the version number out of the cc=N
verstr = ver.split(b"=", 1)[-1].decode("ascii")

# Dispatch to the actual load method for the given version
try:
return getattr(self, f"_loads_v{verstr}")(request, data, body_file) # type: ignore[no-any-return]

except AttributeError:
# This is a version we don't have a loads function for, so we'll
# just treat it as a miss and return None
# Previous versions of this library supported other serialization
# formats, but these have all been removed.
if not data.startswith(f"cc={self.serde_version},".encode()):
return None

data = data[5:]
return self._loads_v4(request, data, body_file)

def prepare_response(
self,
request: PreparedRequest,
Expand Down Expand Up @@ -149,49 +132,6 @@ def prepare_response(

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

def _loads_v0(
self,
request: PreparedRequest,
data: bytes,
body_file: IO[bytes] | None = None,
) -> None:
# The original legacy cache data. This doesn't contain enough
# information to construct everything we need, so we'll treat this as
# a miss.
return None

def _loads_v1(
self,
request: PreparedRequest,
data: bytes,
body_file: IO[bytes] | None = None,
) -> HTTPResponse | None:
# The "v1" pickled cache format. This is no longer supported
# for security reasons, so we treat it as a miss.
return None

def _loads_v2(
self,
request: PreparedRequest,
data: bytes,
body_file: IO[bytes] | None = None,
) -> HTTPResponse | None:
# The "v2" compressed base64 cache format.
# This has been removed due to age and poor size/performance
# characteristics, so we treat it as a miss.
return None

def _loads_v3(
self,
request: PreparedRequest,
data: bytes,
body_file: IO[bytes] | None = None,
) -> None:
# Due to Python 2 encoding issues, it's impossible to know for sure
# exactly how to load v3 entries, thus we'll treat these as a miss so
# that they get rewritten out as v4 entries.
return None

def _loads_v4(
self,
request: PreparedRequest,
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_vendor/idna/LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2013-2023, Kim Davies and contributors.
Copyright (c) 2013-2024, Kim Davies and contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
23 changes: 9 additions & 14 deletions src/pip/_vendor/idna/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ def valid_contextj(label: str, pos: int) -> bool:
joining_type = idnadata.joining_types.get(ord(label[i]))
if joining_type == ord('T'):
continue
if joining_type in [ord('L'), ord('D')]:
elif joining_type in [ord('L'), ord('D')]:
ok = True
break
else:
break

if not ok:
return False
Expand All @@ -162,9 +164,11 @@ def valid_contextj(label: str, pos: int) -> bool:
joining_type = idnadata.joining_types.get(ord(label[i]))
if joining_type == ord('T'):
continue
if joining_type in [ord('R'), ord('D')]:
elif joining_type in [ord('R'), ord('D')]:
ok = True
break
else:
break
return ok

if cp_value == 0x200d:
Expand Down Expand Up @@ -236,12 +240,8 @@ def check_label(label: Union[str, bytes, bytearray]) -> None:
if intranges_contain(cp_value, idnadata.codepoint_classes['PVALID']):
continue
elif intranges_contain(cp_value, idnadata.codepoint_classes['CONTEXTJ']):
try:
if not valid_contextj(label, pos):
raise InvalidCodepointContext('Joiner {} not allowed at position {} in {}'.format(
_unot(cp_value), pos+1, repr(label)))
except ValueError:
raise IDNAError('Unknown codepoint adjacent to joiner {} at position {} in {}'.format(
if not valid_contextj(label, pos):
raise InvalidCodepointContext('Joiner {} not allowed at position {} in {}'.format(
_unot(cp_value), pos+1, repr(label)))
elif intranges_contain(cp_value, idnadata.codepoint_classes['CONTEXTO']):
if not valid_contexto(label, pos):
Expand All @@ -262,13 +262,8 @@ def alabel(label: str) -> bytes:
except UnicodeEncodeError:
pass

if not label:
raise IDNAError('No Input')

label = str(label)
check_label(label)
label_bytes = _punycode(label)
label_bytes = _alabel_prefix + label_bytes
label_bytes = _alabel_prefix + _punycode(label)

if not valid_label_length(label_bytes):
raise IDNAError('Label too long')
Expand Down

0 comments on commit e8e592a

Please sign in to comment.