aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/wave.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-02-12 07:53:52 +0300
committershadchin <shadchin@yandex-team.com>2024-02-12 08:07:36 +0300
commitce1b7ca3171f9158180640c6a02a74b4afffedea (patch)
treee47c1e8391b1b0128262c1e9b1e6ed4c8fff2348 /contrib/tools/python3/src/Lib/wave.py
parent57350d96f030db90f220ce50ee591d5c5d403df7 (diff)
downloadydb-ce1b7ca3171f9158180640c6a02a74b4afffedea.tar.gz
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Lib/wave.py')
-rw-r--r--contrib/tools/python3/src/Lib/wave.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/contrib/tools/python3/src/Lib/wave.py b/contrib/tools/python3/src/Lib/wave.py
index bcacbac4e7..4b0c683f6b 100644
--- a/contrib/tools/python3/src/Lib/wave.py
+++ b/contrib/tools/python3/src/Lib/wave.py
@@ -83,6 +83,9 @@ class Error(Exception):
pass
WAVE_FORMAT_PCM = 0x0001
+WAVE_FORMAT_EXTENSIBLE = 0xFFFE
+# Derived from uuid.UUID("00000001-0000-0010-8000-00aa00389b71").bytes_le
+KSDATAFORMAT_SUBTYPE_PCM = b'\x01\x00\x00\x00\x00\x00\x10\x00\x80\x00\x00\xaa\x008\x9bq'
_array_fmts = None, 'b', 'h', None, 'i'
@@ -376,16 +379,31 @@ class Wave_read:
wFormatTag, self._nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack_from('<HHLLH', chunk.read(14))
except struct.error:
raise EOFError from None
- if wFormatTag == WAVE_FORMAT_PCM:
+ if wFormatTag != WAVE_FORMAT_PCM and wFormatTag != WAVE_FORMAT_EXTENSIBLE:
+ raise Error('unknown format: %r' % (wFormatTag,))
+ try:
+ sampwidth = struct.unpack_from('<H', chunk.read(2))[0]
+ except struct.error:
+ raise EOFError from None
+ if wFormatTag == WAVE_FORMAT_EXTENSIBLE:
try:
- sampwidth = struct.unpack_from('<H', chunk.read(2))[0]
+ cbSize, wValidBitsPerSample, dwChannelMask = struct.unpack_from('<HHL', chunk.read(8))
+ # Read the entire UUID from the chunk
+ SubFormat = chunk.read(16)
+ if len(SubFormat) < 16:
+ raise EOFError
except struct.error:
raise EOFError from None
- self._sampwidth = (sampwidth + 7) // 8
- if not self._sampwidth:
- raise Error('bad sample width')
- else:
- raise Error('unknown format: %r' % (wFormatTag,))
+ if SubFormat != KSDATAFORMAT_SUBTYPE_PCM:
+ try:
+ import uuid
+ subformat_msg = f'unknown extended format: {uuid.UUID(bytes_le=SubFormat)}'
+ except Exception:
+ subformat_msg = 'unknown extended format'
+ raise Error(subformat_msg)
+ self._sampwidth = (sampwidth + 7) // 8
+ if not self._sampwidth:
+ raise Error('bad sample width')
if not self._nchannels:
raise Error('bad # of channels')
self._framesize = self._nchannels * self._sampwidth