Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre commit update #6498

Merged
merged 2 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ exclude: 'docs/|ext/'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.4.0
hooks:
- id: check-yaml
- id: debug-statements
Expand All @@ -13,16 +13,16 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.7.0
hooks:
- id: black
exclude: tests/test_lowlevel.py
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
rev: v3.10.1
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
1 change: 0 additions & 1 deletion requests/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ def cert_verify(self, conn, url, verify, cert):
:param cert: The SSL certificate to verify.
"""
if url.lower().startswith("https") and verify:

cert_loc = None

# Allow self-specified cert location.
Expand Down
1 change: 0 additions & 1 deletion requests/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ def handle_401(self, r, **kwargs):
s_auth = r.headers.get("www-authenticate", "")

if "digest" in s_auth.lower() and self._thread_local.num_401_calls < 2:

self._thread_local.num_401_calls += 1
pat = re.compile(r"digest ", flags=re.IGNORECASE)
self._thread_local.chal = parse_dict_header(pat.sub("", s_auth, count=1))
Expand Down
6 changes: 2 additions & 4 deletions requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _encode_files(files, data):
)
)

for (k, v) in files:
for k, v in files:
# support for explicit filename
ft = None
fh = None
Expand Down Expand Up @@ -268,7 +268,6 @@ def __init__(
hooks=None,
json=None,
):

# Default empty dicts for dict params.
data = [] if data is None else data
files = [] if files is None else files
Expand All @@ -277,7 +276,7 @@ def __init__(
hooks = {} if hooks is None else 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.method = method
Expand Down Expand Up @@ -865,7 +864,6 @@ def iter_lines(
for chunk in self.iter_content(
chunk_size=chunk_size, decode_unicode=decode_unicode
):

if pending is not None:
chunk = pending + chunk

Expand Down
8 changes: 2 additions & 6 deletions requests/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ def resolve_redirects(
if yield_requests:
yield req
else:

resp = self.send(
req,
stream=stream,
Expand Down Expand Up @@ -389,7 +388,6 @@ class Session(SessionRedirectMixin):
]

def __init__(self):

#: A case-insensitive dictionary of headers to be sent on each
#: :class:`Request <Request>` sent from this
#: :class:`Session <Session>`.
Expand Down Expand Up @@ -713,7 +711,6 @@ def send(self, request, **kwargs):

# Persist cookies
if r.history:

# If the hooks create history then we want those cookies too
for resp in r.history:
extract_cookies_to_jar(self.cookies, resp.request, resp.raw)
Expand Down Expand Up @@ -761,7 +758,7 @@ def merge_environment_settings(self, url, proxies, stream, verify, cert):
# Set environment's proxies.
no_proxy = proxies.get("no_proxy") if proxies is not None else None
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)

# Look for requests environment configuration
Expand All @@ -787,8 +784,7 @@ def get_adapter(self, url):

:rtype: requests.adapters.BaseAdapter
"""
for (prefix, adapter) in self.adapters.items():

for prefix, adapter in self.adapters.items():
if url.lower().startswith(prefix.lower()):
return adapter

Expand Down
1 change: 1 addition & 0 deletions requests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ def should_bypass_proxies(url, no_proxy):

:rtype: bool
"""

# Prioritize lowercase environment variables over uppercase
# to keep a consistent behaviour with other http projects (curl, wget).
def get_proxy(key):
Expand Down
13 changes: 0 additions & 13 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@


class TestRequests:

digest_auth_algo = ("MD5", "SHA-256", "SHA-512")

def test_entry_points(self):

requests.session
requests.session().get
requests.session().head
Expand Down Expand Up @@ -510,7 +508,6 @@ def test_headers_preserve_order(self, httpbin):

@pytest.mark.parametrize("key", ("User-agent", "user-agent"))
def test_user_agent_transfers(self, httpbin, key):

heads = {key: "Mozilla/5.0 (github.com/psf/requests)"}

r = requests.get(httpbin("user-agent"), headers=heads)
Expand Down Expand Up @@ -704,7 +701,6 @@ def get_netrc_auth_mock(url):
requests.sessions.get_netrc_auth = old_auth

def test_DIGEST_HTTP_200_OK_GET(self, httpbin):

for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth("user", "pass")
url = httpbin("digest-auth", "auth", "user", "pass", authtype, "never")
Expand All @@ -722,7 +718,6 @@ def test_DIGEST_HTTP_200_OK_GET(self, httpbin):
assert r.status_code == 200

def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin):

for authtype in self.digest_auth_algo:
url = httpbin("digest-auth", "auth", "user", "pass", authtype)
auth = HTTPDigestAuth("user", "pass")
Expand All @@ -733,7 +728,6 @@ def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin):
assert r.status_code == 200

def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin):

for authtype in self.digest_auth_algo:
url = httpbin("digest-auth", "auth", "user", "pass", authtype)
auth = HTTPDigestAuth("user", "pass")
Expand All @@ -742,7 +736,6 @@ def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin):
assert s.cookies["fake"] == "fake_value"

def test_DIGEST_STREAM(self, httpbin):

for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth("user", "pass")
url = httpbin("digest-auth", "auth", "user", "pass", authtype)
Expand All @@ -754,7 +747,6 @@ def test_DIGEST_STREAM(self, httpbin):
assert r.raw.read() == b""

def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin):

for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth("user", "wrongpass")
url = httpbin("digest-auth", "auth", "user", "pass", authtype)
Expand All @@ -771,7 +763,6 @@ def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin):
assert r.status_code == 401

def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin):

for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth("user", "pass")
url = httpbin("digest-auth", "auth", "user", "pass", authtype)
Expand All @@ -780,7 +771,6 @@ def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin):
assert '"auth"' in r.request.headers["Authorization"]

def test_POSTBIN_GET_POST_FILES(self, httpbin):

url = httpbin("post")
requests.post(url).raise_for_status()

Expand All @@ -798,7 +788,6 @@ def test_POSTBIN_GET_POST_FILES(self, httpbin):
requests.post(url, files=["bad file data"])

def test_invalid_files_input(self, httpbin):

url = httpbin("post")
post = requests.post(url, files={"random-file-1": None, "random-file-2": 1})
assert b'name="random-file-1"' not in post.request.body
Expand Down Expand Up @@ -846,7 +835,6 @@ def seek(self, offset, where=0):
assert post2.json()["data"] == "st"

def test_POSTBIN_GET_POST_FILES_WITH_DATA(self, httpbin):

url = httpbin("post")
requests.post(url).raise_for_status()

Expand Down Expand Up @@ -1035,7 +1023,6 @@ def test_certificate_failure(self, httpbin_secure):
requests.get(httpbin_secure("status", "200"))

def test_urlencoded_get_query_multivalued_param(self, httpbin):

r = requests.get(httpbin("get"), params={"test": ["foo", "baz"]})
assert r.status_code == 200
assert r.url == httpbin("get?test=foo&test=baz")
Expand Down
Loading