Skip to content

Commit 7686f3a

Browse files
authored
Merge branch 'main' into patch/httpserver-test-131178
2 parents f735ee5 + 175ba36 commit 7686f3a

File tree

11 files changed

+169
-72
lines changed

11 files changed

+169
-72
lines changed

Doc/library/base64.rst

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,17 @@
1515

1616
This module provides functions for encoding binary data to printable
1717
ASCII characters and decoding such encodings back to binary data.
18-
It provides encoding and decoding functions for the encodings specified in
19-
:rfc:`4648`, which defines the Base16, Base32, and Base64 algorithms,
20-
and for the de-facto standard Ascii85 and Base85 encodings.
21-
22-
The :rfc:`4648` encodings are suitable for encoding binary data so that it can be
23-
safely sent by email, used as parts of URLs, or included as part of an HTTP
24-
POST request. The encoding algorithm is not the same as the
25-
:program:`uuencode` program.
18+
This includes the :ref:`encodings specified in <base64-rfc-4648>`
19+
:rfc:`4648` (Base64, Base32 and Base16)
20+
and the non-standard :ref:`Base85 encodings <base64-base-85>`.
2621

2722
There are two interfaces provided by this module. The modern interface
2823
supports encoding :term:`bytes-like objects <bytes-like object>` to ASCII
2924
:class:`bytes`, and decoding :term:`bytes-like objects <bytes-like object>` or
3025
strings containing ASCII to :class:`bytes`. Both base-64 alphabets
3126
defined in :rfc:`4648` (normal, and URL- and filesystem-safe) are supported.
3227

33-
The legacy interface does not support decoding from strings, but it does
28+
The :ref:`legacy interface <base64-legacy>` does not support decoding from strings, but it does
3429
provide functions for encoding and decoding to and from :term:`file objects
3530
<file object>`. It only supports the Base64 standard alphabet, and it adds
3631
newlines every 76 characters as per :rfc:`2045`. Note that if you are looking
@@ -46,7 +41,15 @@ package instead.
4641
Any :term:`bytes-like objects <bytes-like object>` are now accepted by all
4742
encoding and decoding functions in this module. Ascii85/Base85 support added.
4843

49-
The modern interface provides:
44+
45+
.. _base64-rfc-4648:
46+
47+
RFC 4648 Encodings
48+
------------------
49+
50+
The :rfc:`4648` encodings are suitable for encoding binary data so that it can be
51+
safely sent by email, used as parts of URLs, or included as part of an HTTP
52+
POST request.
5053

5154
.. function:: b64encode(s, altchars=None)
5255

@@ -181,6 +184,26 @@ The modern interface provides:
181184
incorrectly padded or if there are non-alphabet characters present in the
182185
input.
183186

187+
.. _base64-base-85:
188+
189+
Base85 Encodings
190+
-----------------
191+
192+
Base85 encoding is not formally specified but rather a de facto standard,
193+
thus different systems perform the encoding differently.
194+
195+
The :func:`a85encode` and :func:`b85encode` functions in this module are two implementations of
196+
the de facto standard. You should call the function with the Base85
197+
implementation used by the software you intend to work with.
198+
199+
The two functions present in this module differ in how they handle the following:
200+
201+
* Whether to include enclosing ``<~`` and ``~>`` markers
202+
* Whether to include newline characters
203+
* The set of ASCII characters used for encoding
204+
* Handling of null bytes
205+
206+
Refer to the documentation of the individual functions for more information.
184207

185208
.. function:: a85encode(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False)
186209

@@ -262,7 +285,10 @@ The modern interface provides:
262285
.. versionadded:: 3.13
263286

264287

265-
The legacy interface:
288+
.. _base64-legacy:
289+
290+
Legacy Interface
291+
----------------
266292

267293
.. function:: decode(input, output)
268294

Doc/whatsnew/3.13.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,22 @@ asyncio
730730
never awaited).
731731
(Contributed by Arthur Tacca and Jason Zhang in :gh:`115957`.)
732732

733+
* The function and methods named ``create_task`` have received a new
734+
``**kwargs`` argument that is passed through to the task constructor.
735+
This change was accidentally added in 3.13.3,
736+
and broke the API contract for custom task factories.
737+
Several third-party task factories implemented workarounds for this.
738+
In 3.13.4 and later releases the old factory contract is honored
739+
once again (until 3.14).
740+
To keep the workarounds working, the extra ``**kwargs`` argument still
741+
allows passing additional keyword arguments to :class:`~asyncio.Task`
742+
and to custom task factories.
743+
744+
This affects the following function and methods:
745+
:meth:`asyncio.create_task`,
746+
:meth:`asyncio.loop.create_task`,
747+
:meth:`asyncio.TaskGroup.create_task`.
748+
(Contributed by Thomas Grainger in :gh:`128307`.)
733749

734750
base64
735751
------

Doc/whatsnew/3.14.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,24 @@ ast
10641064
(Contributed by Semyon Moroz in :gh:`133367`.)
10651065

10661066

1067+
asyncio
1068+
-------
1069+
1070+
* The function and methods named :func:`!create_task` now take an arbitrary
1071+
list of keyword arguments. All keyword arguments are passed to the
1072+
:class:`~asyncio.Task` constructor or the custom task factory.
1073+
(See :meth:`~asyncio.loop.set_task_factory` for details.)
1074+
The ``name`` and ``context`` keyword arguments are no longer special;
1075+
the name should now be set using the ``name`` keyword argument of the factory,
1076+
and ``context`` may be ``None``.
1077+
1078+
This affects the following function and methods:
1079+
:meth:`asyncio.create_task`,
1080+
:meth:`asyncio.loop.create_task`,
1081+
:meth:`asyncio.TaskGroup.create_task`.
1082+
(Contributed by Thomas Grainger in :gh:`128307`.)
1083+
1084+
10671085
bdb
10681086
---
10691087

Lib/fractions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,6 @@ def __new__(cls, numerator=0, denominator=None):
238238
self._denominator = 1
239239
return self
240240

241-
elif isinstance(numerator, numbers.Rational):
242-
self._numerator = numerator.numerator
243-
self._denominator = numerator.denominator
244-
return self
245-
246241
elif (isinstance(numerator, float) or
247242
(not isinstance(numerator, type) and
248243
hasattr(numerator, 'as_integer_ratio'))):
@@ -278,6 +273,11 @@ def __new__(cls, numerator=0, denominator=None):
278273
if m.group('sign') == '-':
279274
numerator = -numerator
280275

276+
elif isinstance(numerator, numbers.Rational):
277+
self._numerator = numerator.numerator
278+
self._denominator = numerator.denominator
279+
return self
280+
281281
else:
282282
raise TypeError("argument should be a string or a Rational "
283283
"instance or have the as_integer_ratio() method")

Lib/test/pythoninfo.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,16 @@ def collect_zlib(info_add):
658658
copy_attributes(info_add, zlib, 'zlib.%s', attributes)
659659

660660

661+
def collect_zstd(info_add):
662+
try:
663+
import _zstd
664+
except ImportError:
665+
return
666+
667+
attributes = ('zstd_version',)
668+
copy_attributes(info_add, _zstd, 'zstd.%s', attributes)
669+
670+
661671
def collect_expat(info_add):
662672
try:
663673
from xml.parsers import expat
@@ -1051,6 +1061,7 @@ def collect_info(info):
10511061
collect_tkinter,
10521062
collect_windows,
10531063
collect_zlib,
1064+
collect_zstd,
10541065
collect_libregrtest_utils,
10551066

10561067
# Collecting from tests should be last as they have side effects.

Lib/test/test_cmd_line.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -972,10 +972,25 @@ def test_python_legacy_windows_fs_encoding(self):
972972

973973
@unittest.skipUnless(support.MS_WINDOWS, 'Test only applicable on Windows')
974974
def test_python_legacy_windows_stdio(self):
975-
code = "import sys; print(sys.stdin.encoding, sys.stdout.encoding)"
976-
expected = 'cp'
977-
rc, out, err = assert_python_ok('-c', code, PYTHONLEGACYWINDOWSSTDIO='1')
978-
self.assertIn(expected.encode(), out)
975+
# Test that _WindowsConsoleIO is used when PYTHONLEGACYWINDOWSSTDIO
976+
# is not set.
977+
# We cannot use PIPE becase it prevents creating new console.
978+
# So we use exit code.
979+
code = "import sys; sys.exit(type(sys.stdout.buffer.raw).__name__ != '_WindowsConsoleIO')"
980+
env = os.environ.copy()
981+
env["PYTHONLEGACYWINDOWSSTDIO"] = ""
982+
p = subprocess.run([sys.executable, "-c", code],
983+
creationflags=subprocess.CREATE_NEW_CONSOLE,
984+
env=env)
985+
self.assertEqual(p.returncode, 0)
986+
987+
# Then test that FIleIO is used when PYTHONLEGACYWINDOWSSTDIO is set.
988+
code = "import sys; sys.exit(type(sys.stdout.buffer.raw).__name__ != 'FileIO')"
989+
env["PYTHONLEGACYWINDOWSSTDIO"] = "1"
990+
p = subprocess.run([sys.executable, "-c", code],
991+
creationflags=subprocess.CREATE_NEW_CONSOLE,
992+
env=env)
993+
self.assertEqual(p.returncode, 0)
979994

980995
@unittest.skipIf("-fsanitize" in sysconfig.get_config_vars().get('PY_CFLAGS', ()),
981996
"PYTHONMALLOCSTATS doesn't work with ASAN")

0 commit comments

Comments
 (0)