Skip to content

Commit 407c3af

Browse files
authored
gh-91217: deprecate uu (GH-92009)
Automerge-Triggered-By: GH:brettcannon
1 parent f348154 commit 407c3af

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

Doc/whatsnew/3.11.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,7 @@ Deprecated
10711071
* :mod:`spwd`
10721072
* :mod:`sunau`
10731073
* :mod:`telnetlib`
1074+
* :mod:`uu`
10741075

10751076
(Contributed by Brett Cannon in :issue:`47061` and Victor Stinner in
10761077
:gh:`68966`.)

Lib/email/message.py

+36-9
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
__all__ = ['Message', 'EmailMessage']
88

9+
import binascii
910
import re
10-
import uu
1111
import quopri
1212
from io import BytesIO, StringIO
1313

@@ -35,7 +35,7 @@ def _splitparam(param):
3535
if not sep:
3636
return a.strip(), None
3737
return a.strip(), b.strip()
38-
38+
3939
def _formatparam(param, value=None, quote=True):
4040
"""Convenience function to format and return a key=value pair.
4141
@@ -101,7 +101,37 @@ def _unquotevalue(value):
101101
return utils.unquote(value)
102102

103103

104-
104+
def _decode_uu(encoded):
105+
"""Decode uuencoded data."""
106+
decoded_lines = []
107+
encoded_lines_iter = iter(encoded.splitlines())
108+
for line in encoded_lines_iter:
109+
if line.startswith(b"begin "):
110+
mode, _, path = line.removeprefix(b"begin ").partition(b" ")
111+
try:
112+
int(mode, base=8)
113+
except ValueError:
114+
continue
115+
else:
116+
break
117+
else:
118+
raise ValueError("`begin` line not found")
119+
for line in encoded_lines_iter:
120+
if not line:
121+
raise ValueError("Truncated input")
122+
elif line.strip(b' \t\r\n\f') == b'end':
123+
break
124+
try:
125+
decoded_line = binascii.a2b_uu(line)
126+
except binascii.Error:
127+
# Workaround for broken uuencoders by /Fredrik Lundh
128+
nbytes = (((line[0]-32) & 63) * 4 + 5) // 3
129+
decoded_line = binascii.a2b_uu(line[:nbytes])
130+
decoded_lines.append(decoded_line)
131+
132+
return b''.join(decoded_lines)
133+
134+
105135
class Message:
106136
"""Basic message object.
107137
@@ -288,13 +318,10 @@ def get_payload(self, i=None, decode=False):
288318
self.policy.handle_defect(self, defect)
289319
return value
290320
elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
291-
in_file = BytesIO(bpayload)
292-
out_file = BytesIO()
293321
try:
294-
uu.decode(in_file, out_file, quiet=True)
295-
return out_file.getvalue()
296-
except uu.Error:
297-
# Some decoding problem
322+
return _decode_uu(bpayload)
323+
except ValueError:
324+
# Some decoding problem.
298325
return bpayload
299326
if isinstance(payload, str):
300327
return bpayload

Lib/test/test_uu.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
"""
55

66
import unittest
7-
from test.support import os_helper
7+
from test.support import os_helper, warnings_helper
8+
9+
uu = warnings_helper.import_deprecated("uu")
810

911
import os
1012
import stat
1113
import sys
12-
import uu
1314
import io
1415

1516
plaintext = b"The symbols on top of your keyboard are !@#$%^&*()_+|~\n"

Lib/uu.py

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import binascii
3434
import os
3535
import sys
36+
import warnings
37+
38+
warnings._deprecated(__name__, remove=(3, 13))
3639

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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate the uu module.

0 commit comments

Comments
 (0)