Skip to content

Commit c523dde

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.14] gh-62978: Use Python 3 terms in the email package docs (GH-155190) (GH-155636)
Replace "Unicode string" with "string" and the unicode() built-in with str() in docstrings, comments and documentation of the email package. "byte string" is only replaced with "bytes" where other bytes-like objects are not accepted. (cherry picked from commit 4603523) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 83633e4 commit c523dde

15 files changed

Lines changed: 44 additions & 44 deletions

Doc/library/email.compat32-message.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Here are the methods of the :class:`Message` class:
9696
text = fp.getvalue()
9797

9898
If the message object contains binary data that is not encoded according
99-
to RFC standards, the non-compliant data will be replaced by unicode
99+
to RFC standards, the non-compliant data will be replaced by Unicode
100100
"unknown character" code points. (See also :meth:`.as_bytes` and
101101
:class:`~email.generator.BytesGenerator`.)
102102

Doc/library/email.contentmanager.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ Currently the email package provides only one concrete content manager,
9999

100100
This content manager provides only a minimum interface beyond that provided
101101
by :class:`~email.message.Message` itself: it deals only with text, raw
102-
byte strings, and :class:`~email.message.Message` objects. Nevertheless, it
102+
bytes, and :class:`~email.message.Message` objects. Nevertheless, it
103103
provides significant advantages compared to the base API: ``get_content`` on
104-
a text part will return a unicode string without the application needing to
104+
a text part will return a string without the application needing to
105105
manually decode it, ``set_content`` provides a rich set of options for
106106
controlling the headers added to a part and controlling the content transfer
107107
encoding, and it enables the use of the various ``add_`` methods, thereby
@@ -114,7 +114,7 @@ Currently the email package provides only one concrete content manager,
114114
parts), or a ``bytes`` object (for all other non-multipart types). Raise
115115
a :exc:`KeyError` if called on a ``multipart``. If the part is a
116116
``text`` part and *errors* is specified, use it as the error handler when
117-
decoding the payload to unicode. The default error handler is
117+
decoding the payload to a string. The default error handler is
118118
``replace``.
119119

120120
.. method:: set_content(msg, <'str'>, subtype="plain", charset='utf-8', \

Doc/library/email.examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Here are a few examples of how to use the :mod:`email` package to read, write,
77
and send simple email messages, as well as more complex MIME messages.
88

99
First, let's see how to create and send a simple text message (both the
10-
text content and the addresses may contain unicode characters):
10+
text content and the addresses may contain Unicode characters):
1111

1212
.. literalinclude:: ../includes/email-simple.py
1313

Doc/library/email.header.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ For example::
4949

5050
Notice here how we wanted the :mailheader:`Subject` field to contain a non-ASCII
5151
character? We did this by creating a :class:`Header` instance and passing in
52-
the character set that the byte string was encoded in. When the subsequent
52+
the character set to use when encoding it. When the subsequent
5353
:class:`~email.message.Message` instance was flattened, the :mailheader:`Subject`
5454
field was properly :rfc:`2047` encoded. MIME-aware mail readers would show this
5555
header using the embedded ISO-8859-1 character.
@@ -150,7 +150,7 @@ Here is the :class:`Header` class description:
150150
.. method:: __str__()
151151

152152
Returns an approximation of the :class:`Header` as a string, using an
153-
unlimited line length. All pieces are converted to unicode using the
153+
unlimited line length. All pieces are decoded using the
154154
specified encoding and joined together appropriately. Any pieces with a
155155
charset of ``'unknown-8bit'`` are decoded as ASCII using the ``'replace'``
156156
error handler.

Doc/library/email.headerregistry.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ headers.
4343

4444
*name* and *value* are passed to ``BaseHeader`` from the
4545
:attr:`~email.policy.EmailPolicy.header_factory` call. The string value of
46-
any header object is the *value* fully decoded to unicode.
46+
any header object is the *value* fully decoded to a string.
4747

4848
This base class defines the following read-only properties:
4949

@@ -98,10 +98,10 @@ headers.
9898
defects to this list. On return, the ``kwds`` dictionary *must* contain
9999
values for at least the keys ``decoded``, ``defects`` and ``parse_tree``.
100100
``decoded`` should be the string value for the header (that is, the header
101-
value fully decoded to unicode). ``parse_tree`` is set to the parse tree obtained
101+
value fully decoded to a string). ``parse_tree`` is set to the parse tree obtained
102102
from parsing the header. The parse method should assume that *string* may
103103
contain content-transfer-encoded parts, but should correctly handle all valid
104-
unicode characters as well so that it can parse un-encoded header values.
104+
Unicode characters as well so that it can parse un-encoded header values.
105105

106106
``BaseHeader``'s ``__new__`` then creates the header instance, and calls its
107107
``init`` method. The specialized class only needs to provide an ``init``
@@ -129,7 +129,7 @@ headers.
129129
mechanism for encoding non-ASCII text as ASCII characters within a header
130130
value. When a *value* containing encoded words is passed to the
131131
constructor, the ``UnstructuredHeader`` parser converts such encoded words
132-
into unicode, following the :rfc:`2047` rules for unstructured text. The
132+
into a string, following the :rfc:`2047` rules for unstructured text. The
133133
parser uses heuristics to attempt to decode certain non-compliant encoded
134134
words. Defects are registered in such cases, as well as defects for issues
135135
such as invalid characters within the encoded words or the non-encoded text.
@@ -206,8 +206,8 @@ headers.
206206
the list of addresses is "flattened" into a one dimensional list).
207207

208208
The ``decoded`` value of the header will have all encoded words decoded to
209-
unicode. :class:`~encodings.idna` encoded domain names are also decoded to
210-
unicode. The ``decoded`` value is set by :ref:`joining <meth-str-join>` the
209+
a string. :class:`~encodings.idna` encoded domain names are also decoded to
210+
a string. The ``decoded`` value is set by :ref:`joining <meth-str-join>` the
211211
:class:`str` value of the elements of the ``groups`` attribute with ``',
212212
'``.
213213

@@ -391,7 +391,7 @@ construct structured values to assign to specific headers.
391391
*domain*, in which case *username* and *domain* will be parsed from the
392392
*addr_spec*. An *addr_spec* must be a properly RFC quoted string; if it is
393393
not ``Address`` will raise an error. Unicode characters are allowed and
394-
will be property encoded when serialized. However, per the RFCs, unicode is
394+
will be property encoded when serialized. However, per the RFCs, Unicode is
395395
*not* allowed in the username portion of the address.
396396

397397
.. attribute:: display_name

Doc/library/email.policy.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ added matters. To illustrate::
493493
Otherwise the *name*, and the *value* with any CR or LF characters
494494
removed, are passed to the ``header_factory``, and the resulting
495495
header object is returned. Any surrogateescaped bytes get turned into
496-
the unicode unknown-character glyph.
496+
the Unicode unknown-character glyph.
497497

498498

499499
.. method:: fold(name, value)
@@ -588,10 +588,10 @@ the email package is changed from the Python 3.2 API in the following ways:
588588

589589
From the application view, this means that any header obtained through the
590590
:class:`~email.message.EmailMessage` is a header object with extra
591-
attributes, whose string value is the fully decoded unicode value of the
591+
attributes, whose string value is the fully decoded value of the
592592
header. Likewise, a header may be assigned a new value, or a new header
593-
created, using a unicode string, and the policy will take care of converting
594-
the unicode string into the correct RFC encoded form.
593+
created, using a string, and the policy will take care of converting
594+
the string into the correct RFC encoded form.
595595

596596
The header objects and their attributes are described in
597597
:mod:`~email.headerregistry`.

Doc/library/email.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ server.
5757

5858
The email package does its best to hide the details of the various governing
5959
RFCs from the application. Conceptually the application should be able to
60-
treat the email message as a structured tree of unicode text and binary
60+
treat the email message as a structured tree of Unicode text and binary
6161
attachments, without having to worry about how these are represented when
6262
serialized. In practice, however, it is often necessary to be aware of at
6363
least some of the rules governing MIME messages and their structure,
@@ -87,7 +87,7 @@ to advanced applications.
8787
Following those is a set of examples of using the fundamental parts of the APIs
8888
covered in the preceding sections.
8989

90-
The foregoing represent the modern (unicode friendly) API of the email package.
90+
The foregoing represent the modern (Unicode friendly) API of the email package.
9191
The remaining sections, starting with the :class:`~email.message.Message`
9292
class, cover the legacy :data:`~email.policy.compat32` API that deals much more
9393
directly with the details of how email messages are represented. The

Doc/library/email.utils.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ of the new API.
205205
When a header parameter is encoded in :rfc:`2231` format,
206206
:meth:`Message.get_param <email.message.Message.get_param>` may return a
207207
3-tuple containing the character set,
208-
language, and value. :func:`collapse_rfc2231_value` turns this into a unicode
208+
language, and value. :func:`collapse_rfc2231_value` turns this into a
209209
string. Optional *errors* is passed to the *errors* argument of :class:`str`'s
210210
:func:`~str.encode` method; it defaults to ``'replace'``. Optional
211211
*fallback_charset* specifies the character set to use if the one in the

Lib/email/_encoded_words.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ def decode(ew):
161161
This function expects exactly such a string (that is, it does not check the
162162
syntax and may raise errors if the string is not well formed), and returns
163163
the encoded_string decoded first from its Content Transfer Encoding and
164-
then from the resulting bytes into unicode using the specified charset. If
165-
the cte-decoded string does not successfully decode using the specified
164+
then from the resulting bytes into a string using the specified charset.
165+
If the cte-decoded string does not successfully decode using the specified
166166
character set, a defect is added to the defects list and the unknown octets
167-
are replaced by the unicode 'unknown' character \\uFDFF.
167+
are replaced by the Unicode 'unknown' character \\uFDFF.
168168
169169
The specified charset and language are returned. The default for language,
170170
which is rarely if ever encountered, is the empty string.
@@ -176,7 +176,7 @@ def decode(ew):
176176
# Recover the original bytes and do CTE decoding.
177177
bstring = cte_string.encode('ascii', 'surrogateescape')
178178
bstring, defects = _cte_decoders[cte](bstring)
179-
# Turn the CTE decoded bytes into unicode.
179+
# Turn the CTE decoded bytes into a string.
180180
try:
181181
string = bstring.decode(charset)
182182
except UnicodeDecodeError:

Lib/email/_policybase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def _fold(self, name, value, sanitize):
365365
charset=_charset.UNKNOWN8BIT,
366366
header_name=name)
367367
else:
368-
# If we have raw 8bit data in a byte string, we have no idea
368+
# If we have raw 8bit data in a string, we have no idea
369369
# what the encoding is. There is no safe way to split this
370370
# string. If it's ascii-subset, then we could do a normal
371371
# ascii split, but if it's multibyte then we could break the

0 commit comments

Comments
 (0)