From dbc8216f4c00ea40b0c2d3ca487e5afeb4b0e0b1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 25 May 2023 16:25:27 +0200 Subject: gh-104773: PEP 594: Remove the uu module (#104932) Doc/license.rst: Keep the UUencode and UUdecode license since it's also used by the uu codec. --- Doc/library/binascii.rst | 6 +- Doc/library/superseded.rst | 1 - Doc/library/uu.rst | 72 ------ Doc/license.rst | 2 +- Doc/whatsnew/3.11.rst | 2 +- Doc/whatsnew/3.12.rst | 2 +- Doc/whatsnew/3.13.rst | 4 + Doc/whatsnew/3.7.rst | 2 +- Lib/test/test_uu.py | 287 --------------------- Lib/uu.py | 216 ---------------- Misc/NEWS.d/3.12.0b1.rst | 2 +- .../2023-05-25-15-54-02.gh-issue-104773.nW-5MI.rst | 2 + Python/stdlib_module_names.h | 1 - Tools/wasm/wasm_assets.py | 2 - 14 files changed, 12 insertions(+), 589 deletions(-) delete mode 100644 Doc/library/uu.rst delete mode 100644 Lib/test/test_uu.py delete mode 100644 Lib/uu.py create mode 100644 Misc/NEWS.d/next/Library/2023-05-25-15-54-02.gh-issue-104773.nW-5MI.rst diff --git a/Doc/library/binascii.rst b/Doc/library/binascii.rst index 21960cb..e9f6f0e 100644 --- a/Doc/library/binascii.rst +++ b/Doc/library/binascii.rst @@ -6,14 +6,13 @@ representations. .. index:: - pair: module; uu pair: module; base64 -------------- The :mod:`binascii` module contains a number of methods to convert between binary and various ASCII-encoded binary representations. Normally, you will not -use these functions directly but use wrapper modules like :mod:`uu` or +use these functions directly but use wrapper modules like :mod:`base64` instead. The :mod:`binascii` module contains low-level functions written in C for greater speed that are used by the higher-level modules. @@ -179,8 +178,5 @@ The :mod:`binascii` module defines the following functions: Support for RFC compliant base64-style encoding in base 16, 32, 64, and 85. - Module :mod:`uu` - Support for UU encoding used on Unix. - Module :mod:`quopri` Support for quoted-printable encoding used in MIME email messages. diff --git a/Doc/library/superseded.rst b/Doc/library/superseded.rst index 284716e..7e05f0e 100644 --- a/Doc/library/superseded.rst +++ b/Doc/library/superseded.rst @@ -15,4 +15,3 @@ backwards compatibility. They have been superseded by other modules. chunk.rst imghdr.rst optparse.rst - uu.rst diff --git a/Doc/library/uu.rst b/Doc/library/uu.rst deleted file mode 100644 index 83c4aec..0000000 --- a/Doc/library/uu.rst +++ /dev/null @@ -1,72 +0,0 @@ -:mod:`uu` --- Encode and decode uuencode files -============================================== - -.. module:: uu - :synopsis: Encode and decode files in uuencode format. - :deprecated: - -.. moduleauthor:: Lance Ellinghouse - -**Source code:** :source:`Lib/uu.py` - -.. deprecated-removed:: 3.11 3.13 - The :mod:`uu` module is deprecated - (see :pep:`PEP 594 <594#uu-and-the-uu-encoding>` for details). - :mod:`base64` is a modern alternative. - --------------- - -This module encodes and decodes files in uuencode format, allowing arbitrary -binary data to be transferred over ASCII-only connections. Wherever a file -argument is expected, the methods accept a file-like object. For backwards -compatibility, a string containing a pathname is also accepted, and the -corresponding file will be opened for reading and writing; the pathname ``'-'`` -is understood to mean the standard input or output. However, this interface is -deprecated; it's better for the caller to open the file itself, and be sure -that, when required, the mode is ``'rb'`` or ``'wb'`` on Windows. - -.. index:: - single: Jansen, Jack - single: Ellinghouse, Lance - -This code was contributed by Lance Ellinghouse, and modified by Jack Jansen. - -The :mod:`uu` module defines the following functions: - - -.. function:: encode(in_file, out_file, name=None, mode=None, *, backtick=False) - - Uuencode file *in_file* into file *out_file*. The uuencoded file will have - the header specifying *name* and *mode* as the defaults for the results of - decoding the file. The default defaults are taken from *in_file*, or ``'-'`` - and ``0o666`` respectively. If *backtick* is true, zeros are represented by - ``'`'`` instead of spaces. - - .. versionchanged:: 3.7 - Added the *backtick* parameter. - - -.. function:: decode(in_file, out_file=None, mode=None, quiet=False) - - This call decodes uuencoded file *in_file* placing the result on file - *out_file*. If *out_file* is a pathname, *mode* is used to set the permission - bits if the file must be created. Defaults for *out_file* and *mode* are taken - from the uuencode header. However, if the file specified in the header already - exists, a :exc:`uu.Error` is raised. - - :func:`decode` may print a warning to standard error if the input was produced - by an incorrect uuencoder and Python could recover from that error. Setting - *quiet* to a true value silences this warning. - - -.. exception:: Error() - - Subclass of :exc:`Exception`, this can be raised by :func:`uu.decode` under - various situations, such as described above, but also including a badly - formatted header, or truncated input file. - - -.. seealso:: - - Module :mod:`binascii` - Support module containing ASCII-to-binary and binary-to-ASCII conversions. diff --git a/Doc/license.rst b/Doc/license.rst index 947a9b1..4b7113b 100644 --- a/Doc/license.rst +++ b/Doc/license.rst @@ -476,7 +476,7 @@ The :mod:`trace` module contains the following notice:: UUencode and UUdecode functions ------------------------------- -The :mod:`uu` module contains the following notice:: +The ``uu`` codec contains the following notice:: Copyright 1994 by Lance Ellinghouse Cathedral City, California Republic, United States of America. diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index efff132..ece273c 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1733,7 +1733,7 @@ Modules +---------------------+---------------------+---------------------+---------------------+---------------------+ | :mod:`aifc` | :mod:`chunk` | :mod:`!msilib` | :mod:`!pipes` | :mod:`!telnetlib` | +---------------------+---------------------+---------------------+---------------------+---------------------+ - | :mod:`audioop` | :mod:`!crypt` | :mod:`!nis` | :mod:`!sndhdr` | :mod:`uu` | + | :mod:`audioop` | :mod:`!crypt` | :mod:`!nis` | :mod:`!sndhdr` | :mod:`!uu` | +---------------------+---------------------+---------------------+---------------------+---------------------+ | :mod:`!cgi` | :mod:`imghdr` | :mod:`!nntplib` | :mod:`!spwd` | :mod:`!xdrlib` | +---------------------+---------------------+---------------------+---------------------+---------------------+ diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index f01cc27..7c18406 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -935,7 +935,7 @@ Modules (see :pep:`594`): * :mod:`!spwd` * :mod:`!sunau` * :mod:`!telnetlib` -* :mod:`uu` +* :mod:`!uu` * :mod:`!xdrlib` APIs: diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index f570e03..38526e1 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -217,6 +217,10 @@ Removed (Contributed by Victor Stinner in :gh:`104773`.) +* :pep:`594`: Remove the :mod:`!uu` module, deprecated in Python 3.11: + the :mod:`base64` module is a modern alternative. + (Contributed by Victor Stinner in :gh:`104773`.) + Porting to Python 3.13 ====================== diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 93915b2..fa89b7d 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -1547,7 +1547,7 @@ adding ``~`` to the set of characters that are never quoted by default. uu -- -The :func:`uu.encode` function now accepts an optional *backtick* +The :func:`!uu.encode` function now accepts an optional *backtick* keyword argument. When it's true, zeros are represented by ``'`'`` instead of spaces. (Contributed by Xiang Zhang in :issue:`30103`.) diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py deleted file mode 100644 index a189d6b..0000000 --- a/Lib/test/test_uu.py +++ /dev/null @@ -1,287 +0,0 @@ -""" -Tests for uu module. -Nick Mathewson -""" - -import unittest -from test.support import os_helper, warnings_helper - -uu = warnings_helper.import_deprecated("uu") - -import os -import stat -import sys -import io - -plaintext = b"The symbols on top of your keyboard are !@#$%^&*()_+|~\n" - -encodedtext = b"""\ -M5&AE('-Y;6)O;',@;VX@=&]P(&]F('EO=7(@:V5Y8F]A 0: - out_file.write(binascii.b2a_uu(data, backtick=backtick)) - data = in_file.read(45) - if backtick: - out_file.write(b'`\nend\n') - else: - out_file.write(b' \nend\n') - finally: - for f in opened_files: - f.close() - - -def decode(in_file, out_file=None, mode=None, quiet=False): - """Decode uuencoded file""" - # - # Open the input file, if needed. - # - opened_files = [] - if in_file == '-': - in_file = sys.stdin.buffer - elif isinstance(in_file, str): - in_file = open(in_file, 'rb') - opened_files.append(in_file) - - try: - # - # Read until a begin is encountered or we've exhausted the file - # - while True: - hdr = in_file.readline() - if not hdr: - raise Error('No valid begin line found in input file') - if not hdr.startswith(b'begin'): - continue - hdrfields = hdr.split(b' ', 2) - if len(hdrfields) == 3 and hdrfields[0] == b'begin': - try: - int(hdrfields[1], 8) - break - except ValueError: - pass - if out_file is None: - # If the filename isn't ASCII, what's up with that?!? - out_file = hdrfields[2].rstrip(b' \t\r\n\f').decode("ascii") - if os.path.exists(out_file): - raise Error(f'Cannot overwrite existing file: {out_file}') - if (out_file.startswith(os.sep) or - f'..{os.sep}' in out_file or ( - os.altsep and - (out_file.startswith(os.altsep) or - f'..{os.altsep}' in out_file)) - ): - raise Error(f'Refusing to write to {out_file} due to directory traversal') - if mode is None: - mode = int(hdrfields[1], 8) - # - # Open the output file - # - if out_file == '-': - out_file = sys.stdout.buffer - elif isinstance(out_file, str): - fp = open(out_file, 'wb') - os.chmod(out_file, mode) - out_file = fp - opened_files.append(out_file) - # - # Main decoding loop - # - s = in_file.readline() - while s and s.strip(b' \t\r\n\f') != b'end': - try: - 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]) - if not quiet: - sys.stderr.write("Warning: %s\n" % v) - out_file.write(data) - s = in_file.readline() - if not s: - raise Error('Truncated input file') - finally: - for f in opened_files: - f.close() - -def test(): - """uuencode/uudecode main program""" - - import optparse - parser = optparse.OptionParser(usage='usage: %prog [-d] [-t] [input [output]]') - parser.add_option('-d', '--decode', dest='decode', help='Decode (instead of encode)?', default=False, action='store_true') - parser.add_option('-t', '--text', dest='text', help='data is text, encoded format unix-compatible text?', default=False, action='store_true') - - (options, args) = parser.parse_args() - if len(args) > 2: - parser.error('incorrect number of arguments') - sys.exit(1) - - # Use the binary streams underlying stdin/stdout - input = sys.stdin.buffer - output = sys.stdout.buffer - if len(args) > 0: - input = args[0] - if len(args) > 1: - output = args[1] - - if options.decode: - if options.text: - if isinstance(output, str): - output = open(output, 'wb') - else: - print(sys.argv[0], ': cannot do -t to stdout') - sys.exit(1) - decode(input, output) - else: - if options.text: - if isinstance(input, str): - input = open(input, 'rb') - else: - print(sys.argv[0], ': cannot do -t from stdin') - sys.exit(1) - encode(input, output) - -if __name__ == '__main__': - test() diff --git a/Misc/NEWS.d/3.12.0b1.rst b/Misc/NEWS.d/3.12.0b1.rst index a1ea082..96d76f8 100644 --- a/Misc/NEWS.d/3.12.0b1.rst +++ b/Misc/NEWS.d/3.12.0b1.rst @@ -4,7 +4,7 @@ .. release date: 2023-05-22 .. section: Security -Fixed a security in flaw in :func:`uu.decode` that could allow for directory +Fixed a security in flaw in :func:`!uu.decode` that could allow for directory traversal based on the input if no ``out_file`` was specified. .. diff --git a/Misc/NEWS.d/next/Library/2023-05-25-15-54-02.gh-issue-104773.nW-5MI.rst b/Misc/NEWS.d/next/Library/2023-05-25-15-54-02.gh-issue-104773.nW-5MI.rst new file mode 100644 index 0000000..522e259 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-05-25-15-54-02.gh-issue-104773.nW-5MI.rst @@ -0,0 +1,2 @@ +:pep:`594`: Remove the :mod:`!uu` module, deprecated in Python 3.11. Patch +by Victor Stinner. diff --git a/Python/stdlib_module_names.h b/Python/stdlib_module_names.h index 00742b3..db574fe 100644 --- a/Python/stdlib_module_names.h +++ b/Python/stdlib_module_names.h @@ -268,7 +268,6 @@ static const char* _Py_stdlib_module_names[] = { "unicodedata", "unittest", "urllib", -"uu", "uuid", "venv", "warnings", diff --git a/Tools/wasm/wasm_assets.py b/Tools/wasm/wasm_assets.py index 5e59ee7..2cf5ac5 100755 --- a/Tools/wasm/wasm_assets.py +++ b/Tools/wasm/wasm_assets.py @@ -41,8 +41,6 @@ OMIT_FILES = ( # package management "ensurepip/", "venv/", - # deprecated - "uu.py", # other platforms "_aix_support.py", "_osx_support.py", -- cgit v0.12