Pre commit update (#6498)

This commit is contained in:
Nate Prewitt
2023-08-12 12:03:10 -07:00
committed by GitHub
parent 2c193bda0c
commit 8112fcc7be
7 changed files with 9 additions and 29 deletions
+4 -4
View File
@@ -2,7 +2,7 @@ exclude: 'docs/|ext/'
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1 rev: v4.4.0
hooks: hooks:
- id: check-yaml - id: check-yaml
- id: debug-statements - id: debug-statements
@@ -13,16 +13,16 @@ repos:
hooks: hooks:
- id: isort - id: isort
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 22.3.0 rev: 23.7.0
hooks: hooks:
- id: black - id: black
exclude: tests/test_lowlevel.py exclude: tests/test_lowlevel.py
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/asottile/pyupgrade
rev: v2.31.1 rev: v3.10.1
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: [--py37-plus] args: [--py37-plus]
- repo: https://github.com/PyCQA/flake8 - repo: https://github.com/PyCQA/flake8
rev: 6.0.0 rev: 6.1.0
hooks: hooks:
- id: flake8 - id: flake8
-1
View File
@@ -247,7 +247,6 @@ class HTTPAdapter(BaseAdapter):
:param cert: The SSL certificate to verify. :param cert: The SSL certificate to verify.
""" """
if url.lower().startswith("https") and verify: if url.lower().startswith("https") and verify:
cert_loc = None cert_loc = None
# Allow self-specified cert location. # Allow self-specified cert location.
-1
View File
@@ -258,7 +258,6 @@ class HTTPDigestAuth(AuthBase):
s_auth = r.headers.get("www-authenticate", "") s_auth = r.headers.get("www-authenticate", "")
if "digest" in s_auth.lower() and self._thread_local.num_401_calls < 2: if "digest" in s_auth.lower() and self._thread_local.num_401_calls < 2:
self._thread_local.num_401_calls += 1 self._thread_local.num_401_calls += 1
pat = re.compile(r"digest ", flags=re.IGNORECASE) pat = re.compile(r"digest ", flags=re.IGNORECASE)
self._thread_local.chal = parse_dict_header(pat.sub("", s_auth, count=1)) self._thread_local.chal = parse_dict_header(pat.sub("", s_auth, count=1))
+2 -4
View File
@@ -170,7 +170,7 @@ class RequestEncodingMixin:
) )
) )
for (k, v) in files: for k, v in files:
# support for explicit filename # support for explicit filename
ft = None ft = None
fh = None fh = None
@@ -268,7 +268,6 @@ class Request(RequestHooksMixin):
hooks=None, hooks=None,
json=None, json=None,
): ):
# Default empty dicts for dict params. # Default empty dicts for dict params.
data = [] if data is None else data data = [] if data is None else data
files = [] if files is None else files files = [] if files is None else files
@@ -277,7 +276,7 @@ class Request(RequestHooksMixin):
hooks = {} if hooks is None else hooks hooks = {} if hooks is None else hooks
self.hooks = default_hooks() self.hooks = default_hooks()
for (k, v) in list(hooks.items()): for k, v in list(hooks.items()):
self.register_hook(event=k, hook=v) self.register_hook(event=k, hook=v)
self.method = method self.method = method
@@ -865,7 +864,6 @@ class Response:
for chunk in self.iter_content( for chunk in self.iter_content(
chunk_size=chunk_size, decode_unicode=decode_unicode chunk_size=chunk_size, decode_unicode=decode_unicode
): ):
if pending is not None: if pending is not None:
chunk = pending + chunk chunk = pending + chunk
+2 -6
View File
@@ -262,7 +262,6 @@ class SessionRedirectMixin:
if yield_requests: if yield_requests:
yield req yield req
else: else:
resp = self.send( resp = self.send(
req, req,
stream=stream, stream=stream,
@@ -389,7 +388,6 @@ class Session(SessionRedirectMixin):
] ]
def __init__(self): def __init__(self):
#: A case-insensitive dictionary of headers to be sent on each #: A case-insensitive dictionary of headers to be sent on each
#: :class:`Request <Request>` sent from this #: :class:`Request <Request>` sent from this
#: :class:`Session <Session>`. #: :class:`Session <Session>`.
@@ -713,7 +711,6 @@ class Session(SessionRedirectMixin):
# Persist cookies # Persist cookies
if r.history: if r.history:
# If the hooks create history then we want those cookies too # If the hooks create history then we want those cookies too
for resp in r.history: for resp in r.history:
extract_cookies_to_jar(self.cookies, resp.request, resp.raw) extract_cookies_to_jar(self.cookies, resp.request, resp.raw)
@@ -761,7 +758,7 @@ class Session(SessionRedirectMixin):
# Set environment's proxies. # Set environment's proxies.
no_proxy = proxies.get("no_proxy") if proxies is not None else None no_proxy = proxies.get("no_proxy") if proxies is not None else None
env_proxies = get_environ_proxies(url, no_proxy=no_proxy) env_proxies = get_environ_proxies(url, no_proxy=no_proxy)
for (k, v) in env_proxies.items(): for k, v in env_proxies.items():
proxies.setdefault(k, v) proxies.setdefault(k, v)
# Look for requests environment configuration # Look for requests environment configuration
@@ -787,8 +784,7 @@ class Session(SessionRedirectMixin):
:rtype: requests.adapters.BaseAdapter :rtype: requests.adapters.BaseAdapter
""" """
for (prefix, adapter) in self.adapters.items(): for prefix, adapter in self.adapters.items():
if url.lower().startswith(prefix.lower()): if url.lower().startswith(prefix.lower()):
return adapter return adapter
+1
View File
@@ -763,6 +763,7 @@ def should_bypass_proxies(url, no_proxy):
:rtype: bool :rtype: bool
""" """
# Prioritize lowercase environment variables over uppercase # Prioritize lowercase environment variables over uppercase
# to keep a consistent behaviour with other http projects (curl, wget). # to keep a consistent behaviour with other http projects (curl, wget).
def get_proxy(key): def get_proxy(key):
-13
View File
@@ -75,11 +75,9 @@ except AttributeError:
class TestRequests: class TestRequests:
digest_auth_algo = ("MD5", "SHA-256", "SHA-512") digest_auth_algo = ("MD5", "SHA-256", "SHA-512")
def test_entry_points(self): def test_entry_points(self):
requests.session requests.session
requests.session().get requests.session().get
requests.session().head requests.session().head
@@ -510,7 +508,6 @@ class TestRequests:
@pytest.mark.parametrize("key", ("User-agent", "user-agent")) @pytest.mark.parametrize("key", ("User-agent", "user-agent"))
def test_user_agent_transfers(self, httpbin, key): def test_user_agent_transfers(self, httpbin, key):
heads = {key: "Mozilla/5.0 (github.com/psf/requests)"} heads = {key: "Mozilla/5.0 (github.com/psf/requests)"}
r = requests.get(httpbin("user-agent"), headers=heads) r = requests.get(httpbin("user-agent"), headers=heads)
@@ -704,7 +701,6 @@ class TestRequests:
requests.sessions.get_netrc_auth = old_auth requests.sessions.get_netrc_auth = old_auth
def test_DIGEST_HTTP_200_OK_GET(self, httpbin): def test_DIGEST_HTTP_200_OK_GET(self, httpbin):
for authtype in self.digest_auth_algo: for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth("user", "pass") auth = HTTPDigestAuth("user", "pass")
url = httpbin("digest-auth", "auth", "user", "pass", authtype, "never") url = httpbin("digest-auth", "auth", "user", "pass", authtype, "never")
@@ -722,7 +718,6 @@ class TestRequests:
assert r.status_code == 200 assert r.status_code == 200
def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin): def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin):
for authtype in self.digest_auth_algo: for authtype in self.digest_auth_algo:
url = httpbin("digest-auth", "auth", "user", "pass", authtype) url = httpbin("digest-auth", "auth", "user", "pass", authtype)
auth = HTTPDigestAuth("user", "pass") auth = HTTPDigestAuth("user", "pass")
@@ -733,7 +728,6 @@ class TestRequests:
assert r.status_code == 200 assert r.status_code == 200
def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin): def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin):
for authtype in self.digest_auth_algo: for authtype in self.digest_auth_algo:
url = httpbin("digest-auth", "auth", "user", "pass", authtype) url = httpbin("digest-auth", "auth", "user", "pass", authtype)
auth = HTTPDigestAuth("user", "pass") auth = HTTPDigestAuth("user", "pass")
@@ -742,7 +736,6 @@ class TestRequests:
assert s.cookies["fake"] == "fake_value" assert s.cookies["fake"] == "fake_value"
def test_DIGEST_STREAM(self, httpbin): def test_DIGEST_STREAM(self, httpbin):
for authtype in self.digest_auth_algo: for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth("user", "pass") auth = HTTPDigestAuth("user", "pass")
url = httpbin("digest-auth", "auth", "user", "pass", authtype) url = httpbin("digest-auth", "auth", "user", "pass", authtype)
@@ -754,7 +747,6 @@ class TestRequests:
assert r.raw.read() == b"" assert r.raw.read() == b""
def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin): def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin):
for authtype in self.digest_auth_algo: for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth("user", "wrongpass") auth = HTTPDigestAuth("user", "wrongpass")
url = httpbin("digest-auth", "auth", "user", "pass", authtype) url = httpbin("digest-auth", "auth", "user", "pass", authtype)
@@ -771,7 +763,6 @@ class TestRequests:
assert r.status_code == 401 assert r.status_code == 401
def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin): def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin):
for authtype in self.digest_auth_algo: for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth("user", "pass") auth = HTTPDigestAuth("user", "pass")
url = httpbin("digest-auth", "auth", "user", "pass", authtype) url = httpbin("digest-auth", "auth", "user", "pass", authtype)
@@ -780,7 +771,6 @@ class TestRequests:
assert '"auth"' in r.request.headers["Authorization"] assert '"auth"' in r.request.headers["Authorization"]
def test_POSTBIN_GET_POST_FILES(self, httpbin): def test_POSTBIN_GET_POST_FILES(self, httpbin):
url = httpbin("post") url = httpbin("post")
requests.post(url).raise_for_status() requests.post(url).raise_for_status()
@@ -798,7 +788,6 @@ class TestRequests:
requests.post(url, files=["bad file data"]) requests.post(url, files=["bad file data"])
def test_invalid_files_input(self, httpbin): def test_invalid_files_input(self, httpbin):
url = httpbin("post") url = httpbin("post")
post = requests.post(url, files={"random-file-1": None, "random-file-2": 1}) post = requests.post(url, files={"random-file-1": None, "random-file-2": 1})
assert b'name="random-file-1"' not in post.request.body assert b'name="random-file-1"' not in post.request.body
@@ -846,7 +835,6 @@ class TestRequests:
assert post2.json()["data"] == "st" assert post2.json()["data"] == "st"
def test_POSTBIN_GET_POST_FILES_WITH_DATA(self, httpbin): def test_POSTBIN_GET_POST_FILES_WITH_DATA(self, httpbin):
url = httpbin("post") url = httpbin("post")
requests.post(url).raise_for_status() requests.post(url).raise_for_status()
@@ -1035,7 +1023,6 @@ class TestRequests:
requests.get(httpbin_secure("status", "200")) requests.get(httpbin_secure("status", "200"))
def test_urlencoded_get_query_multivalued_param(self, httpbin): def test_urlencoded_get_query_multivalued_param(self, httpbin):
r = requests.get(httpbin("get"), params={"test": ["foo", "baz"]}) r = requests.get(httpbin("get"), params={"test": ["foo", "baz"]})
assert r.status_code == 200 assert r.status_code == 200
assert r.url == httpbin("get?test=foo&test=baz") assert r.url == httpbin("get?test=foo&test=baz")