Skip to content

Commit 6c3853a

Browse files
committed
Upgrade requests to 2.28.1
1 parent f1b3926 commit 6c3853a

20 files changed

+1193
-966
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.28.1

src/pip/_vendor/requests/__init__.py

Lines changed: 67 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
# __
42
# /__) _ _ _ _ _/ _
53
# / ( (- (/ (/ (- _) / _)
@@ -40,27 +38,27 @@
4038
:license: Apache 2.0, see LICENSE for more details.
4139
"""
4240

43-
from pip._vendor import urllib3
4441
import warnings
42+
43+
from pip._vendor import urllib3
44+
4545
from .exceptions import RequestsDependencyWarning
4646

47-
try:
48-
from charset_normalizer import __version__ as charset_normalizer_version
49-
except ImportError:
50-
charset_normalizer_version = None
47+
charset_normalizer_version = None
5148

5249
try:
5350
from pip._vendor.chardet import __version__ as chardet_version
5451
except ImportError:
5552
chardet_version = None
5653

54+
5755
def check_compatibility(urllib3_version, chardet_version, charset_normalizer_version):
58-
urllib3_version = urllib3_version.split('.')
59-
assert urllib3_version != ['dev'] # Verify urllib3 isn't installed from git.
56+
urllib3_version = urllib3_version.split(".")
57+
assert urllib3_version != ["dev"] # Verify urllib3 isn't installed from git.
6058

6159
# Sometimes, urllib3 only reports its version as 16.1.
6260
if len(urllib3_version) == 2:
63-
urllib3_version.append('0')
61+
urllib3_version.append("0")
6462

6563
# Check urllib3 for compatibility.
6664
major, minor, patch = urllib3_version # noqa: F811
@@ -72,81 +70,113 @@ def check_compatibility(urllib3_version, chardet_version, charset_normalizer_ver
7270

7371
# Check charset_normalizer for compatibility.
7472
if chardet_version:
75-
major, minor, patch = chardet_version.split('.')[:3]
73+
major, minor, patch = chardet_version.split(".")[:3]
7674
major, minor, patch = int(major), int(minor), int(patch)
77-
# chardet_version >= 3.0.2, < 5.0.0
78-
assert (3, 0, 2) <= (major, minor, patch) < (5, 0, 0)
75+
# chardet_version >= 3.0.2, < 6.0.0
76+
assert (3, 0, 2) <= (major, minor, patch) < (6, 0, 0)
7977
elif charset_normalizer_version:
80-
major, minor, patch = charset_normalizer_version.split('.')[:3]
78+
major, minor, patch = charset_normalizer_version.split(".")[:3]
8179
major, minor, patch = int(major), int(minor), int(patch)
8280
# charset_normalizer >= 2.0.0 < 3.0.0
8381
assert (2, 0, 0) <= (major, minor, patch) < (3, 0, 0)
8482
else:
8583
raise Exception("You need either charset_normalizer or chardet installed")
8684

85+
8786
def _check_cryptography(cryptography_version):
8887
# cryptography < 1.3.4
8988
try:
90-
cryptography_version = list(map(int, cryptography_version.split('.')))
89+
cryptography_version = list(map(int, cryptography_version.split(".")))
9190
except ValueError:
9291
return
9392

9493
if cryptography_version < [1, 3, 4]:
95-
warning = 'Old version of cryptography ({}) may cause slowdown.'.format(cryptography_version)
94+
warning = "Old version of cryptography ({}) may cause slowdown.".format(
95+
cryptography_version
96+
)
9697
warnings.warn(warning, RequestsDependencyWarning)
9798

99+
98100
# Check imported dependencies for compatibility.
99101
try:
100-
check_compatibility(urllib3.__version__, chardet_version, charset_normalizer_version)
102+
check_compatibility(
103+
urllib3.__version__, chardet_version, charset_normalizer_version
104+
)
101105
except (AssertionError, ValueError):
102-
warnings.warn("urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "
103-
"version!".format(urllib3.__version__, chardet_version, charset_normalizer_version),
104-
RequestsDependencyWarning)
106+
warnings.warn(
107+
"urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "
108+
"version!".format(
109+
urllib3.__version__, chardet_version, charset_normalizer_version
110+
),
111+
RequestsDependencyWarning,
112+
)
105113

106114
# Attempt to enable urllib3's fallback for SNI support
107115
# if the standard library doesn't support SNI or the
108116
# 'ssl' library isn't available.
109117
try:
118+
# Note: This logic prevents upgrading cryptography on Windows, if imported
119+
# as part of pip.
120+
from pip._internal.utils.compat import WINDOWS
121+
if not WINDOWS:
122+
raise ImportError("pip internals: don't import cryptography on Windows")
110123
try:
111124
import ssl
112125
except ImportError:
113126
ssl = None
114127

115128
if not getattr(ssl, "HAS_SNI", False):
116129
from pip._vendor.urllib3.contrib import pyopenssl
130+
117131
pyopenssl.inject_into_urllib3()
118132

119133
# Check cryptography version
120134
from cryptography import __version__ as cryptography_version
135+
121136
_check_cryptography(cryptography_version)
122137
except ImportError:
123138
pass
124139

125140
# urllib3's DependencyWarnings should be silenced.
126141
from pip._vendor.urllib3.exceptions import DependencyWarning
127-
warnings.simplefilter('ignore', DependencyWarning)
128-
129-
from .__version__ import __title__, __description__, __url__, __version__
130-
from .__version__ import __build__, __author__, __author_email__, __license__
131-
from .__version__ import __copyright__, __cake__
132142

133-
from . import utils
134-
from . import packages
135-
from .models import Request, Response, PreparedRequest
136-
from .api import request, get, head, post, patch, put, delete, options
137-
from .sessions import session, Session
138-
from .status_codes import codes
139-
from .exceptions import (
140-
RequestException, Timeout, URLRequired,
141-
TooManyRedirects, HTTPError, ConnectionError,
142-
FileModeWarning, ConnectTimeout, ReadTimeout, JSONDecodeError
143-
)
143+
warnings.simplefilter("ignore", DependencyWarning)
144144

145145
# Set default logging handler to avoid "No handler found" warnings.
146146
import logging
147147
from logging import NullHandler
148148

149+
from . import packages, utils
150+
from .__version__ import (
151+
__author__,
152+
__author_email__,
153+
__build__,
154+
__cake__,
155+
__copyright__,
156+
__description__,
157+
__license__,
158+
__title__,
159+
__url__,
160+
__version__,
161+
)
162+
from .api import delete, get, head, options, patch, post, put, request
163+
from .exceptions import (
164+
ConnectionError,
165+
ConnectTimeout,
166+
FileModeWarning,
167+
HTTPError,
168+
JSONDecodeError,
169+
ReadTimeout,
170+
RequestException,
171+
Timeout,
172+
TooManyRedirects,
173+
URLRequired,
174+
)
175+
from .models import PreparedRequest, Request, Response
176+
from .sessions import Session, session
177+
from .status_codes import codes
178+
149179
logging.getLogger(__name__).addHandler(NullHandler())
150180

151181
# FileModeWarnings go off per the default.
152-
warnings.simplefilter('default', FileModeWarning, append=True)
182+
warnings.simplefilter("default", FileModeWarning, append=True)

src/pip/_vendor/requests/__version__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# |( |- |.| | | |- `-. | `-.
33
# ' ' `-' `-`.`-' `-' `-' ' `-'
44

5-
__title__ = 'requests'
6-
__description__ = 'Python HTTP for Humans.'
7-
__url__ = 'https://requests.readthedocs.io'
8-
__version__ = '2.27.1'
9-
__build__ = 0x022701
10-
__author__ = 'Kenneth Reitz'
11-
__author_email__ = '[email protected]'
12-
__license__ = 'Apache 2.0'
13-
__copyright__ = 'Copyright 2022 Kenneth Reitz'
14-
__cake__ = u'\u2728 \U0001f370 \u2728'
5+
__title__ = "requests"
6+
__description__ = "Python HTTP for Humans."
7+
__url__ = "https://requests.readthedocs.io"
8+
__version__ = "2.28.1"
9+
__build__ = 0x022801
10+
__author__ = "Kenneth Reitz"
11+
__author_email__ = "[email protected]"
12+
__license__ = "Apache 2.0"
13+
__copyright__ = "Copyright 2022 Kenneth Reitz"
14+
__cake__ = "\u2728 \U0001f370 \u2728"
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
1-
# -*- coding: utf-8 -*-
2-
31
"""
42
requests._internal_utils
53
~~~~~~~~~~~~~~
64
75
Provides utility functions that are consumed internally by Requests
86
which depend on extremely few external helpers (such as compat)
97
"""
8+
import re
9+
10+
from .compat import builtin_str
11+
12+
_VALID_HEADER_NAME_RE_BYTE = re.compile(rb"^[^:\s][^:\r\n]*$")
13+
_VALID_HEADER_NAME_RE_STR = re.compile(r"^[^:\s][^:\r\n]*$")
14+
_VALID_HEADER_VALUE_RE_BYTE = re.compile(rb"^\S[^\r\n]*$|^$")
15+
_VALID_HEADER_VALUE_RE_STR = re.compile(r"^\S[^\r\n]*$|^$")
1016

11-
from .compat import is_py2, builtin_str, str
17+
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+
}
1221

1322

14-
def to_native_string(string, encoding='ascii'):
23+
def to_native_string(string, encoding="ascii"):
1524
"""Given a string object, regardless of type, returns a representation of
1625
that string in the native string type, encoding and decoding where
1726
necessary. This assumes ASCII unless told otherwise.
1827
"""
1928
if isinstance(string, builtin_str):
2029
out = string
2130
else:
22-
if is_py2:
23-
out = string.encode(encoding)
24-
else:
25-
out = string.decode(encoding)
31+
out = string.decode(encoding)
2632

2733
return out
2834

@@ -36,7 +42,7 @@ def unicode_is_ascii(u_string):
3642
"""
3743
assert isinstance(u_string, str)
3844
try:
39-
u_string.encode('ascii')
45+
u_string.encode("ascii")
4046
return True
4147
except UnicodeEncodeError:
4248
return False

0 commit comments

Comments
 (0)