mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
gh-91217: deprecate uu (GH-92009)
Automerge-Triggered-By: GH:brettcannon
This commit is contained in:
parent
f348154c8f
commit
407c3afe19
5 changed files with 44 additions and 11 deletions
|
@ -1071,6 +1071,7 @@ Deprecated
|
||||||
* :mod:`spwd`
|
* :mod:`spwd`
|
||||||
* :mod:`sunau`
|
* :mod:`sunau`
|
||||||
* :mod:`telnetlib`
|
* :mod:`telnetlib`
|
||||||
|
* :mod:`uu`
|
||||||
|
|
||||||
(Contributed by Brett Cannon in :issue:`47061` and Victor Stinner in
|
(Contributed by Brett Cannon in :issue:`47061` and Victor Stinner in
|
||||||
:gh:`68966`.)
|
:gh:`68966`.)
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
__all__ = ['Message', 'EmailMessage']
|
__all__ = ['Message', 'EmailMessage']
|
||||||
|
|
||||||
|
import binascii
|
||||||
import re
|
import re
|
||||||
import uu
|
|
||||||
import quopri
|
import quopri
|
||||||
from io import BytesIO, StringIO
|
from io import BytesIO, StringIO
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ def _splitparam(param):
|
||||||
if not sep:
|
if not sep:
|
||||||
return a.strip(), None
|
return a.strip(), None
|
||||||
return a.strip(), b.strip()
|
return a.strip(), b.strip()
|
||||||
|
|
||||||
def _formatparam(param, value=None, quote=True):
|
def _formatparam(param, value=None, quote=True):
|
||||||
"""Convenience function to format and return a key=value pair.
|
"""Convenience function to format and return a key=value pair.
|
||||||
|
|
||||||
|
@ -101,7 +101,37 @@ def _unquotevalue(value):
|
||||||
return utils.unquote(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:
|
class Message:
|
||||||
"""Basic message object.
|
"""Basic message object.
|
||||||
|
|
||||||
|
@ -288,13 +318,10 @@ class Message:
|
||||||
self.policy.handle_defect(self, defect)
|
self.policy.handle_defect(self, defect)
|
||||||
return value
|
return value
|
||||||
elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
|
elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
|
||||||
in_file = BytesIO(bpayload)
|
|
||||||
out_file = BytesIO()
|
|
||||||
try:
|
try:
|
||||||
uu.decode(in_file, out_file, quiet=True)
|
return _decode_uu(bpayload)
|
||||||
return out_file.getvalue()
|
except ValueError:
|
||||||
except uu.Error:
|
# Some decoding problem.
|
||||||
# Some decoding problem
|
|
||||||
return bpayload
|
return bpayload
|
||||||
if isinstance(payload, str):
|
if isinstance(payload, str):
|
||||||
return bpayload
|
return bpayload
|
||||||
|
|
|
@ -4,12 +4,13 @@ Nick Mathewson
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import unittest
|
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 os
|
||||||
import stat
|
import stat
|
||||||
import sys
|
import sys
|
||||||
import uu
|
|
||||||
import io
|
import io
|
||||||
|
|
||||||
plaintext = b"The symbols on top of your keyboard are !@#$%^&*()_+|~\n"
|
plaintext = b"The symbols on top of your keyboard are !@#$%^&*()_+|~\n"
|
||||||
|
|
|
@ -33,6 +33,9 @@ decode(in_file [, out_file, mode, quiet])
|
||||||
import binascii
|
import binascii
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
warnings._deprecated(__name__, remove=(3, 13))
|
||||||
|
|
||||||
__all__ = ["Error", "encode", "decode"]
|
__all__ = ["Error", "encode", "decode"]
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Deprecate the uu module.
|
Loading…
Add table
Add a link
Reference in a new issue