Skip to content

Commit 9cd6ebe

Browse files
Merge branch 'main' into binary-op-extend
2 parents c9c716f + 70e67f5 commit 9cd6ebe

File tree

22 files changed

+314
-454
lines changed

22 files changed

+314
-454
lines changed

Doc/faq/programming.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,13 +1226,13 @@ This converts the list into a set, thereby removing duplicates, and then back
12261226
into a list.
12271227

12281228

1229-
How do you remove multiple items from a list
1230-
--------------------------------------------
1229+
How do you remove multiple items from a list?
1230+
---------------------------------------------
12311231

12321232
As with removing duplicates, explicitly iterating in reverse with a
12331233
delete condition is one possibility. However, it is easier and faster
12341234
to use slice replacement with an implicit or explicit forward iteration.
1235-
Here are three variations.::
1235+
Here are three variations::
12361236

12371237
mylist[:] = filter(keep_function, mylist)
12381238
mylist[:] = (x for x in mylist if keep_condition)

Doc/library/importlib.rst

Lines changed: 0 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -596,172 +596,6 @@ ABC hierarchy::
596596
itself does not end in ``__init__``.
597597

598598

599-
.. class:: ResourceReader
600-
601-
*Superseded by TraversableResources*
602-
603-
An :term:`abstract base class` to provide the ability to read
604-
*resources*.
605-
606-
From the perspective of this ABC, a *resource* is a binary
607-
artifact that is shipped within a package. Typically this is
608-
something like a data file that lives next to the ``__init__.py``
609-
file of the package. The purpose of this class is to help abstract
610-
out the accessing of such data files so that it does not matter if
611-
the package and its data file(s) are stored e.g. in a zip file
612-
versus on the file system.
613-
614-
For any of methods of this class, a *resource* argument is
615-
expected to be a :term:`path-like object` which represents
616-
conceptually just a file name. This means that no subdirectory
617-
paths should be included in the *resource* argument. This is
618-
because the location of the package the reader is for, acts as the
619-
"directory". Hence the metaphor for directories and file
620-
names is packages and resources, respectively. This is also why
621-
instances of this class are expected to directly correlate to
622-
a specific package (instead of potentially representing multiple
623-
packages or a module).
624-
625-
Loaders that wish to support resource reading are expected to
626-
provide a method called ``get_resource_reader(fullname)`` which
627-
returns an object implementing this ABC's interface. If the module
628-
specified by fullname is not a package, this method should return
629-
:const:`None`. An object compatible with this ABC should only be
630-
returned when the specified module is a package.
631-
632-
.. versionadded:: 3.7
633-
634-
.. deprecated-removed:: 3.12 3.14
635-
Use :class:`importlib.resources.abc.TraversableResources` instead.
636-
637-
.. method:: open_resource(resource)
638-
:abstractmethod:
639-
640-
Returns an opened, :term:`file-like object` for binary reading
641-
of the *resource*.
642-
643-
If the resource cannot be found, :exc:`FileNotFoundError` is
644-
raised.
645-
646-
.. method:: resource_path(resource)
647-
:abstractmethod:
648-
649-
Returns the file system path to the *resource*.
650-
651-
If the resource does not concretely exist on the file system,
652-
raise :exc:`FileNotFoundError`.
653-
654-
.. method:: is_resource(name)
655-
:abstractmethod:
656-
657-
Returns ``True`` if the named *name* is considered a resource.
658-
:exc:`FileNotFoundError` is raised if *name* does not exist.
659-
660-
.. method:: contents()
661-
:abstractmethod:
662-
663-
Returns an :term:`iterable` of strings over the contents of
664-
the package. Do note that it is not required that all names
665-
returned by the iterator be actual resources, e.g. it is
666-
acceptable to return names for which :meth:`is_resource` would
667-
be false.
668-
669-
Allowing non-resource names to be returned is to allow for
670-
situations where how a package and its resources are stored
671-
are known a priori and the non-resource names would be useful.
672-
For instance, returning subdirectory names is allowed so that
673-
when it is known that the package and resources are stored on
674-
the file system then those subdirectory names can be used
675-
directly.
676-
677-
The abstract method returns an iterable of no items.
678-
679-
680-
.. class:: Traversable
681-
682-
An object with a subset of :class:`pathlib.Path` methods suitable for
683-
traversing directories and opening files.
684-
685-
For a representation of the object on the file-system, use
686-
:meth:`importlib.resources.as_file`.
687-
688-
.. versionadded:: 3.9
689-
690-
.. deprecated-removed:: 3.12 3.14
691-
Use :class:`importlib.resources.abc.Traversable` instead.
692-
693-
.. attribute:: name
694-
695-
Abstract. The base name of this object without any parent references.
696-
697-
.. method:: iterdir()
698-
:abstractmethod:
699-
700-
Yield ``Traversable`` objects in ``self``.
701-
702-
.. method:: is_dir()
703-
:abstractmethod:
704-
705-
Return ``True`` if ``self`` is a directory.
706-
707-
.. method:: is_file()
708-
:abstractmethod:
709-
710-
Return ``True`` if ``self`` is a file.
711-
712-
.. method:: joinpath(child)
713-
:abstractmethod:
714-
715-
Return Traversable child in ``self``.
716-
717-
.. method:: __truediv__(child)
718-
:abstractmethod:
719-
720-
Return ``Traversable`` child in ``self``.
721-
722-
.. method:: open(mode='r', *args, **kwargs)
723-
:abstractmethod:
724-
725-
*mode* may be 'r' or 'rb' to open as text or binary. Return a handle
726-
suitable for reading (same as :attr:`pathlib.Path.open`).
727-
728-
When opening as text, accepts encoding parameters such as those
729-
accepted by :class:`io.TextIOWrapper`.
730-
731-
.. method:: read_bytes()
732-
733-
Read contents of ``self`` as bytes.
734-
735-
.. method:: read_text(encoding=None)
736-
737-
Read contents of ``self`` as text.
738-
739-
740-
.. class:: TraversableResources
741-
742-
An abstract base class for resource readers capable of serving
743-
the :meth:`importlib.resources.files` interface. Subclasses
744-
:class:`importlib.resources.abc.ResourceReader` and provides
745-
concrete implementations of the :class:`importlib.resources.abc.ResourceReader`'s
746-
abstract methods. Therefore, any loader supplying
747-
:class:`importlib.abc.TraversableResources` also supplies ResourceReader.
748-
749-
Loaders that wish to support resource reading are expected to
750-
implement this interface.
751-
752-
.. versionadded:: 3.9
753-
754-
.. deprecated-removed:: 3.12 3.14
755-
Use :class:`importlib.resources.abc.TraversableResources` instead.
756-
757-
.. method:: files()
758-
:abstractmethod:
759-
760-
Returns a :class:`importlib.resources.abc.Traversable` object for the loaded
761-
package.
762-
763-
764-
765599
:mod:`importlib.machinery` -- Importers and path hooks
766600
------------------------------------------------------
767601

Doc/library/inspect.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
524524

525525
.. versionchanged:: 3.13
526526
Functions wrapped in :func:`functools.partialmethod` now return ``True``
527-
if the wrapped function is a :term:`coroutine function`.
527+
if the wrapped function is a :term:`asynchronous generator` function.
528528

529529
.. function:: isasyncgen(object)
530530

Doc/library/msvcrt.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
99

10+
**Source code:** :source:`PC/msvcrtmodule.c`
11+
1012
--------------
1113

1214
These functions provide access to some useful capabilities on Windows platforms.

Doc/library/winreg.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
.. sectionauthor:: Mark Hammond <MarkH@ActiveState.com>
99

10+
**Source code:** :source:`PC/winreg.c`
11+
1012
--------------
1113

1214
These functions expose the Windows registry API to Python. Instead of using an
@@ -25,7 +27,7 @@ to explicitly close them.
2527
.. _functions:
2628

2729
Functions
28-
------------------
30+
---------
2931

3032
This module offers the following functions:
3133

@@ -554,7 +556,7 @@ This module offers the following functions:
554556
.. _constants:
555557

556558
Constants
557-
------------------
559+
---------
558560

559561
The following constants are defined for use in many :mod:`winreg` functions.
560562

Doc/library/winsound.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
.. moduleauthor:: Toby Dickenson <htrd90@zepler.org>
99
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
1010

11+
**Source code:** :source:`PC/winsound.c`
12+
1113
--------------
1214

1315
The :mod:`winsound` module provides access to the basic sound-playing machinery
@@ -16,6 +18,9 @@ provided by Windows platforms. It includes functions and several constants.
1618
.. availability:: Windows.
1719

1820

21+
Functions
22+
---------
23+
1924
.. function:: Beep(frequency, duration)
2025

2126
Beep the PC's speaker. The *frequency* parameter specifies frequency, in hertz,
@@ -46,6 +51,9 @@ provided by Windows platforms. It includes functions and several constants.
4651
error, :exc:`RuntimeError` is raised.
4752

4853

54+
Constants
55+
---------
56+
4957
.. data:: SND_FILENAME
5058

5159
The *sound* parameter is the name of a WAV file. Do not use with

Doc/whatsnew/3.7.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ new ABC for access to, opening, and reading *resources* inside packages.
604604
Resources are roughly similar to files inside packages, but they needn't
605605
be actual files on the physical file system. Module loaders can provide a
606606
:meth:`!get_resource_reader` function which returns
607-
a :class:`importlib.abc.ResourceReader` instance to support this
607+
a :class:`!importlib.abc.ResourceReader` instance to support this
608608
new API. Built-in file path loaders and zip file loaders both support this.
609609

610610
Contributed by Barry Warsaw and Brett Cannon in :issue:`32248`.
@@ -1043,7 +1043,7 @@ window are shown and hidden in the Options menu.
10431043
importlib
10441044
---------
10451045

1046-
The :class:`importlib.abc.ResourceReader` ABC was introduced to
1046+
The :class:`!importlib.abc.ResourceReader` ABC was introduced to
10471047
support the loading of resources from packages. See also
10481048
:ref:`whatsnew37_importlib_resources`.
10491049
(Contributed by Barry Warsaw, Brett Cannon in :issue:`32248`.)
@@ -2032,7 +2032,7 @@ both deprecated in Python 3.4 now emit :exc:`DeprecationWarning`.
20322032
(Contributed by Matthias Bussonnier in :issue:`29576`.)
20332033

20342034
The :class:`importlib.abc.ResourceLoader` ABC has been deprecated in
2035-
favour of :class:`importlib.abc.ResourceReader`.
2035+
favour of :class:`!importlib.abc.ResourceReader`.
20362036

20372037

20382038
locale

Lib/email/generator.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
NLCRE = re.compile(r'\r\n|\r|\n')
2323
fcre = re.compile(r'^From ', re.MULTILINE)
2424
NEWLINE_WITHOUT_FWSP = re.compile(r'\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]')
25+
NEWLINE_WITHOUT_FWSP_BYTES = re.compile(br'\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]')
2526

2627

2728
class Generator:
@@ -429,7 +430,16 @@ def _write_headers(self, msg):
429430
# This is almost the same as the string version, except for handling
430431
# strings with 8bit bytes.
431432
for h, v in msg.raw_items():
432-
self._fp.write(self.policy.fold_binary(h, v))
433+
folded = self.policy.fold_binary(h, v)
434+
if self.policy.verify_generated_headers:
435+
linesep = self.policy.linesep.encode()
436+
if not folded.endswith(linesep):
437+
raise HeaderWriteError(
438+
f'folded header does not end with {linesep!r}: {folded!r}')
439+
if NEWLINE_WITHOUT_FWSP_BYTES.search(folded.removesuffix(linesep)):
440+
raise HeaderWriteError(
441+
f'folded header contains newline: {folded!r}')
442+
self._fp.write(folded)
433443
# A blank line always separates headers from body
434444
self.write(self._NL)
435445

Lib/test/test_email/test_generator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def test_flatten_unicode_linesep(self):
313313
self.assertEqual(s.getvalue(), self.typ(expected))
314314

315315
def test_verify_generated_headers(self):
316-
"""gh-121650: by default the generator prevents header injection"""
316+
# gh-121650: by default the generator prevents header injection
317317
class LiteralHeader(str):
318318
name = 'Header'
319319
def fold(self, **kwargs):
@@ -334,6 +334,8 @@ def fold(self, **kwargs):
334334

335335
with self.assertRaises(email.errors.HeaderWriteError):
336336
message.as_string()
337+
with self.assertRaises(email.errors.HeaderWriteError):
338+
message.as_bytes()
337339

338340

339341
class TestBytesGenerator(TestGeneratorBase, TestEmailBase):

Lib/test/test_email/test_policy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def test_short_maxlen_error(self):
296296
policy.fold("Subject", subject)
297297

298298
def test_verify_generated_headers(self):
299-
"""Turning protection off allows header injection"""
299+
# Turning protection off allows header injection
300300
policy = email.policy.default.clone(verify_generated_headers=False)
301301
for text in (
302302
'Header: Value\r\nBad: Injection\r\n',
@@ -319,6 +319,10 @@ def fold(self, **kwargs):
319319
message.as_string(),
320320
f"{text}\nBody",
321321
)
322+
self.assertEqual(
323+
message.as_bytes(),
324+
f"{text}\nBody".encode(),
325+
)
322326

323327
# XXX: Need subclassing tests.
324328
# For adding subclassed objects, make sure the usual rules apply (subclass

0 commit comments

Comments
 (0)