8000 Add warnings about obsolescence of 'email.header.decode_header' and '… · python/cpython@9c0c56f · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 9c0c56f

Browse files
committed
Add warnings about obsolescence of 'email.header.decode_header' and 'email.header.make_header' functions.
Recommend use of `email.headerregistry.HeaderRegistry` instead, as suggested in #92900 (comment)
1 parent 5e86f31 commit 9c0c56f

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Doc/library/email.header.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ The :mod:`email.header` module also provides the following convenient functions.
204204
>>> decode_header('bar =?utf-8?B?ZsOzbw==?=')
205205
[(b'bar ', None), (b'f\xc3\xb3o', 'utf-8')]
206206

207+
.. note::
208+
209+
This function exists for for backwards compatibility only. For
210+
new code, we recommend using :class:`email.headerregistry.HeaderRegistry`.
211+
207212

208213
.. function:: make_header(decoded_seq, maxlinelen=None, header_name=None, continuation_ws=' ')
209214

@@ -217,3 +222,8 @@ The :mod:`email.header` module also provides the following convenient functions.
217222
This function takes one of those sequence of pairs and retu 8000 rns a
218223
:class:`Header` instance. Optional *maxlinelen*, *header_name*, and
219224
*continuation_ws* are as in the :class:`Header` constructor.
225+
226+
.. note::
227+
228+
This function exists for for backwards compatibility only, and is
229+
not recommended for use in new code.

Lib/email/header.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def decode_header(header):
7272
7373
An email.errors.HeaderParseError may be raised when certain decoding error
7474
occurs (e.g. a base64 decoding exception).
75+
76+
This function exists for backwards compatibility only. For new code, we
77+
recommend using email.headerregistry.HeaderRegistry instead.
7578
"""
7679
# If it is a Header object, we can just return the encoded chunks.
7780
if hasattr(header, '_chunks'):
@@ -164,6 +167,9 @@ def make_header(decoded_seq, maxlinelen=None, header_name=None,
164167
This function takes one of those sequence of pairs and returns a Header
165168
instance. Optional maxlinelen, header_name, and continuation_ws are as in
166169
the Header constructor.
170+
171+
This function exists for backwards compatibility only, and is not
172+
recommended for use in new code.
167173
"""
168174
h = Header(maxlinelen=maxlinelen, header_name=header_name,
169175
continuation_ws=continuation_ws)
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
The inconsistent return types of :func:`email.header.decode_header` are now documented.
1+
The inconsistent return types of :func:`email.header.decode_header` are now documented,
2+
and the use of :func:`email.header.decode_header` and :func:`email.header.make_header`
3+
are discouraged, with :class:`email.headerregistry.HeaderRegistry` recommended as a
4+
replacement.

0 commit comments

Comments
 (0)
0