[Python-checkins] bpo-40321: Add missing test, slightly expand documentation (GH-28760)
ambv
webhook-mailer at python.org
Wed Oct 6 11:28:25 EDT 2021
https://github.com/python/cpython/commit/f528045f695f7483d955a1eae4c1df68b1b4cacd
commit: f528045f695f7483d955a1eae4c1df68b1b4cacd
branch: main
author: Łukasz Langa <lukasz at langa.pl>
committer: ambv <lukasz at langa.pl>
date: 2021-10-06T17:28:16+02:00
summary:
bpo-40321: Add missing test, slightly expand documentation (GH-28760)
files:
M Doc/library/urllib.request.rst
M Lib/test/test_urllib2.py
M Lib/urllib/request.py
M Misc/NEWS.d/next/Library/2021-07-22-21-25-56.bpo-40321.gBlFmw.rst
diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst
index 099d74b2d5eab..88e93ba6b002e 100644
--- a/Doc/library/urllib.request.rst
+++ b/Doc/library/urllib.request.rst
@@ -876,13 +876,17 @@ HTTPRedirectHandler Objects
.. method:: HTTPRedirectHandler.http_error_307(req, fp, code, msg, hdrs)
The same as :meth:`http_error_301`, but called for the 'temporary redirect'
- response.
+ response. It does not allow changing the request method from ``POST``
+ to ``GET``.
.. method:: HTTPRedirectHandler.http_error_308(req, fp, code, msg, hdrs)
The same as :meth:`http_error_301`, but called for the 'permanent redirect'
- response.
+ response. It does not allow changing the request method from ``POST``
+ to ``GET``.
+
+ .. versionadded:: 3.11
.. _http-cookie-processor:
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 9db23e6ce04bd..a2b1340e0bf5b 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1163,7 +1163,7 @@ def test_redirect(self):
o = h.parent = MockOpener()
# ordinary redirect behaviour
- for code in 301, 302, 303, 307:
+ for code in 301, 302, 303, 307, 308:
for data in None, "blah\nblah\n":
method = getattr(h, "http_error_%s" % code)
req = Request(from_url, data)
@@ -1176,8 +1176,8 @@ def test_redirect(self):
method(req, MockFile(), code, "Blah",
MockHeaders({"location": to_url}))
except urllib.error.HTTPError:
- # 307 in response to POST requires user OK
- self.assertEqual(code, 307)
+ # 307 and 308 in response to POST require user OK
+ self.assertIn(code, (307, 308))
self.assertIsNotNone(data)
self.assertEqual(o.req.get_full_url(), to_url)
try:
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 3ba6d926aa8e7..fd6fc36aee04b 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -11,7 +11,7 @@
Handlers needed to open the requested URL. For example, the
HTTPHandler performs HTTP GET and POST requests and deals with
non-error returns. The HTTPRedirectHandler automatically deals with
-HTTP 301, 302, 303, 307 and 308 redirect errors, and the
+HTTP 301, 302, 303, 307, and 308 redirect errors, and the
HTTPDigestAuthHandler deals with digest authentication.
urlopen(url, data=None) -- Basic usage is the same as original
diff --git a/Misc/NEWS.d/next/Library/2021-07-22-21-25-56.bpo-40321.gBlFmw.rst b/Misc/NEWS.d/next/Library/2021-07-22-21-25-56.bpo-40321.gBlFmw.rst
index 1a7dba249c7db..fede2a0e5e35f 100644
--- a/Misc/NEWS.d/next/Library/2021-07-22-21-25-56.bpo-40321.gBlFmw.rst
+++ b/Misc/NEWS.d/next/Library/2021-07-22-21-25-56.bpo-40321.gBlFmw.rst
@@ -1,2 +1,2 @@
-Adds support for HTTP 308 redirects to :mod:`urllib`. Patch by Jochem
-Schulenklopper.
+Adds support for HTTP 308 redirects to :mod:`urllib`. See :rfc:`7538` for
+details. Patch by Jochem Schulenklopper.
More information about the Python-checkins
mailing list