Skip to content

gh-91217: deprecate uu #92009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ Deprecated
* :mod:`spwd`
* :mod:`sunau`
* :mod:`telnetlib`
* :mod:`uu`

(Contributed by Brett Cannon in :issue:`47061` and Victor Stinner in
:gh:`68966`.)
Expand Down
45 changes: 36 additions & 9 deletions Lib/email/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

__all__ = ['Message', 'EmailMessage']

import binascii
import re
import uu
import quopri
from io import BytesIO, StringIO

Expand Down Expand Up @@ -35,7 +35,7 @@ def _splitparam(param):
if not sep:
return a.strip(), None
return a.strip(), b.strip()

def _formatparam(param, value=None, quote=True):
"""Convenience function to format and return a key=value pair.

Expand Down Expand Up @@ -101,7 +101,37 @@ def _unquotevalue(value):
return utils.unquote(value)



def _decode_uu(encoded):
"""Decode uuencoded data."""
decoded_lines = []
encoded_lines_iter = iter(encoded.splitlines())
for line in encoded_lines_iter:
if line.startswith(b"begin "):
mode, _, path = line.removeprefix(b"begin ").partition(b" ")
try:
int(mode, base=8)
except ValueError:
continue
else:
break
else:
raise ValueError("`begin` line not found")
for line in encoded_lines_iter:
if not line:
raise ValueError("Truncated input")
elif line.strip(b' \t\r\n\f') == b'end':
break
try:
decoded_line = binascii.a2b_uu(line)
except binascii.Error:
# Workaround for broken uuencoders by /Fredrik Lundh
nbytes = (((line[0]-32) & 63) * 4 + 5) // 3
decoded_line = binascii.a2b_uu(line[:nbytes])
decoded_lines.append(decoded_line)

return b''.join(decoded_lines)


class Message:
"""Basic message object.

Expand Down Expand Up @@ -288,13 +318,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'):
in_file = BytesIO(bpayload)
out_file = BytesIO()
try:
uu.decode(in_file, out_file, quiet=True)
return out_file.getvalue()
except uu.Error:
# Some decoding problem
return _decode_uu(bpayload)
except ValueError:
# Some decoding problem.
return bpayload
if isinstance(payload, str):
return bpayload
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_uu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"""

import unittest
from test.support import os_helper
from test.support import os_helper, warnings_helper

uu = warnings_helper.import_deprecated("uu")

import os
import stat
import sys
import uu
import io

plaintext = b"The symbols on top of your keyboard are !@#$%^&*()_+|~\n"
Expand Down
3 changes: 3 additions & 0 deletions Lib/uu.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import binascii
import os
import sys
import warnings

warnings._deprecated(__name__, remove=(3, 13))

__all__ = ["Error", "encode", "decode"]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate the uu module.