[Python-checkins] gh-100519: simplification to `eff_request_host` in cookiejar.py (#99588)

hauntsaninja webhook-mailer at python.org
Sat Dec 24 19:15:04 EST 2022


https://github.com/python/cpython/commit/b9aa14a484f653cb6a3a242776df9ac5fe161bfc
commit: b9aa14a484f653cb6a3a242776df9ac5fe161bfc
branch: main
author: Glyph <code at glyph.im>
committer: hauntsaninja <12621235+hauntsaninja at users.noreply.github.com>
date: 2022-12-24T18:14:51-06:00
summary:

gh-100519: simplification to `eff_request_host` in cookiejar.py (#99588)

`IPV4_RE` includes a `.`, and the `.find(".") == -1` included here is already testing to make sure there's no dot, so this part of the expression is tautological. Instead use more modern `in` syntax to make it clear what the check is doing here. The simplified implementation more clearly matches the wording in RFC 2965.

Co-authored-by: hauntsaninja <hauntsaninja at gmail.com>

files:
A Misc/NEWS.d/next/Library/2022-12-24-16-39-53.gh-issue-100519.G_dZLP.rst
M Lib/http/cookiejar.py

diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py
index e3df007033b3..93b10d26c845 100644
--- a/Lib/http/cookiejar.py
+++ b/Lib/http/cookiejar.py
@@ -640,7 +640,7 @@ def eff_request_host(request):
 
     """
     erhn = req_host = request_host(request)
-    if req_host.find(".") == -1 and not IPV4_RE.search(req_host):
+    if "." not in req_host:
         erhn = req_host + ".local"
     return req_host, erhn
 
diff --git a/Misc/NEWS.d/next/Library/2022-12-24-16-39-53.gh-issue-100519.G_dZLP.rst b/Misc/NEWS.d/next/Library/2022-12-24-16-39-53.gh-issue-100519.G_dZLP.rst
new file mode 100644
index 000000000000..6b889b61c274
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-12-24-16-39-53.gh-issue-100519.G_dZLP.rst
@@ -0,0 +1,2 @@
+Small simplification of :func:`http.cookiejar.eff_request_host` that
+improves readability and better matches the RFC wording.



More information about the Python-checkins mailing list