Skip to content
Open
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
7 changes: 7 additions & 0 deletions Doc/deprecations/pending-removal-in-3.18.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ Pending removal in Python 3.18
* ``import`` lines in :file:`{name}.pth` files are silently ignored.

(Contributed by Barry Warsaw in :gh:`148641`.)

* :mod:`http.client`:

* :meth:`!http.client.HTTPMessage.getallmatchingheaders` has been deprecated
since Python 3.16. It has returned an empty list for every input since
Python 3.0; use :meth:`email.message.Message.get_all` instead.
(Contributed by Julian Soreavis in :gh:`153648`.)
9 changes: 9 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,15 @@ New deprecations
3.9, now issues a deprecation warning on use. This property is slated for
removal in 3.21. Use ``ast.Tuple.elts`` instead.

* :mod:`http.client`:

* :meth:`!http.client.HTTPMessage.getallmatchingheaders` is now deprecated
and will be removed in Python 3.18. It has returned an empty list for
every input since Python 3.0, and its only user, the CGI handler, was
removed in Python 3.15. Use :meth:`email.message.Message.get_all`
instead.
(Contributed by Julian Soreavis in :gh:`153648`.)

* :mod:`struct`:

* Soft-deprecated since Python 3.15, using ``'F'`` and ``'D'`` type codes are now
Expand Down
13 changes: 11 additions & 2 deletions Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ def _strip_ipv6_iface(enc_name: bytes) -> bytes:
class HTTPMessage(email.message.Message):

# The getallmatchingheaders() method was only used by the CGI handler
# that was removed in Python 3.15. However, since the public API was not
# properly defined, it will be kept for backwards compatibility reasons.
# that was removed in Python 3.15. It has returned an empty list for every
# input since Python 3.0.

def getallmatchingheaders(self, name):
"""Find all header lines matching a given header name.
Expand All @@ -208,6 +208,15 @@ def getallmatchingheaders(self, name):
occurrences are returned. Case is not important in the header name.

"""
import warnings
warnings._deprecated(
"http.client.HTTPMessage.getallmatchingheaders",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a "use XXX instead"?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — done. The warning now reads:

'http.client.HTTPMessage.getallmatchingheaders' is deprecated and slated for removal in Python 3.18. Use email.message.Message.get_all() instead.

message=(
"{name!r} is deprecated and slated for removal in Python "
"{remove}. Use email.message.Message.get_all() instead."
),
remove=(3, 18),
)
name = name.lower() + ':'
n = len(name)
lst = []
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,12 @@ def test_max_connection_trailers(self):
response = conn.getresponse()
self.assertEqual(response.read(), chunked_expected)

def test_getallmatchingheaders_deprecated(self):
message = client.parse_headers(io.BytesIO(b"Set-Cookie: a=1\r\n\r\n"))
with self.assertWarns(DeprecationWarning):
message.getallmatchingheaders("Set-Cookie")


class HttpMethodTests(TestCase):
def test_invalid_method_names(self):
methods = (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Deprecate :meth:`!http.client.HTTPMessage.getallmatchingheaders`, to be
removed in Python 3.18. It has returned an empty list for every input since
Python 3.0, and its only user, the CGI handler, was removed in Python 3.15.
Use :meth:`email.message.Message.get_all` instead. Patch by Julian Soreavis.
Loading