summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2022-04-07 19:27:35 (GMT)
committerGitHub <noreply@github.com>2022-04-07 19:27:35 (GMT)
commit87eec70d97b250f820325b4f1b4f781b443b5180 (patch)
treef8e20384e332b2c5743c134d87a82070cee87ff7
parent1df4298b62fcc124ba9de861f8dc8239ad72cde2 (diff)
downloadcpython-87eec70d97b250f820325b4f1b4f781b443b5180.zip
cpython-87eec70d97b250f820325b4f1b4f781b443b5180.tar.gz
cpython-87eec70d97b250f820325b4f1b4f781b443b5180.tar.bz2
Deprecate audioop (GH-32392)
-rw-r--r--Doc/whatsnew/3.11.rst1
-rw-r--r--Lib/aifc.py32
-rw-r--r--Lib/sunau.py9
-rw-r--r--Lib/test/test_aifc.py6
-rw-r--r--Lib/test/test_audioop.py5
-rw-r--r--Lib/test/test_ossaudiodev.py4
-rw-r--r--Lib/test/test_pyclbr.py1
-rw-r--r--Lib/test/test_sunau.py6
-rw-r--r--Lib/test/test_wave.py7
-rw-r--r--Lib/wave.py15
-rw-r--r--Misc/NEWS.d/next/Library/2022-04-06-18-01-28.bpo-47061.qoVTR9.rst1
-rw-r--r--Modules/audioop.c7
12 files changed, 68 insertions, 26 deletions
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index 31cdf10..bc4a195 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -833,6 +833,7 @@ Deprecated
slated for removal in Python 3.13:
* :mod:`aifc`
+ * :mod:`audioop`
(Contributed by Brett Cannon in :issue:`47061`.)
diff --git a/Lib/aifc.py b/Lib/aifc.py
index b5eab92..314cfd2 100644
--- a/Lib/aifc.py
+++ b/Lib/aifc.py
@@ -451,15 +451,21 @@ class Aifc_read:
#
def _alaw2lin(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
return audioop.alaw2lin(data, 2)
def _ulaw2lin(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
return audioop.ulaw2lin(data, 2)
def _adpcm2lin(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
if not hasattr(self, '_adpcmstate'):
# first time
self._adpcmstate = None
@@ -467,7 +473,9 @@ class Aifc_read:
return data
def _sowt2lin(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
return audioop.byteswap(data, 2)
def _read_comm_chunk(self, chunk):
@@ -774,22 +782,30 @@ class Aifc_write:
#
def _lin2alaw(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
return audioop.lin2alaw(data, 2)
def _lin2ulaw(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
return audioop.lin2ulaw(data, 2)
def _lin2adpcm(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
if not hasattr(self, '_adpcmstate'):
self._adpcmstate = None
data, self._adpcmstate = audioop.lin2adpcm(data, 2, self._adpcmstate)
return data
def _lin2sowt(self, data):
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
return audioop.byteswap(data, 2)
def _ensure_header_written(self, datasize):
diff --git a/Lib/sunau.py b/Lib/sunau.py
index 79750a9..9b3533d 100644
--- a/Lib/sunau.py
+++ b/Lib/sunau.py
@@ -104,6 +104,7 @@ is destroyed.
"""
from collections import namedtuple
+import warnings
_sunau_params = namedtuple('_sunau_params',
@@ -275,7 +276,9 @@ class Au_read:
data = self._file.read(nframes * self._framesize)
self._soundpos += len(data) // self._framesize
if self._encoding == AUDIO_FILE_ENCODING_MULAW_8:
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
data = audioop.ulaw2lin(data, self._sampwidth)
return data
return None # XXX--not implemented yet
@@ -421,7 +424,9 @@ class Au_write:
data = memoryview(data).cast('B')
self._ensure_header_written()
if self._comptype == 'ULAW':
- import audioop
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ import audioop
data = audioop.lin2ulaw(data, self._sampwidth)
nframes = len(data) // self._framesize
self._file.write(data)
diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py
index ad8a7ee..d3863d4 100644
--- a/Lib/test/test_aifc.py
+++ b/Lib/test/test_aifc.py
@@ -4,13 +4,13 @@ from test.support.warnings_helper import check_no_resource_warning, import_depre
import unittest
from unittest import mock
from test import audiotests
-from audioop import byteswap
import io
import sys
import struct
aifc = import_deprecated("aifc")
+audioop = import_deprecated("audioop")
class AifcTest(audiotests.AudioWriteTests,
@@ -124,7 +124,7 @@ class AifcULAWTest(AifcTest, unittest.TestCase):
E5040CBC 617C0A3C 08BC0A3C 2C7C0B3C 517C0E3C 8A8410FC B6840EBC 457C0A3C \
""")
if sys.byteorder != 'big':
- frames = byteswap(frames, 2)
+ frames = audioop.byteswap(frames, 2)
class AifcALAWTest(AifcTest, unittest.TestCase):
@@ -145,7 +145,7 @@ class AifcALAWTest(AifcTest, unittest.TestCase):
E4800CC0 62000A40 08C00A40 2B000B40 52000E40 8A001180 B6000EC0 46000A40 \
""")
if sys.byteorder != 'big':
- frames = byteswap(frames, 2)
+ frames = audioop.byteswap(frames, 2)
class AifcMiscTest(unittest.TestCase):
diff --git a/Lib/test/test_audioop.py b/Lib/test/test_audioop.py
index 9baa62a..05c0f20 100644
--- a/Lib/test/test_audioop.py
+++ b/Lib/test/test_audioop.py
@@ -1,7 +1,10 @@
-import audioop
import sys
+from test.support import warnings_helper
import unittest
+audioop = warnings_helper.import_deprecated("audioop")
+
+
def pack(width, data):
return b''.join(v.to_bytes(width, sys.byteorder, signed=True) for v in data)
diff --git a/Lib/test/test_ossaudiodev.py b/Lib/test/test_ossaudiodev.py
index ebce3e9..37d2d1f 100644
--- a/Lib/test/test_ossaudiodev.py
+++ b/Lib/test/test_ossaudiodev.py
@@ -1,16 +1,16 @@
from test import support
-from test.support import import_helper
+from test.support import import_helper, warnings_helper
support.requires('audio')
from test.support import findfile
ossaudiodev = import_helper.import_module('ossaudiodev')
+audioop = warnings_helper.import_deprecated('audioop')
import errno
import sys
import sunau
import time
-import audioop
import unittest
# Arggh, AFMT_S16_NE not defined on all platforms -- seems to be a
diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py
index 329acf0..ad7b31a 100644
--- a/Lib/test/test_pyclbr.py
+++ b/Lib/test/test_pyclbr.py
@@ -217,7 +217,6 @@ class PyclbrTest(TestCase):
cm = self.checkModule
# These were once some of the longest modules.
- cm('aifc', ignore=('_aifc_params',)) # set with = in module
cm('random', ignore=('Random',)) # from _random import Random as CoreGenerator
cm('cgi', ignore=('log',)) # set with = in module
cm('pickle', ignore=('partial', 'PickleBuffer'))
diff --git a/Lib/test/test_sunau.py b/Lib/test/test_sunau.py
index 7f1c0a5..e65742b 100644
--- a/Lib/test/test_sunau.py
+++ b/Lib/test/test_sunau.py
@@ -1,10 +1,12 @@
import unittest
from test import audiotests
-from audioop import byteswap
import io
import struct
import sys
import sunau
+from test.support import warnings_helper
+
+audioop = warnings_helper.import_deprecated("audioop")
class SunauTest(audiotests.AudioWriteTests,
@@ -116,7 +118,7 @@ class SunauULAWTest(SunauTest, unittest.TestCase):
E5040CBC 617C0A3C 08BC0A3C 2C7C0B3C 517C0E3C 8A8410FC B6840EBC 457C0A3C \
""")
if sys.byteorder != 'big':
- frames = byteswap(frames, 2)
+ frames = audioop.byteswap(frames, 2)
class SunauLowLevelTest(unittest.TestCase):
diff --git a/Lib/test/test_wave.py b/Lib/test/test_wave.py
index f85e40b..0cc94e8 100644
--- a/Lib/test/test_wave.py
+++ b/Lib/test/test_wave.py
@@ -1,7 +1,6 @@
import unittest
from test import audiotests
from test import support
-from audioop import byteswap
import io
import struct
import sys
@@ -48,7 +47,7 @@ class WavePCM16Test(WaveTest, unittest.TestCase):
E4B50CEB 63440A5A 08CA0A1F 2BBA0B0B 51460E47 8BCB113C B6F50EEA 44150A59 \
""")
if sys.byteorder != 'big':
- frames = byteswap(frames, 2)
+ frames = wave._byteswap(frames, 2)
class WavePCM24Test(WaveTest, unittest.TestCase):
@@ -75,7 +74,7 @@ class WavePCM24Test(WaveTest, unittest.TestCase):
51486F0E44E1 8BCC64113B05 B6F4EC0EEB36 4413170A5B48 \
""")
if sys.byteorder != 'big':
- frames = byteswap(frames, 3)
+ frames = wave._byteswap(frames, 3)
class WavePCM32Test(WaveTest, unittest.TestCase):
@@ -102,7 +101,7 @@ class WavePCM32Test(WaveTest, unittest.TestCase):
51486F800E44E190 8BCC6480113B0580 B6F4EC000EEB3630 441317800A5B48A0 \
""")
if sys.byteorder != 'big':
- frames = byteswap(frames, 4)
+ frames = wave._byteswap(frames, 4)
class MiscTestCase(unittest.TestCase):
diff --git a/Lib/wave.py b/Lib/wave.py
index b707119..47a233d 100644
--- a/Lib/wave.py
+++ b/Lib/wave.py
@@ -73,7 +73,6 @@ is destroyed.
from chunk import Chunk
from collections import namedtuple
-import audioop
import builtins
import struct
import sys
@@ -91,6 +90,16 @@ _array_fmts = None, 'b', 'h', None, 'i'
_wave_params = namedtuple('_wave_params',
'nchannels sampwidth framerate nframes comptype compname')
+def _byteswap(data, width):
+ swapped_data = bytearray(len(data))
+
+ for i in range(0, len(data), width):
+ for j in range(width):
+ swapped_data[i + width - 1 - j] = data[i + j]
+
+ return bytes(swapped_data)
+
+
class Wave_read:
"""Variables used in this class:
@@ -241,7 +250,7 @@ class Wave_read:
return b''
data = self._data_chunk.read(nframes * self._framesize)
if self._sampwidth != 1 and sys.byteorder == 'big':
- data = audioop.byteswap(data, self._sampwidth)
+ data = _byteswap(data, self._sampwidth)
if self._convert and data:
data = self._convert(data)
self._soundpos = self._soundpos + len(data) // (self._nchannels * self._sampwidth)
@@ -428,7 +437,7 @@ class Wave_write:
if self._convert:
data = self._convert(data)
if self._sampwidth != 1 and sys.byteorder == 'big':
- data = audioop.byteswap(data, self._sampwidth)
+ data = _byteswap(data, self._sampwidth)
self._file.write(data)
self._datawritten += len(data)
self._nframeswritten = self._nframeswritten + nframes
diff --git a/Misc/NEWS.d/next/Library/2022-04-06-18-01-28.bpo-47061.qoVTR9.rst b/Misc/NEWS.d/next/Library/2022-04-06-18-01-28.bpo-47061.qoVTR9.rst
new file mode 100644
index 0000000..65ffa2e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-04-06-18-01-28.bpo-47061.qoVTR9.rst
@@ -0,0 +1 @@
+Deprecate audioop.
diff --git a/Modules/audioop.c b/Modules/audioop.c
index 32237ca..d74e634 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -1975,5 +1975,12 @@ static struct PyModuleDef audioopmodule = {
PyMODINIT_FUNC
PyInit_audioop(void)
{
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "'audioop' is deprecated and slated for removal in "
+ "Python 3.13",
+ 7)) {
+ return NULL;
+ }
+
return PyModuleDef_Init(&audioopmodule);
}