Skip to content

Commit 55ae905

Browse files
authored
Merge pull request #12048 from nateprewitt/requests-2.31.0
2 parents 3aaf5c3 + 75f54ca commit 55ae905

File tree

9 files changed

+50
-83
lines changed

9 files changed

+50
-83
lines changed

news/requests.vendor.rst

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

src/pip/_vendor/requests/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ def check_compatibility(urllib3_version, chardet_version, charset_normalizer_ver
6363
# Check urllib3 for compatibility.
6464
major, minor, patch = urllib3_version # noqa: F811
6565
major, minor, patch = int(major), int(minor), int(patch)
66-
# urllib3 >= 1.21.1, <= 1.26
67-
assert major == 1
68-
assert minor >= 21
69-
assert minor <= 26
66+
# urllib3 >= 1.21.1
67+
assert major >= 1
68+
if major == 1:
69+
assert minor >= 21
7070

7171
# Check charset_normalizer for compatibility.
7272
if chardet_version:

src/pip/_vendor/requests/__version__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
__title__ = "requests"
66
__description__ = "Python HTTP for Humans."
77
__url__ = "https://requests.readthedocs.io"
8-
__version__ = "2.28.2"
9-
__build__ = 0x022802
8+
__version__ = "2.31.0"
9+
__build__ = 0x023100
1010
__author__ = "Kenneth Reitz"
1111
__author_email__ = "[email protected]"
1212
__license__ = "Apache 2.0"

src/pip/_vendor/requests/_internal_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
_VALID_HEADER_VALUE_RE_BYTE = re.compile(rb"^\S[^\r\n]*$|^$")
1515
_VALID_HEADER_VALUE_RE_STR = re.compile(r"^\S[^\r\n]*$|^$")
1616

17+
_HEADER_VALIDATORS_STR = (_VALID_HEADER_NAME_RE_STR, _VALID_HEADER_VALUE_RE_STR)
18+
_HEADER_VALIDATORS_BYTE = (_VALID_HEADER_NAME_RE_BYTE, _VALID_HEADER_VALUE_RE_BYTE)
1719
HEADER_VALIDATORS = {
18-
bytes: (_VALID_HEADER_NAME_RE_BYTE, _VALID_HEADER_VALUE_RE_BYTE),
19-
str: (_VALID_HEADER_NAME_RE_STR, _VALID_HEADER_VALUE_RE_STR),
20+
bytes: _HEADER_VALIDATORS_BYTE,
21+
str: _HEADER_VALIDATORS_STR,
2022
}
2123

2224

src/pip/_vendor/requests/adapters.py

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from pip._vendor.urllib3.exceptions import ReadTimeoutError, ResponseError
2323
from pip._vendor.urllib3.exceptions import SSLError as _SSLError
2424
from pip._vendor.urllib3.poolmanager import PoolManager, proxy_from_url
25-
from pip._vendor.urllib3.response import HTTPResponse
2625
from pip._vendor.urllib3.util import Timeout as TimeoutSauce
2726
from pip._vendor.urllib3.util import parse_url
2827
from pip._vendor.urllib3.util.retry import Retry
@@ -194,7 +193,6 @@ def init_poolmanager(
194193
num_pools=connections,
195194
maxsize=maxsize,
196195
block=block,
197-
strict=True,
198196
**pool_kwargs,
199197
)
200198

@@ -485,63 +483,19 @@ def send(
485483
timeout = TimeoutSauce(connect=timeout, read=timeout)
486484

487485
try:
488-
if not chunked:
489-
resp = conn.urlopen(
490-
method=request.method,
491-
url=url,
492-
body=request.body,
493-
headers=request.headers,
494-
redirect=False,
495-
assert_same_host=False,
496-
preload_content=False,
497-
decode_content=False,
498-
retries=self.max_retries,
499-
timeout=timeout,
500-
)
501-
502-
# Send the request.
503-
else:
504-
if hasattr(conn, "proxy_pool"):
505-
conn = conn.proxy_pool
506-
507-
low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT)
508-
509-
try:
510-
skip_host = "Host" in request.headers
511-
low_conn.putrequest(
512-
request.method,
513-
url,
514-
skip_accept_encoding=True,
515-
skip_host=skip_host,
516-
)
517-
518-
for header, value in request.headers.items():
519-
low_conn.putheader(header, value)
520-
521-
low_conn.endheaders()
522-
523-
for i in request.body:
524-
low_conn.send(hex(len(i))[2:].encode("utf-8"))
525-
low_conn.send(b"\r\n")
526-
low_conn.send(i)
527-
low_conn.send(b"\r\n")
528-
low_conn.send(b"0\r\n\r\n")
529-
530-
# Receive the response from the server
531-
r = low_conn.getresponse()
532-
533-
resp = HTTPResponse.from_httplib(
534-
r,
535-
pool=conn,
536-
connection=low_conn,
537-
preload_content=False,
538-
decode_content=False,
539-
)
540-
except Exception:
541-
# If we hit any problems here, clean up the connection.
542-
# Then, raise so that we can handle the actual exception.
543-
low_conn.close()
544-
raise
486+
resp = conn.urlopen(
487+
method=request.method,
488+
url=url,
489+
body=request.body,
490+
headers=request.headers,
491+
redirect=False,
492+
assert_same_host=False,
493+
preload_content=False,
494+
decode_content=False,
495+
retries=self.max_retries,
496+
timeout=timeout,
497+
chunked=chunked,
498+
)
545499

546500
except (ProtocolError, OSError) as err:
547501
raise ConnectionError(err, request=request)

src/pip/_vendor/requests/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def post(url, data=None, json=None, **kwargs):
106106
:param url: URL for the new :class:`Request` object.
107107
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
108108
object to send in the body of the :class:`Request`.
109-
:param json: (optional) json data to send in the body of the :class:`Request`.
109+
:param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`.
110110
:param \*\*kwargs: Optional arguments that ``request`` takes.
111111
:return: :class:`Response <Response>` object
112112
:rtype: requests.Response
@@ -121,7 +121,7 @@ def put(url, data=None, **kwargs):
121121
:param url: URL for the new :class:`Request` object.
122122
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
123123
object to send in the body of the :class:`Request`.
124-
:param json: (optional) json data to send in the body of the :class:`Request`.
124+
:param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`.
125125
:param \*\*kwargs: Optional arguments that ``request`` takes.
126126
:return: :class:`Response <Response>` object
127127
:rtype: requests.Response
@@ -136,7 +136,7 @@ def patch(url, data=None, **kwargs):
136136
:param url: URL for the new :class:`Request` object.
137137
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
138138
object to send in the body of the :class:`Request`.
139-
:param json: (optional) json data to send in the body of the :class:`Request`.
139+
:param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`.
140140
:param \*\*kwargs: Optional arguments that ``request`` takes.
141141
:return: :class:`Response <Response>` object
142142
:rtype: requests.Response

src/pip/_vendor/requests/sessions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ def rebuild_proxies(self, prepared_request, proxies):
324324
except KeyError:
325325
username, password = None, None
326326

327-
if username and password:
327+
# urllib3 handles proxy authorization for us in the standard adapter.
328+
# Avoid appending this to TLS tunneled requests where it may be leaked.
329+
if not scheme.startswith('https') and username and password:
328330
headers["Proxy-Authorization"] = _basic_auth_str(username, password)
329331

330332
return new_proxies

src/pip/_vendor/requests/utils.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
from .__version__ import __version__
2626

2727
# to_native_string is unused here, but imported here for backwards compatibility
28-
from ._internal_utils import HEADER_VALIDATORS, to_native_string # noqa: F401
28+
from ._internal_utils import ( # noqa: F401
29+
_HEADER_VALIDATORS_BYTE,
30+
_HEADER_VALIDATORS_STR,
31+
HEADER_VALIDATORS,
32+
to_native_string,
33+
)
2934
from .compat import (
3035
Mapping,
3136
basestring,
@@ -1031,20 +1036,23 @@ def check_header_validity(header):
10311036
:param header: tuple, in the format (name, value).
10321037
"""
10331038
name, value = header
1039+
_validate_header_part(header, name, 0)
1040+
_validate_header_part(header, value, 1)
10341041

1035-
for part in header:
1036-
if type(part) not in HEADER_VALIDATORS:
1037-
raise InvalidHeader(
1038-
f"Header part ({part!r}) from {{{name!r}: {value!r}}} must be "
1039-
f"of type str or bytes, not {type(part)}"
1040-
)
1041-
1042-
_validate_header_part(name, "name", HEADER_VALIDATORS[type(name)][0])
1043-
_validate_header_part(value, "value", HEADER_VALIDATORS[type(value)][1])
10441042

1043+
def _validate_header_part(header, header_part, header_validator_index):
1044+
if isinstance(header_part, str):
1045+
validator = _HEADER_VALIDATORS_STR[header_validator_index]
1046+
elif isinstance(header_part, bytes):
1047+
validator = _HEADER_VALIDATORS_BYTE[header_validator_index]
1048+
else:
1049+
raise InvalidHeader(
1050+
f"Header part ({header_part!r}) from {header} "
1051+
f"must be of type str or bytes, not {type(header_part)}"
1052+
)
10451053

1046-
def _validate_header_part(header_part, header_kind, validator):
10471054
if not validator.match(header_part):
1055+
header_kind = "name" if header_validator_index == 0 else "value"
10481056
raise InvalidHeader(
10491057
f"Invalid leading whitespace, reserved character(s), or return"
10501058
f"character(s) in header {header_kind}: {header_part!r}"

src/pip/_vendor/vendor.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packaging==21.3
77
platformdirs==3.2.0
88
pyparsing==3.0.9
99
pyproject-hooks==1.0.0
10-
requests==2.28.2
10+
requests==2.31.0
1111
certifi==2022.12.7
1212
chardet==5.1.0
1313
idna==3.4

0 commit comments

Comments
 (0)