From e2fd5f68edeeb72f2974a395e78123bcdb2690ea Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 12 May 2022 17:30:18 -0500 Subject: [PATCH 01/13] gh-92613: Deprecate the uuencode codec in codecs --- Lib/encodings/uu_codec.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/encodings/uu_codec.py b/Lib/encodings/uu_codec.py index 4e58c62fe9ef0f..fc733037c01632 100644 --- a/Lib/encodings/uu_codec.py +++ b/Lib/encodings/uu_codec.py @@ -7,13 +7,15 @@ modified by Jack Jansen and Fredrik Lundh. """ -import codecs import binascii +import codecs +import warnings from io import BytesIO ### Codec APIs def uu_encode(input, errors='strict', filename='', mode=0o666): + warnings._deprecated(__name__, remove=(3, 13)) assert errors == 'strict' infile = BytesIO(input) outfile = BytesIO() @@ -35,6 +37,7 @@ def uu_encode(input, errors='strict', filename='', mode=0o666): return (outfile.getvalue(), len(input)) def uu_decode(input, errors='strict'): + warnings._deprecated(__name__, remove=(3, 13)) assert errors == 'strict' infile = BytesIO(input) outfile = BytesIO() From ef6af615db178bca8cd94b4ed8e8b778031c9e66 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 12 May 2022 17:31:07 -0500 Subject: [PATCH 02/13] gh-92613: Silence uu-codec-related deprecation warnings in tests --- Lib/test/test_codecs.py | 52 +++++++++++++++++++++++++++++------------ Lib/test/test_uu.py | 4 +++- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index e3add0c1ee926c..601a2d616c43b6 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -8,7 +8,7 @@ from unittest import mock from test import support -from test.support import os_helper +from test.support import os_helper, warnings_helper try: import _testcapi @@ -2711,6 +2711,11 @@ def test_seek0(self): "rot_13": ["rot13"], } +deprecated_transforms = { + "uu_codec", +} + + try: import zlib except ImportError: @@ -2727,6 +2732,14 @@ def test_seek0(self): transform_aliases["bz2_codec"] = ["bz2"] +def _check_transform_warning(encoding): + """Helper to check that deprecated transforms warn and silence them.""" + if encoding not in deprecated_transforms: + return contextlib.nullcontext() + return warnings_helper.check_warnings( + (f".*({encoding}).*", DeprecationWarning)) + + class TransformCodecTest(unittest.TestCase): def test_basics(self): @@ -2734,26 +2747,30 @@ def test_basics(self): for encoding in bytes_transform_encodings: with self.subTest(encoding=encoding): # generic codecs interface - (o, size) = codecs.getencoder(encoding)(binput) + with _check_transform_warning(encoding): + (o, size) = codecs.getencoder(encoding)(binput) self.assertEqual(size, len(binput)) - (i, size) = codecs.getdecoder(encoding)(o) + with _check_transform_warning(encoding): + (i, size) = codecs.getdecoder(encoding)(o) self.assertEqual(size, len(o)) self.assertEqual(i, binput) def test_read(self): for encoding in bytes_transform_encodings: with self.subTest(encoding=encoding): - sin = codecs.encode(b"\x80", encoding) - reader = codecs.getreader(encoding)(io.BytesIO(sin)) - sout = reader.read() + with _check_transform_warning(encoding): + sin = codecs.encode(b"\x80", encoding) + reader = codecs.getreader(encoding)(io.BytesIO(sin)) + sout = reader.read() self.assertEqual(sout, b"\x80") def test_readline(self): for encoding in bytes_transform_encodings: with self.subTest(encoding=encoding): - sin = codecs.encode(b"\x80", encoding) - reader = codecs.getreader(encoding)(io.BytesIO(sin)) - sout = reader.readline() + with _check_transform_warning(encoding): + sin = codecs.encode(b"\x80", encoding) + reader = codecs.getreader(encoding)(io.BytesIO(sin)) + sout = reader.readline() self.assertEqual(sout, b"\x80") def test_buffer_api_usage(self): @@ -2765,13 +2782,16 @@ def test_buffer_api_usage(self): with self.subTest(encoding=encoding): data = original view = memoryview(data) - data = codecs.encode(data, encoding) - view_encoded = codecs.encode(view, encoding) + with _check_transform_warning(encoding): + data = codecs.encode(data, encoding) + view_encoded = codecs.encode(view, encoding) self.assertEqual(view_encoded, data) view = memoryview(data) - data = codecs.decode(data, encoding) + with _check_transform_warning(encoding): + data = codecs.decode(data, encoding) self.assertEqual(data, original) - view_decoded = codecs.decode(view, encoding) + with _check_transform_warning(encoding): + view_decoded = codecs.decode(view, encoding) self.assertEqual(view_decoded, data) def test_text_to_binary_denylists_binary_transforms(self): @@ -2799,7 +2819,8 @@ def test_binary_to_text_denylists_binary_transforms(self): data = b"encode first to ensure we meet any format restrictions" for encoding in bytes_transform_encodings: with self.subTest(encoding=encoding): - encoded_data = codecs.encode(data, encoding) + with _check_transform_warning(encoding): + encoded_data = codecs.encode(data, encoding) fmt = (r"{!r} is not a text encoding; " r"use codecs.decode\(\) to handle arbitrary codecs") msg = fmt.format(encoding) @@ -2857,7 +2878,8 @@ def test_quopri_stateless(self): def test_uu_invalid(self): # Missing "begin" line - self.assertRaises(ValueError, codecs.decode, b"", "uu-codec") + with _check_transform_warning("uu_codec"): + self.assertRaises(ValueError, codecs.decode, b"", "uu-codec") # The codec system tries to wrap exceptions in order to ensure the error diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py index 0493aae4fc67be..2c01160bb57588 100644 --- a/Lib/test/test_uu.py +++ b/Lib/test/test_uu.py @@ -135,7 +135,9 @@ def test_garbage_padding(self): with self.subTest("uu_codec"): import codecs - decoded = codecs.decode(encodedtext, "uu_codec") + with warnings_helper.check_warnings( + (".*uu_codec.*", DeprecationWarning)): + decoded = codecs.decode(encodedtext, "uu_codec") self.assertEqual(decoded, plaintext) def test_newlines_escaped(self): From 9b28da828ceab8686aad553810f0f1a4d16a28ac Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 12 May 2022 18:37:13 -0500 Subject: [PATCH 03/13] gh-92613: Add deprecation note to codecs docs for uuencode codec --- Doc/library/codecs.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/library/codecs.rst b/Doc/library/codecs.rst index 8225236350d22e..d2c1bce0a45159 100644 --- a/Doc/library/codecs.rst +++ b/Doc/library/codecs.rst @@ -1414,7 +1414,7 @@ to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode` | | quoted_printable | | :meth:`quopri.decode` | +----------------------+------------------+------------------------------+------------------------------+ | uu_codec | uu | Convert the operand using | :meth:`uu.encode` / | -| | | uuencode. | :meth:`uu.decode` | +| | | uuencode (deprecated). | :meth:`uu.decode` | +----------------------+------------------+------------------------------+------------------------------+ | zlib_codec | zip, zlib | Compress the operand using | :meth:`zlib.compress` / | | | | gzip. | :meth:`zlib.decompress` | @@ -1430,6 +1430,10 @@ to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode` .. versionchanged:: 3.4 Restoration of the aliases for the binary transforms. +.. deprecated-removed:: 3.11 3.13 + The uuencode codec (``uu_codec``) is deprecated + (see :pep:`PEP 594 <594#uu-and-the-uu-encoding>` for details). + .. _text-transforms: From 87b9035f62d34b2262b992401c0b18e9381bdc2b Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 12 May 2022 18:29:22 -0500 Subject: [PATCH 04/13] gh-92613: Deprecate built-in decoding support for uuencode in email --- Lib/email/message.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/email/message.py b/Lib/email/message.py index 65fda507251ce3..3ac9662844a6c3 100644 --- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -7,8 +7,9 @@ __all__ = ['Message', 'EmailMessage'] import binascii -import re import quopri +import re +import warnings from io import BytesIO, StringIO # Intrapackage imports @@ -318,6 +319,10 @@ def get_payload(self, i=None, decode=False): self.policy.handle_defect(self, defect) return value elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'): + warnings._deprecated( + 'Support for decoding legacy uuencoded payloads in messages ' + 'is deprecated and scheduled for removal in Python {remove}', + remove=(3, 13)) try: return _decode_uu(bpayload) except ValueError: From b42a4dbe23ecb13bb7557de83eb219b72a000f28 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 12 May 2022 18:30:16 -0500 Subject: [PATCH 05/13] gh-92613: Silence uuencode deprecation warnings in email tests --- Lib/test/test_email/test_email.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index 44b405740c4403..0bbdc7417df262 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -39,6 +39,7 @@ from email import utils from test.support import threading_helper +from test.support.warnings_helper import check_warnings from test.support.os_helper import unlink from test.test_email import openfile, TestEmailBase @@ -50,6 +51,8 @@ EMPTYSTRING = '' SPACE = ' ' +UU_WARNING_FILTER = ('.*uu.*', DeprecationWarning) + # Test various aspects of the Message class's API class TestMessageAPI(TestEmailBase): @@ -263,10 +266,12 @@ def test_get_decoded_uu_payload(self): msg.set_payload('begin 666 -\n+:&5L;&\\@=V]R;&0 \n \nend\n') for cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'): msg['content-transfer-encoding'] = cte - eq(msg.get_payload(decode=True), b'hello world') + with check_warnings(UU_WARNING_FILTER): + eq(msg.get_payload(decode=True), b'hello world') # Now try some bogus data msg.set_payload('foo') - eq(msg.get_payload(decode=True), b'foo') + with check_warnings(UU_WARNING_FILTER): + eq(msg.get_payload(decode=True), b'foo') def test_get_payload_n_raises_on_non_multipart(self): msg = Message() @@ -740,12 +745,13 @@ def test_binary_uuencode_payload(self): msg['content-type'] = 'text/plain; charset=%s' % charset msg['content-transfer-encoding'] = encoding msg.set_payload(b"begin 666 -\n)9F]OYI:'8F%R\n \nend\n") - self.assertEqual( - msg.get_payload(decode=True), - b'foo\xe6\x96\x87bar', - str(('get_payload returns wrong result ', - 'with charset {0} and encoding {1}.')).\ - format(charset, encoding)) + with check_warnings(UU_WARNING_FILTER): + self.assertEqual( + msg.get_payload(decode=True), + b'foo\xe6\x96\x87bar', + str(('get_payload returns wrong result ', + 'with charset {0} and encoding {1}.')).\ + format(charset, encoding)) def test_add_header_with_name_only_param(self): msg = Message() @@ -3963,8 +3969,9 @@ def test_8bit_in_uuencode_body(self): cte='uuencode', bodyline='<,.V Date: Thu, 12 May 2022 18:48:33 -0500 Subject: [PATCH 06/13] gh-92613: Add deprecation note for uuencode payloads to email.message --- Doc/library/email.compat32-message.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/library/email.compat32-message.rst b/Doc/library/email.compat32-message.rst index 5bef155a4af310..d5a7e352a58afa 100644 --- a/Doc/library/email.compat32-message.rst +++ b/Doc/library/email.compat32-message.rst @@ -227,6 +227,10 @@ Here are the methods of the :class:`Message` class: replaced by :meth:`~email.message.EmailMessage.get_content` and :meth:`~email.message.EmailMessage.iter_parts`. + .. deprecated-removed:: 3.11 3.13 + Decoding legacy uuencode payloads (with ``decode=True``) is deprecated + (see :pep:`PEP 594 <594#uu-and-the-uu-encoding>` for details). + .. method:: set_payload(payload, charset=None) From 45112865d6b722c680ce15ff324a196bcbc69382 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 12 May 2022 21:09:20 -0500 Subject: [PATCH 07/13] gh-92613: Add deprecation warning for binascii uuencode functions --- Modules/binascii.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Modules/binascii.c b/Modules/binascii.c index ffc2c59413613b..4bbfafaabcf871 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -223,6 +223,13 @@ binascii_a2b_uu_impl(PyObject *module, Py_buffer *data) Py_ssize_t ascii_len, bin_len; binascii_state *state; + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'binascii.a2b_uu' is deprecated and scheduled for " + "removal in Python 3.13", + 1)) { + return NULL; + } + ascii_data = data->buf; ascii_len = data->len; @@ -321,6 +328,13 @@ binascii_b2a_uu_impl(PyObject *module, Py_buffer *data, int backtick) Py_ssize_t bin_len, out_len; _PyBytesWriter writer; + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'binascii.b2a_uu' is deprecated and scheduled for " + "removal in Python 3.13", + 1)) { + return NULL; + } + _PyBytesWriter_Init(&writer); bin_data = data->buf; bin_len = data->len; From c10fd87bae3f557599d3af55fcf54b17986490d3 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 12 May 2022 21:10:40 -0500 Subject: [PATCH 08/13] gh-92613: Silence depr warnings for binascii uuencode that already warn --- Lib/email/message.py | 6 +++++- Lib/encodings/uu_codec.py | 28 +++++++++++++++++++++++----- Lib/uu.py | 23 ++++++++++++++++++++--- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Lib/email/message.py b/Lib/email/message.py index 3ac9662844a6c3..2aacbbcf597fbd 100644 --- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -324,7 +324,11 @@ def get_payload(self, i=None, decode=False): 'is deprecated and scheduled for removal in Python {remove}', remove=(3, 13)) try: - return _decode_uu(bpayload) + # We already issue our own warning here + with warnings.catch_warnings(): + warnings.filterwarnings( + 'ignore', message='.*uu.*', category=DeprecationWarning) + return _decode_uu(bpayload) except ValueError: # Some decoding problem. return bpayload diff --git a/Lib/encodings/uu_codec.py b/Lib/encodings/uu_codec.py index fc733037c01632..9a3322617a0766 100644 --- a/Lib/encodings/uu_codec.py +++ b/Lib/encodings/uu_codec.py @@ -12,6 +12,14 @@ import warnings from io import BytesIO + +_uu_deprecation_warning_filter = { + 'action': 'ignore', + 'message': '.*uu.*', + 'category': DeprecationWarning, +} + + ### Codec APIs def uu_encode(input, errors='strict', filename='', mode=0o666): @@ -29,9 +37,13 @@ def uu_encode(input, errors='strict', filename='', mode=0o666): # Encode write(('begin %o %s\n' % (mode & 0o777, filename)).encode('ascii')) chunk = read(45) - while chunk: - write(binascii.b2a_uu(chunk)) - chunk = read(45) + + # We already warn above on calling this function + with warnings.catch_warnings(): + warnings.filterwarnings(**_uu_deprecation_warning_filter) + while chunk: + write(binascii.b2a_uu(chunk)) + chunk = read(45) write(b' \nend\n') return (outfile.getvalue(), len(input)) @@ -58,11 +70,17 @@ def uu_decode(input, errors='strict'): if not s or s == b'end\n': break try: - data = binascii.a2b_uu(s) + # We already warn above on calling this function + with warnings.catch_warnings(): + warnings.filterwarnings(**_uu_deprecation_warning_filter) + data = binascii.a2b_uu(s) except binascii.Error as v: # Workaround for broken uuencoders by /Fredrik Lundh nbytes = (((s[0]-32) & 63) * 4 + 5) // 3 - data = binascii.a2b_uu(s[:nbytes]) + # We already warn above on calling this function + with warnings.catch_warnings(): + warnings.filterwarnings(**_uu_deprecation_warning_filter) + data = binascii.a2b_uu(s[:nbytes]) #sys.stderr.write("Warning: %s\n" % str(v)) write(data) if not s: diff --git a/Lib/uu.py b/Lib/uu.py index 6f8805d8c5d0c6..e22b97025ad724 100755 --- a/Lib/uu.py +++ b/Lib/uu.py @@ -39,6 +39,13 @@ __all__ = ["Error", "encode", "decode"] +_uu_deprecation_warning_filter = { + 'action': 'ignore', + 'message': '.*uu.*', + 'category': DeprecationWarning, +} + + class Error(Exception): pass @@ -89,7 +96,11 @@ def encode(in_file, out_file, name=None, mode=None, *, backtick=False): out_file.write(('begin %o %s\n' % ((mode & 0o777), name)).encode("ascii")) data = in_file.read(45) while len(data) > 0: - out_file.write(binascii.b2a_uu(data, backtick=backtick)) + # We already warn on import of this module + with warnings.catch_warnings(): + warnings.filterwarnings(**_uu_deprecation_warning_filter) + converted_data = binascii.b2a_uu(data, backtick=backtick) + out_file.write(converted_data) data = in_file.read(45) if backtick: out_file.write(b'`\nend\n') @@ -152,11 +163,17 @@ def decode(in_file, out_file=None, mode=None, quiet=False): s = in_file.readline() while s and s.strip(b' \t\r\n\f') != b'end': try: - data = binascii.a2b_uu(s) + # We already warn on import of this module + with warnings.catch_warnings(): + warnings.filterwarnings(**_uu_deprecation_warning_filter) + data = binascii.a2b_uu(s) except binascii.Error as v: # Workaround for broken uuencoders by /Fredrik Lundh nbytes = (((s[0]-32) & 63) * 4 + 5) // 3 - data = binascii.a2b_uu(s[:nbytes]) + # We already warn on import of this module + with warnings.catch_warnings(): + warnings.filterwarnings(**_uu_deprecation_warning_filter) + data = binascii.a2b_uu(s[:nbytes]) if not quiet: sys.stderr.write("Warning: %s\n" % v) out_file.write(data) From ec15dc649a5c6c41777c5c02b4f0ec30a83a1f55 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 12 May 2022 21:11:41 -0500 Subject: [PATCH 09/13] gh-92613: Suppress binascii uuencode deprecation warnings in tests --- Lib/test/test_binascii.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py index a2d7d0293ce1ae..221df7d9e35346 100644 --- a/Lib/test/test_binascii.py +++ b/Lib/test/test_binascii.py @@ -1,10 +1,11 @@ """Test the binascii C module.""" -import unittest -import binascii import array +import binascii +import contextlib import re -from test.support import bigmemtest, _1G, _4G +import unittest +from test.support import bigmemtest, _1G, _4G, warnings_helper # Note: "*_hex" functions are aliases for "(un)hexlify" @@ -14,6 +15,16 @@ 'unhexlify'] all_functions = a2b_functions + b2a_functions + ['crc32', 'crc_hqx'] +deprecated_functions = ['b2a_uu', 'a2b_uu'] + + +def _check_function_warning(function_name): + """Helper to check that deprecated functions warn, and silence them.""" + if function_name not in deprecated_functions: + return contextlib.nullcontext() + return warnings_helper.check_warnings( + (f".*{function_name}.*", DeprecationWarning)) + class BinASCIITest(unittest.TestCase): @@ -46,8 +57,10 @@ def test_returned_value(self): a2b = getattr(binascii, fa) b2a = getattr(binascii, fb) try: - a = b2a(self.type2test(raw)) - res = a2b(self.type2test(a)) + with _check_function_warning(fb): + a = b2a(self.type2test(raw)) + with _check_function_warning(fa): + res = a2b(self.type2test(a)) except Exception as err: self.fail("{}/{} conversion raises {!r}".format(fb, fa, err)) self.assertEqual(res, raw, "{}/{} conversion: " @@ -185,6 +198,8 @@ def assertInvalidLength(data): assertInvalidLength(b'a' * (4 * 87 + 1)) assertInvalidLength(b'A\tB\nC ??DE') # only 5 valid characters + # Uuencode is deprecated + @warnings_helper.ignore_warnings(category=DeprecationWarning) def test_uu(self): MAX_UU = 45 for backtick in (True, False): @@ -383,7 +398,8 @@ def test_empty_string(self): continue f = getattr(binascii, func) try: - f(empty) + with _check_function_warning(func): + f(empty) except Exception as err: self.fail("{}({!r}) raises {!r}".format(func, empty, err)) @@ -405,10 +421,13 @@ def test_unicode_a2b(self): a2b = getattr(binascii, fa) b2a = getattr(binascii, fb) try: - a = b2a(self.type2test(raw)) - binary_res = a2b(a) + with _check_function_warning(fb): + a = b2a(self.type2test(raw)) + with _check_function_warning(fa): + binary_res = a2b(a) a = a.decode('ascii') - res = a2b(a) + with _check_function_warning(fa): + res = a2b(a) except Exception as err: self.fail("{}/{} conversion raises {!r}".format(fb, fa, err)) self.assertEqual(res, raw, "{}/{} conversion: " From aabe3332fd1ac9064099f04d72d4de882526ec7c Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 12 May 2022 21:19:46 -0500 Subject: [PATCH 10/13] gh-92613: Add deprecation note for uuencode functions to binascii docs --- Doc/library/binascii.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/library/binascii.rst b/Doc/library/binascii.rst index 5a0815faa38eac..950bdb376a0398 100644 --- a/Doc/library/binascii.rst +++ b/Doc/library/binascii.rst @@ -38,6 +38,10 @@ The :mod:`binascii` module defines the following functions: data. Lines normally contain 45 (binary) bytes, except for the last line. Line data may be followed by whitespace. + .. deprecated-removed:: 3.11 3.13 + This function and the legacy uuencode format it implements are deprecated + (see :pep:`PEP 594 <594#uu-and-the-uu-encoding>` for details). + .. function:: b2a_uu(data, *, backtick=False) @@ -48,6 +52,10 @@ The :mod:`binascii` module defines the following functions: .. versionchanged:: 3.7 Added the *backtick* parameter. + .. deprecated-removed:: 3.11 3.13 + This function and the legacy uuencode format it implements are deprecated + (see :pep:`PEP 594 <594#uu-and-the-uu-encoding>` for details). + .. function:: a2b_base64(string, /, *, strict_mode=False) From b3ce3291ceef30bdffe2c9ce42fd108a3bf2dbeb Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 12 May 2022 22:11:23 -0500 Subject: [PATCH 11/13] gh-92613: Add News entry for uuencode deprecations --- .../Library/2022-05-12-22-05-49.gh-issue-92613.yQjMHl.rst | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-05-12-22-05-49.gh-issue-92613.yQjMHl.rst diff --git a/Misc/NEWS.d/next/Library/2022-05-12-22-05-49.gh-issue-92613.yQjMHl.rst b/Misc/NEWS.d/next/Library/2022-05-12-22-05-49.gh-issue-92613.yQjMHl.rst new file mode 100644 index 00000000000000..3ed39f5ffc5047 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-05-12-22-05-49.gh-issue-92613.yQjMHl.rst @@ -0,0 +1,8 @@ +Per :pep:`PEP 594 <594#uu-and-the-uu-encoding>`, deprecate other +uuencode-related functionality with appropriate warnings, and document them. +This includes :func:`binascii.a2b_uu`/:func:`binascii.b2a_uu`, +the ``uu_codec`` :ref:`binary transform ` +in the :mod:`codecs` module, and support for decoding uuencode payloads +with the :meth:`email.message.Message.get_payload` method of the legacy +:ref:`email.message.Message ` (``Compat32``) API. +Contributed by C.A.M. Gerlach. From 53141f598e21a75791dca30572ff423ab83bb106 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Wed, 10 Aug 2022 23:28:19 -0500 Subject: [PATCH 12/13] Update uuencode deprecation messages to reflect bump to Python 3.12 --- Doc/library/binascii.rst | 4 ++-- Doc/library/codecs.rst | 2 +- Doc/library/email.compat32-message.rst | 2 +- Doc/whatsnew/3.12.rst | 18 ++++++++++++++++++ Lib/email/message.py | 2 +- Lib/encodings/uu_codec.py | 4 ++-- ...22-05-12-22-05-49.gh-issue-92613.yQjMHl.rst | 11 +++++++---- Modules/binascii.c | 4 ++-- 8 files changed, 34 insertions(+), 13 deletions(-) diff --git a/Doc/library/binascii.rst b/Doc/library/binascii.rst index 950bdb376a0398..31461fabac2854 100644 --- a/Doc/library/binascii.rst +++ b/Doc/library/binascii.rst @@ -38,7 +38,7 @@ The :mod:`binascii` module defines the following functions: data. Lines normally contain 45 (binary) bytes, except for the last line. Line data may be followed by whitespace. - .. deprecated-removed:: 3.11 3.13 + .. deprecated-removed:: 3.12 3.14 This function and the legacy uuencode format it implements are deprecated (see :pep:`PEP 594 <594#uu-and-the-uu-encoding>` for details). @@ -52,7 +52,7 @@ The :mod:`binascii` module defines the following functions: .. versionchanged:: 3.7 Added the *backtick* parameter. - .. deprecated-removed:: 3.11 3.13 + .. deprecated-removed:: 3.12 3.14 This function and the legacy uuencode format it implements are deprecated (see :pep:`PEP 594 <594#uu-and-the-uu-encoding>` for details). diff --git a/Doc/library/codecs.rst b/Doc/library/codecs.rst index d2c1bce0a45159..d1fef1ad0a879a 100644 --- a/Doc/library/codecs.rst +++ b/Doc/library/codecs.rst @@ -1430,7 +1430,7 @@ to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode` .. versionchanged:: 3.4 Restoration of the aliases for the binary transforms. -.. deprecated-removed:: 3.11 3.13 +.. deprecated-removed:: 3.12 3.14 The uuencode codec (``uu_codec``) is deprecated (see :pep:`PEP 594 <594#uu-and-the-uu-encoding>` for details). diff --git a/Doc/library/email.compat32-message.rst b/Doc/library/email.compat32-message.rst index d5a7e352a58afa..10810ad343f7b8 100644 --- a/Doc/library/email.compat32-message.rst +++ b/Doc/library/email.compat32-message.rst @@ -227,7 +227,7 @@ Here are the methods of the :class:`Message` class: replaced by :meth:`~email.message.EmailMessage.get_content` and :meth:`~email.message.EmailMessage.iter_parts`. - .. deprecated-removed:: 3.11 3.13 + .. deprecated-removed:: 3.12 3.14 Decoding legacy uuencode payloads (with ``decode=True``) is deprecated (see :pep:`PEP 594 <594#uu-and-the-uu-encoding>` for details). diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 7ebfc5537c7a3d..36fdee882cf243 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -348,6 +348,24 @@ Deprecated and tailor them to your needs. (Contributed by Erlend E. Aasland in :gh:`90016`.) +* Per :pep:`PEP 594 <594#uu-and-the-uu-encoding>`, + the remaining functionality related to the legacy + `uuencode encoding `__ + (also exposed in the to-be-removed :mod:`uu` module) has been deprecated, + and will be removed in Python 3.14: + + * :func:`binascii.a2b_uu` and :func:`binascii.b2a_uu`, + low-level interfaces for decoding and encoding uuencode data. + * The ``uu_codec`` :ref:`binary transform ` + in the :mod:`codecs` module, + implementing uuencode as a Python codec + * Support for decoding non-MIME uuencode payloads + with the :meth:`email.message.Message.get_payload` method + of the legacy :ref:`email.message.Message ` + (:attr:`email.policy.Compat32`) API. + + (Contributed by C.A.M. Gerlach in :gh:`92613`.) + * The 3-arg signatures (type, value, traceback) of :meth:`~coroutine.throw`, :meth:`~generator.throw` and :meth:`~agen.athrow` are deprecated and may be removed in a future version of Python. Use the single-arg versions diff --git a/Lib/email/message.py b/Lib/email/message.py index 2aacbbcf597fbd..2c5ca25cd502d0 100644 --- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -322,7 +322,7 @@ def get_payload(self, i=None, decode=False): warnings._deprecated( 'Support for decoding legacy uuencoded payloads in messages ' 'is deprecated and scheduled for removal in Python {remove}', - remove=(3, 13)) + remove=(3, 14)) try: # We already issue our own warning here with warnings.catch_warnings(): diff --git a/Lib/encodings/uu_codec.py b/Lib/encodings/uu_codec.py index 9a3322617a0766..1750001137e30f 100644 --- a/Lib/encodings/uu_codec.py +++ b/Lib/encodings/uu_codec.py @@ -23,7 +23,7 @@ ### Codec APIs def uu_encode(input, errors='strict', filename='', mode=0o666): - warnings._deprecated(__name__, remove=(3, 13)) + warnings._deprecated(__name__, remove=(3, 14)) assert errors == 'strict' infile = BytesIO(input) outfile = BytesIO() @@ -49,7 +49,7 @@ def uu_encode(input, errors='strict', filename='', mode=0o666): return (outfile.getvalue(), len(input)) def uu_decode(input, errors='strict'): - warnings._deprecated(__name__, remove=(3, 13)) + warnings._deprecated(__name__, remove=(3, 14)) assert errors == 'strict' infile = BytesIO(input) outfile = BytesIO() diff --git a/Misc/NEWS.d/next/Library/2022-05-12-22-05-49.gh-issue-92613.yQjMHl.rst b/Misc/NEWS.d/next/Library/2022-05-12-22-05-49.gh-issue-92613.yQjMHl.rst index 3ed39f5ffc5047..236fe105115923 100644 --- a/Misc/NEWS.d/next/Library/2022-05-12-22-05-49.gh-issue-92613.yQjMHl.rst +++ b/Misc/NEWS.d/next/Library/2022-05-12-22-05-49.gh-issue-92613.yQjMHl.rst @@ -1,8 +1,11 @@ -Per :pep:`PEP 594 <594#uu-and-the-uu-encoding>`, deprecate other -uuencode-related functionality with appropriate warnings, and document them. +Per :pep:`PEP 594 <594#uu-and-the-uu-encoding>`, +deprecate other uuencode-related functionality with appropriate warnings, +and document them as scheduled for removal in Python 3.14. This includes :func:`binascii.a2b_uu`/:func:`binascii.b2a_uu`, the ``uu_codec`` :ref:`binary transform ` -in the :mod:`codecs` module, and support for decoding uuencode payloads -with the :meth:`email.message.Message.get_payload` method of the legacy +in the :mod:`codecs` module, +and support for decoding uuencode payloads +with the :meth:`email.message.Message.get_payload` method +of the legacy :ref:`email.message.Message ` (``Compat32``) API. Contributed by C.A.M. Gerlach. diff --git a/Modules/binascii.c b/Modules/binascii.c index 4bbfafaabcf871..e4d22682d2b158 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -225,7 +225,7 @@ binascii_a2b_uu_impl(PyObject *module, Py_buffer *data) if (PyErr_WarnEx(PyExc_DeprecationWarning, "'binascii.a2b_uu' is deprecated and scheduled for " - "removal in Python 3.13", + "removal in Python 3.14", 1)) { return NULL; } @@ -330,7 +330,7 @@ binascii_b2a_uu_impl(PyObject *module, Py_buffer *data, int backtick) if (PyErr_WarnEx(PyExc_DeprecationWarning, "'binascii.b2a_uu' is deprecated and scheduled for " - "removal in Python 3.13", + "removal in Python 3.14", 1)) { return NULL; } From e4632af2c1e42014148177fc53b3e13f58aaf990 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Tue, 8 Nov 2022 15:38:53 -0600 Subject: [PATCH 13/13] Call warnings._deprecated correctly for uu message payload decode --- Lib/email/message.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/email/message.py b/Lib/email/message.py index 2c5ca25cd502d0..49c1e0457d89e6 100644 --- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -320,8 +320,7 @@ def get_payload(self, i=None, decode=False): return value elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'): warnings._deprecated( - 'Support for decoding legacy uuencoded payloads in messages ' - 'is deprecated and scheduled for removal in Python {remove}', + 'Decoding legacy uuencoded payloads in messages', remove=(3, 14)) try: # We already issue our own warning here