aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/future
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2025-07-21 12:37:15 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2025-07-21 12:54:58 +0300
commitcaefbb016b70b186bad0fa7f07a1524b3211fec4 (patch)
treecc7f0d3f511d8d66cfe794fc3550bbe187901014 /contrib/python/future
parentce2bac1786d54724a15f7211d5f1bf29d15af171 (diff)
downloadydb-caefbb016b70b186bad0fa7f07a1524b3211fec4.tar.gz
Intermediate changes
commit_hash:0897b988c8ca7235b4f13624177866ac14a46fdd
Diffstat (limited to 'contrib/python/future')
-rw-r--r--contrib/python/future/py3/future/backports/email/message.py41
-rw-r--r--contrib/python/future/py3/future/backports/email/mime/audio.py80
-rw-r--r--contrib/python/future/py3/future/backports/email/mime/image.py113
-rw-r--r--contrib/python/future/py3/patches/07-support-python-3.13.patch65
-rw-r--r--contrib/python/future/py3/patches/08-support-python-3.13.patch103
-rw-r--r--contrib/python/future/py3/patches/09-support-python-3.13.patch131
6 files changed, 496 insertions, 37 deletions
diff --git a/contrib/python/future/py3/future/backports/email/message.py b/contrib/python/future/py3/future/backports/email/message.py
index d8d9615d7d7..8b4a974944b 100644
--- a/contrib/python/future/py3/future/backports/email/message.py
+++ b/contrib/python/future/py3/future/backports/email/message.py
@@ -10,7 +10,6 @@ from future.builtins import list, range, str, zip
__all__ = ['Message']
import re
-import uu
import base64
import binascii
from io import BytesIO, StringIO
@@ -106,6 +105,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(object):
"""Basic message object.
@@ -262,13 +292,10 @@ class Message(object):
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
diff --git a/contrib/python/future/py3/future/backports/email/mime/audio.py b/contrib/python/future/py3/future/backports/email/mime/audio.py
index 4989c114207..0cd703fdc31 100644
--- a/contrib/python/future/py3/future/backports/email/mime/audio.py
+++ b/contrib/python/future/py3/future/backports/email/mime/audio.py
@@ -9,37 +9,11 @@ from __future__ import absolute_import
__all__ = ['MIMEAudio']
-import sndhdr
-
from io import BytesIO
from future.backports.email import encoders
from future.backports.email.mime.nonmultipart import MIMENonMultipart
-_sndhdr_MIMEmap = {'au' : 'basic',
- 'wav' :'x-wav',
- 'aiff':'x-aiff',
- 'aifc':'x-aiff',
- }
-
-# There are others in sndhdr that don't have MIME types. :(
-# Additional ones to be added to sndhdr? midi, mp3, realaudio, wma??
-def _whatsnd(data):
- """Try to identify a sound file type.
-
- sndhdr.what() has a pretty cruddy interface, unfortunately. This is why
- we re-do it here. It would be easier to reverse engineer the Unix 'file'
- command and use the standard 'magic' file, as shipped with a modern Unix.
- """
- hdr = data[:512]
- fakefile = BytesIO(hdr)
- for testfn in sndhdr.tests:
- res = testfn(hdr, fakefile)
- if res is not None:
- return _sndhdr_MIMEmap.get(res[0])
- return None
-
-
class MIMEAudio(MIMENonMultipart):
"""Class for generating audio/* MIME documents."""
@@ -66,9 +40,61 @@ class MIMEAudio(MIMENonMultipart):
header.
"""
if _subtype is None:
- _subtype = _whatsnd(_audiodata)
+ _subtype = _what(_audiodata)
if _subtype is None:
raise TypeError('Could not find audio MIME subtype')
MIMENonMultipart.__init__(self, 'audio', _subtype, **_params)
self.set_payload(_audiodata)
_encoder(self)
+
+
+_rules = []
+
+
+# Originally from the sndhdr module.
+#
+# There are others in sndhdr that don't have MIME types. :(
+# Additional ones to be added to sndhdr? midi, mp3, realaudio, wma??
+def _what(data):
+ # Try to identify a sound file type.
+ #
+ # sndhdr.what() had a pretty cruddy interface, unfortunately. This is why
+ # we re-do it here. It would be easier to reverse engineer the Unix 'file'
+ # command and use the standard 'magic' file, as shipped with a modern Unix.
+ for testfn in _rules:
+ if res := testfn(data):
+ return res
+ else:
+ return None
+
+
+def rule(rulefunc):
+ _rules.append(rulefunc)
+ return rulefunc
+
+
+@rule
+def _aiff(h):
+ if not h.startswith(b'FORM'):
+ return None
+ if h[8:12] in {b'AIFC', b'AIFF'}:
+ return 'x-aiff'
+ else:
+ return None
+
+
+@rule
+def _au(h):
+ if h.startswith(b'.snd'):
+ return 'basic'
+ else:
+ return None
+
+
+@rule
+def _wav(h):
+ # 'RIFF' <len> 'WAVE' 'fmt ' <len>
+ if not h.startswith(b'RIFF') or h[8:12] != b'WAVE' or h[12:16] != b'fmt ':
+ return None
+ else:
+ return "x-wav"
diff --git a/contrib/python/future/py3/future/backports/email/mime/image.py b/contrib/python/future/py3/future/backports/email/mime/image.py
index a03602464aa..b8fa87930f0 100644
--- a/contrib/python/future/py3/future/backports/email/mime/image.py
+++ b/contrib/python/future/py3/future/backports/email/mime/image.py
@@ -9,8 +9,6 @@ from __future__ import absolute_import
__all__ = ['MIMEImage']
-import imghdr
-
from future.backports.email import encoders
from future.backports.email.mime.nonmultipart import MIMENonMultipart
@@ -40,9 +38,118 @@ class MIMEImage(MIMENonMultipart):
header.
"""
if _subtype is None:
- _subtype = imghdr.what(None, _imagedata)
+ _subtype = _what(_imagedata)
if _subtype is None:
raise TypeError('Could not guess image MIME subtype')
MIMENonMultipart.__init__(self, 'image', _subtype, **_params)
self.set_payload(_imagedata)
_encoder(self)
+
+
+_rules = []
+
+
+# Originally from the imghdr module.
+def _what(data):
+ for rule in _rules:
+ if res := rule(data):
+ return res
+ else:
+ return None
+
+
+def rule(rulefunc):
+ _rules.append(rulefunc)
+ return rulefunc
+
+
+@rule
+def _jpeg(h):
+ """JPEG data with JFIF or Exif markers; and raw JPEG"""
+ if h[6:10] in (b'JFIF', b'Exif'):
+ return 'jpeg'
+ elif h[:4] == b'\xff\xd8\xff\xdb':
+ return 'jpeg'
+
+
+@rule
+def _png(h):
+ if h.startswith(b'\211PNG\r\n\032\n'):
+ return 'png'
+
+
+@rule
+def _gif(h):
+ """GIF ('87 and '89 variants)"""
+ if h[:6] in (b'GIF87a', b'GIF89a'):
+ return 'gif'
+
+
+@rule
+def _tiff(h):
+ """TIFF (can be in Motorola or Intel byte order)"""
+ if h[:2] in (b'MM', b'II'):
+ return 'tiff'
+
+
+@rule
+def _rgb(h):
+ """SGI image library"""
+ if h.startswith(b'\001\332'):
+ return 'rgb'
+
+
+@rule
+def _pbm(h):
+ """PBM (portable bitmap)"""
+ if len(h) >= 3 and \
+ h[0] == ord(b'P') and h[1] in b'14' and h[2] in b' \t\n\r':
+ return 'pbm'
+
+
+@rule
+def _pgm(h):
+ """PGM (portable graymap)"""
+ if len(h) >= 3 and \
+ h[0] == ord(b'P') and h[1] in b'25' and h[2] in b' \t\n\r':
+ return 'pgm'
+
+
+@rule
+def _ppm(h):
+ """PPM (portable pixmap)"""
+ if len(h) >= 3 and \
+ h[0] == ord(b'P') and h[1] in b'36' and h[2] in b' \t\n\r':
+ return 'ppm'
+
+
+@rule
+def _rast(h):
+ """Sun raster file"""
+ if h.startswith(b'\x59\xA6\x6A\x95'):
+ return 'rast'
+
+
+@rule
+def _xbm(h):
+ """X bitmap (X10 or X11)"""
+ if h.startswith(b'#define '):
+ return 'xbm'
+
+
+@rule
+def _bmp(h):
+ if h.startswith(b'BM'):
+ return 'bmp'
+
+
+@rule
+def _webp(h):
+ if h.startswith(b'RIFF') and h[8:12] == b'WEBP':
+ return 'webp'
+
+
+@rule
+def _exr(h):
+ if h.startswith(b'\x76\x2f\x31\x01'):
+ return 'exr'
diff --git a/contrib/python/future/py3/patches/07-support-python-3.13.patch b/contrib/python/future/py3/patches/07-support-python-3.13.patch
new file mode 100644
index 00000000000..c0e15bbbc33
--- /dev/null
+++ b/contrib/python/future/py3/patches/07-support-python-3.13.patch
@@ -0,0 +1,65 @@
+--- contrib/python/future/py3/future/backports/email/message.py (index)
++++ contrib/python/future/py3/future/backports/email/message.py (working tree)
+@@ -10,7 +10,6 @@ from future.builtins import list, range, str, zip
+ __all__ = ['Message']
+
+ import re
+-import uu
+ import base64
+ import binascii
+ from io import BytesIO, StringIO
+@@ -106,6 +105,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(object):
+ """Basic message object.
+
+@@ -262,13 +292,10 @@ class Message(object):
+ 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
diff --git a/contrib/python/future/py3/patches/08-support-python-3.13.patch b/contrib/python/future/py3/patches/08-support-python-3.13.patch
new file mode 100644
index 00000000000..9b726f25e98
--- /dev/null
+++ b/contrib/python/future/py3/patches/08-support-python-3.13.patch
@@ -0,0 +1,103 @@
+--- contrib/python/future/py3/future/backports/email/mime/audio.py (index)
++++ contrib/python/future/py3/future/backports/email/mime/audio.py (working tree)
+@@ -9,37 +9,11 @@ from __future__ import absolute_import
+
+ __all__ = ['MIMEAudio']
+
+-import sndhdr
+-
+ from io import BytesIO
+ from future.backports.email import encoders
+ from future.backports.email.mime.nonmultipart import MIMENonMultipart
+
+
+-_sndhdr_MIMEmap = {'au' : 'basic',
+- 'wav' :'x-wav',
+- 'aiff':'x-aiff',
+- 'aifc':'x-aiff',
+- }
+-
+-# There are others in sndhdr that don't have MIME types. :(
+-# Additional ones to be added to sndhdr? midi, mp3, realaudio, wma??
+-def _whatsnd(data):
+- """Try to identify a sound file type.
+-
+- sndhdr.what() has a pretty cruddy interface, unfortunately. This is why
+- we re-do it here. It would be easier to reverse engineer the Unix 'file'
+- command and use the standard 'magic' file, as shipped with a modern Unix.
+- """
+- hdr = data[:512]
+- fakefile = BytesIO(hdr)
+- for testfn in sndhdr.tests:
+- res = testfn(hdr, fakefile)
+- if res is not None:
+- return _sndhdr_MIMEmap.get(res[0])
+- return None
+-
+-
+ class MIMEAudio(MIMENonMultipart):
+ """Class for generating audio/* MIME documents."""
+
+@@ -66,9 +40,61 @@ class MIMEAudio(MIMENonMultipart):
+ header.
+ """
+ if _subtype is None:
+- _subtype = _whatsnd(_audiodata)
++ _subtype = _what(_audiodata)
+ if _subtype is None:
+ raise TypeError('Could not find audio MIME subtype')
+ MIMENonMultipart.__init__(self, 'audio', _subtype, **_params)
+ self.set_payload(_audiodata)
+ _encoder(self)
++
++
++_rules = []
++
++
++# Originally from the sndhdr module.
++#
++# There are others in sndhdr that don't have MIME types. :(
++# Additional ones to be added to sndhdr? midi, mp3, realaudio, wma??
++def _what(data):
++ # Try to identify a sound file type.
++ #
++ # sndhdr.what() had a pretty cruddy interface, unfortunately. This is why
++ # we re-do it here. It would be easier to reverse engineer the Unix 'file'
++ # command and use the standard 'magic' file, as shipped with a modern Unix.
++ for testfn in _rules:
++ if res := testfn(data):
++ return res
++ else:
++ return None
++
++
++def rule(rulefunc):
++ _rules.append(rulefunc)
++ return rulefunc
++
++
++@rule
++def _aiff(h):
++ if not h.startswith(b'FORM'):
++ return None
++ if h[8:12] in {b'AIFC', b'AIFF'}:
++ return 'x-aiff'
++ else:
++ return None
++
++
++@rule
++def _au(h):
++ if h.startswith(b'.snd'):
++ return 'basic'
++ else:
++ return None
++
++
++@rule
++def _wav(h):
++ # 'RIFF' <len> 'WAVE' 'fmt ' <len>
++ if not h.startswith(b'RIFF') or h[8:12] != b'WAVE' or h[12:16] != b'fmt ':
++ return None
++ else:
++ return "x-wav"
diff --git a/contrib/python/future/py3/patches/09-support-python-3.13.patch b/contrib/python/future/py3/patches/09-support-python-3.13.patch
new file mode 100644
index 00000000000..ebcd7356378
--- /dev/null
+++ b/contrib/python/future/py3/patches/09-support-python-3.13.patch
@@ -0,0 +1,131 @@
+--- contrib/python/future/py3/future/backports/email/mime/image.py (index)
++++ contrib/python/future/py3/future/backports/email/mime/image.py (working tree)
+@@ -9,8 +9,6 @@ from __future__ import absolute_import
+
+ __all__ = ['MIMEImage']
+
+-import imghdr
+-
+ from future.backports.email import encoders
+ from future.backports.email.mime.nonmultipart import MIMENonMultipart
+
+@@ -40,9 +38,118 @@ class MIMEImage(MIMENonMultipart):
+ header.
+ """
+ if _subtype is None:
+- _subtype = imghdr.what(None, _imagedata)
++ _subtype = _what(_imagedata)
+ if _subtype is None:
+ raise TypeError('Could not guess image MIME subtype')
+ MIMENonMultipart.__init__(self, 'image', _subtype, **_params)
+ self.set_payload(_imagedata)
+ _encoder(self)
++
++
++_rules = []
++
++
++# Originally from the imghdr module.
++def _what(data):
++ for rule in _rules:
++ if res := rule(data):
++ return res
++ else:
++ return None
++
++
++def rule(rulefunc):
++ _rules.append(rulefunc)
++ return rulefunc
++
++
++@rule
++def _jpeg(h):
++ """JPEG data with JFIF or Exif markers; and raw JPEG"""
++ if h[6:10] in (b'JFIF', b'Exif'):
++ return 'jpeg'
++ elif h[:4] == b'\xff\xd8\xff\xdb':
++ return 'jpeg'
++
++
++@rule
++def _png(h):
++ if h.startswith(b'\211PNG\r\n\032\n'):
++ return 'png'
++
++
++@rule
++def _gif(h):
++ """GIF ('87 and '89 variants)"""
++ if h[:6] in (b'GIF87a', b'GIF89a'):
++ return 'gif'
++
++
++@rule
++def _tiff(h):
++ """TIFF (can be in Motorola or Intel byte order)"""
++ if h[:2] in (b'MM', b'II'):
++ return 'tiff'
++
++
++@rule
++def _rgb(h):
++ """SGI image library"""
++ if h.startswith(b'\001\332'):
++ return 'rgb'
++
++
++@rule
++def _pbm(h):
++ """PBM (portable bitmap)"""
++ if len(h) >= 3 and \
++ h[0] == ord(b'P') and h[1] in b'14' and h[2] in b' \t\n\r':
++ return 'pbm'
++
++
++@rule
++def _pgm(h):
++ """PGM (portable graymap)"""
++ if len(h) >= 3 and \
++ h[0] == ord(b'P') and h[1] in b'25' and h[2] in b' \t\n\r':
++ return 'pgm'
++
++
++@rule
++def _ppm(h):
++ """PPM (portable pixmap)"""
++ if len(h) >= 3 and \
++ h[0] == ord(b'P') and h[1] in b'36' and h[2] in b' \t\n\r':
++ return 'ppm'
++
++
++@rule
++def _rast(h):
++ """Sun raster file"""
++ if h.startswith(b'\x59\xA6\x6A\x95'):
++ return 'rast'
++
++
++@rule
++def _xbm(h):
++ """X bitmap (X10 or X11)"""
++ if h.startswith(b'#define '):
++ return 'xbm'
++
++
++@rule
++def _bmp(h):
++ if h.startswith(b'BM'):
++ return 'bmp'
++
++
++@rule
++def _webp(h):
++ if h.startswith(b'RIFF') and h[8:12] == b'WEBP':
++ return 'webp'
++
++
++@rule
++def _exr(h):
++ if h.startswith(b'\x76\x2f\x31\x01'):
++ return 'exr'