Skip to content

Commit a6a9212

Browse files
authored
Merge pull request RustPython#5007 from DimitrisJim/pylibs_upgrade_uno
Bump some Python libraries to 3.11
2 parents 8dbf7b2 + 436be2b commit a6a9212

File tree

13 files changed

+633
-316
lines changed

13 files changed

+633
-316
lines changed

Lib/aifc.py

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@
138138
import builtins
139139
import warnings
140140

141-
__all__ = ["Error", "open", "openfp"]
141+
__all__ = ["Error", "open"]
142+
143+
144+
warnings._deprecated(__name__, remove=(3, 13))
145+
142146

143147
class Error(Exception):
144148
pass
@@ -251,7 +255,9 @@ def _write_float(f, x):
251255
_write_ulong(f, himant)
252256
_write_ulong(f, lomant)
253257

254-
from chunk import Chunk
258+
with warnings.catch_warnings():
259+
warnings.simplefilter("ignore", DeprecationWarning)
260+
from chunk import Chunk
255261
from collections import namedtuple
256262

257263
_aifc_params = namedtuple('_aifc_params',
@@ -447,21 +453,33 @@ def readframes(self, nframes):
447453
#
448454

449455
def _alaw2lin(self, data):
450-
import audioop
456+
with warnings.catch_warnings():
457+
warnings.simplefilter('ignore', category=DeprecationWarning)
458+
import audioop
451459
return audioop.alaw2lin(data, 2)
452460

453461
def _ulaw2lin(self, data):
454-
import audioop
462+
with warnings.catch_warnings():
463+
warnings.simplefilter('ignore', category=DeprecationWarning)
464+
import audioop
455465
return audioop.ulaw2lin(data, 2)
456466

457467
def _adpcm2lin(self, data):
458-
import audioop
468+
with warnings.catch_warnings():
469+
warnings.simplefilter('ignore', category=DeprecationWarning)
470+
import audioop
459471
if not hasattr(self, '_adpcmstate'):
460472
# first time
461473
self._adpcmstate = None
462474
data, self._adpcmstate = audioop.adpcm2lin(data, 2, self._adpcmstate)
463475
return data
464476

477+
def _sowt2lin(self, data):
478+
with warnings.catch_warnings():
479+
warnings.simplefilter('ignore', category=DeprecationWarning)
480+
import audioop
481+
return audioop.byteswap(data, 2)
482+
465483
def _read_comm_chunk(self, chunk):
466484
self._nchannels = _read_short(chunk)
467485
self._nframes = _read_long(chunk)
@@ -497,6 +515,8 @@ def _read_comm_chunk(self, chunk):
497515
self._convert = self._ulaw2lin
498516
elif self._comptype in (b'alaw', b'ALAW'):
499517
self._convert = self._alaw2lin
518+
elif self._comptype in (b'sowt', b'SOWT'):
519+
self._convert = self._sowt2lin
500520
else:
501521
raise Error('unsupported compression type')
502522
self._sampwidth = 2
@@ -659,7 +679,7 @@ def setcomptype(self, comptype, compname):
659679
if self._nframeswritten:
660680
raise Error('cannot change parameters after starting to write')
661681
if comptype not in (b'NONE', b'ulaw', b'ULAW',
662-
b'alaw', b'ALAW', b'G722'):
682+
b'alaw', b'ALAW', b'G722', b'sowt', b'SOWT'):
663683
raise Error('unsupported compression type')
664684
self._comptype = comptype
665685
self._compname = compname
@@ -680,7 +700,7 @@ def setparams(self, params):
680700
if self._nframeswritten:
681701
raise Error('cannot change parameters after starting to write')
682702
if comptype not in (b'NONE', b'ulaw', b'ULAW',
683-
b'alaw', b'ALAW', b'G722'):
703+
b'alaw', b'ALAW', b'G722', b'sowt', b'SOWT'):
684704
raise Error('unsupported compression type')
685705
self.setnchannels(nchannels)
686706
self.setsampwidth(sampwidth)
@@ -764,28 +784,43 @@ def close(self):
764784
#
765785

766786
def _lin2alaw(self, data):
767-
import audioop
787+
with warnings.catch_warnings():
788+
warnings.simplefilter('ignore', category=DeprecationWarning)
789+
import audioop
768790
return audioop.lin2alaw(data, 2)
769791

770792
def _lin2ulaw(self, data):
771-
import audioop
793+
with warnings.catch_warnings():
794+
warnings.simplefilter('ignore', category=DeprecationWarning)
795+
import audioop
772796
return audioop.lin2ulaw(data, 2)
773797

774798
def _lin2adpcm(self, data):
775-
import audioop
799+
with warnings.catch_warnings():
800+
warnings.simplefilter('ignore', category=DeprecationWarning)
801+
import audioop
776802
if not hasattr(self, '_adpcmstate'):
777803
self._adpcmstate = None
778804
data, self._adpcmstate = audioop.lin2adpcm(data, 2, self._adpcmstate)
779805
return data
780806

807+
def _lin2sowt(self, data):
808+
with warnings.catch_warnings():
809+
warnings.simplefilter('ignore', category=DeprecationWarning)
810+
import audioop
811+
return audioop.byteswap(data, 2)
812+
781813
def _ensure_header_written(self, datasize):
782814
if not self._nframeswritten:
783-
if self._comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'):
815+
if self._comptype in (b'ULAW', b'ulaw',
816+
b'ALAW', b'alaw', b'G722',
817+
b'sowt', b'SOWT'):
784818
if not self._sampwidth:
785819
self._sampwidth = 2
786820
if self._sampwidth != 2:
787821
raise Error('sample width must be 2 when compressing '
788-
'with ulaw/ULAW, alaw/ALAW or G7.22 (ADPCM)')
822+
'with ulaw/ULAW, alaw/ALAW, sowt/SOWT '
823+
'or G7.22 (ADPCM)')
789824
if not self._nchannels:
790825
raise Error('# channels not specified')
791826
if not self._sampwidth:
@@ -801,6 +836,8 @@ def _init_compression(self):
801836
self._convert = self._lin2ulaw
802837
elif self._comptype in (b'alaw', b'ALAW'):
803838
self._convert = self._lin2alaw
839+
elif self._comptype in (b'sowt', b'SOWT'):
840+
self._convert = self._lin2sowt
804841

805842
def _write_header(self, initlength):
806843
if self._aifc and self._comptype != b'NONE':
@@ -920,10 +957,6 @@ def open(f, mode=None):
920957
else:
921958
raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
922959

923-
def openfp(f, mode=None):
924-
warnings.warn("aifc.openfp is deprecated since Python 3.7. "
925-
"Use aifc.open instead.", DeprecationWarning, stacklevel=2)
926-
return open(f, mode=mode)
927960

928961
if __name__ == '__main__':
929962
import sys

Lib/cgi.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
1414
This module defines a number of utilities for use by CGI scripts
1515
written in Python.
16+
17+
The global variable maxlen can be set to an integer indicating the maximum size
18+
of a POST request. POST requests larger than this size will result in a
19+
ValueError being raised during parsing. The default value of this variable is 0,
20+
meaning the request size is unlimited.
1621
"""
1722

1823
# History
@@ -41,12 +46,16 @@
4146
import html
4247
import locale
4348
import tempfile
49+
import warnings
4450

4551
__all__ = ["MiniFieldStorage", "FieldStorage", "parse", "parse_multipart",
4652
"parse_header", "test", "print_exception", "print_environ",
4753
"print_form", "print_directory", "print_arguments",
4854
"print_environ_usage"]
4955

56+
57+
warnings._deprecated(__name__, remove=(3,13))
58+
5059
# Logging support
5160
# ===============
5261

@@ -77,9 +86,11 @@ def initlog(*allargs):
7786
7887
"""
7988
global log, logfile, logfp
89+
warnings.warn("cgi.log() is deprecated as of 3.10. Use logging instead",
90+
DeprecationWarning, stacklevel=2)
8091
if logfile and not logfp:
8192
try:
82-
logfp = open(logfile, "a")
93+
logfp = open(logfile, "a", encoding="locale")
8394
except OSError:
8495
pass
8596
if not logfp:
@@ -115,7 +126,8 @@ def closelog():
115126
# 0 ==> unlimited input
116127
maxlen = 0
117128

118-
def parse(fp=None, environ=os.environ, keep_blank_values=0, strict_parsing=0):
129+
def parse(fp=None, environ=os.environ, keep_blank_values=0,
130+
strict_parsing=0, separator='&'):
119131
"""Parse a query in the environment or from a file (default stdin)
120132
121133
Arguments, all optional:
@@ -134,6 +146,9 @@ def parse(fp=None, environ=os.environ, keep_blank_values=0, strict_parsing=0):
134146
strict_parsing: flag indicating what to do with parsing errors.
135147
If false (the default), errors are silently ignored.
136148
If true, errors raise a ValueError exception.
149+
150+
separator: str. The symbol to use for separating the query arguments.
151+
Defaults to &.
137152
"""
138153
if fp is None:
139154
fp = sys.stdin
@@ -154,7 +169,7 @@ def parse(fp=None, environ=os.environ, keep_blank_values=0, strict_parsing=0):
154169
if environ['REQUEST_METHOD'] == 'POST':
155170
ctype, pdict = parse_header(environ['CONTENT_TYPE'])
156171
if ctype == 'multipart/form-data':
157-
return parse_multipart(fp, pdict)
172+
return parse_multipart(fp, pdict, separator=separator)
158173
elif ctype == 'application/x-www-form-urlencoded':
159174
clength = int(environ['CONTENT_LENGTH'])
160175
if maxlen and clength > maxlen:
@@ -178,10 +193,10 @@ def parse(fp=None, environ=os.environ, keep_blank_values=0, strict_parsing=0):
178193
qs = ""
179194
environ['QUERY_STRING'] = qs # XXX Shouldn't, really
180195
return urllib.parse.parse_qs(qs, keep_blank_values, strict_parsing,
181-
encoding=encoding)
196+
encoding=encoding, separator=separator)
182197

183198

184-
def parse_multipart(fp, pdict, encoding="utf-8", errors="replace"):
199+
def parse_multipart(fp, pdict, encoding="utf-8", errors="replace", separator='&'):
185200
"""Parse multipart input.
186201
187202
Arguments:
@@ -194,15 +209,18 @@ def parse_multipart(fp, pdict, encoding="utf-8", errors="replace"):
194209
value is a list of values for that field. For non-file fields, the value
195210
is a list of strings.
196211
"""
197-
# RFC 2026, Section 5.1 : The "multipart" boundary delimiters are always
212+
# RFC 2046, Section 5.1 : The "multipart" boundary delimiters are always
198213
# represented as 7bit US-ASCII.
199214
boundary = pdict['boundary'].decode('ascii')
200215
ctype = "multipart/form-data; boundary={}".format(boundary)
201216
headers = Message()
202217
headers.set_type(ctype)
203-
headers['Content-Length'] = pdict['CONTENT-LENGTH']
218+
try:
219+
headers['Content-Length'] = pdict['CONTENT-LENGTH']
220+
except KeyError:
221+
pass
204222
fs = FieldStorage(fp, headers=headers, encoding=encoding, errors=errors,
205-
environ={'REQUEST_METHOD': 'POST'})
223+
environ={'REQUEST_METHOD': 'POST'}, separator=separator)
206224
return {k: fs.getlist(k) for k in fs}
207225

208226
def _parseparam(s):
@@ -312,7 +330,7 @@ class FieldStorage:
312330
def __init__(self, fp=None, headers=None, outerboundary=b'',
313331
environ=os.environ, keep_blank_values=0, strict_parsing=0,
314332
limit=None, encoding='utf-8', errors='replace',
315-
max_num_fields=None):
333+
max_num_fields=None, separator='&'):
316334
"""Constructor. Read multipart/* until last part.
317335
318336
Arguments, all optional:
@@ -360,6 +378,7 @@ def __init__(self, fp=None, headers=None, outerboundary=b'',
360378
self.keep_blank_values = keep_blank_values
361379
self.strict_parsing = strict_parsing
362380
self.max_num_fields = max_num_fields
381+
self.separator = separator
363382
if 'REQUEST_METHOD' in environ:
364383
method = environ['REQUEST_METHOD'].upper()
365384
self.qs_on_post = None
@@ -586,7 +605,7 @@ def read_urlencoded(self):
586605
query = urllib.parse.parse_qsl(
587606
qs, self.keep_blank_values, self.strict_parsing,
588607
encoding=self.encoding, errors=self.errors,
589-
max_num_fields=self.max_num_fields)
608+
max_num_fields=self.max_num_fields, separator=self.separator)
590609
self.list = [MiniFieldStorage(key, value) for key, value in query]
591610
self.skip_lines()
592611

@@ -602,7 +621,7 @@ def read_multi(self, environ, keep_blank_values, strict_parsing):
602621
query = urllib.parse.parse_qsl(
603622
self.qs_on_post, self.keep_blank_values, self.strict_parsing,
604623
encoding=self.encoding, errors=self.errors,
605-
max_num_fields=self.max_num_fields)
624+
max_num_fields=self.max_num_fields, separator=self.separator)
606625
self.list.extend(MiniFieldStorage(key, value) for key, value in query)
607626

608627
klass = self.FieldStorageClass or self.__class__
@@ -646,7 +665,7 @@ def read_multi(self, environ, keep_blank_values, strict_parsing):
646665
else self.limit - self.bytes_read
647666
part = klass(self.fp, headers, ib, environ, keep_blank_values,
648667
strict_parsing, limit,
649-
self.encoding, self.errors, max_num_fields)
668+
self.encoding, self.errors, max_num_fields, self.separator)
650669

651670
if max_num_fields is not None:
652671
max_num_fields -= 1
@@ -736,7 +755,8 @@ def read_lines_to_outerboundary(self):
736755
last_line_lfend = True
737756
_read = 0
738757
while 1:
739-
if self.limit is not None and _read >= self.limit:
758+
759+
if self.limit is not None and 0 <= self.limit <= _read:
740760
break
741761
line = self.fp.readline(1<<16) # bytes
742762
self.bytes_read += len(line)

Lib/cgitb.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
import time
3232
import tokenize
3333
import traceback
34+
import warnings
35+
from html import escape as html_escape
36+
37+
warnings._deprecated(__name__, remove=(3, 13))
38+
3439

3540
def reset():
3641
"""Return a string that resets the CGI and browser to a known state."""
@@ -105,10 +110,16 @@ def html(einfo, context=5):
105110
etype = etype.__name__
106111
pyver = 'Python ' + sys.version.split()[0] + ': ' + sys.executable
107112
date = time.ctime(time.time())
108-
head = '<body bgcolor="#f0f0f8">' + pydoc.html.heading(
109-
'<big><big>%s</big></big>' %
110-
strong(pydoc.html.escape(str(etype))),
111-
'#ffffff', '#6622aa', pyver + '<br>' + date) + '''
113+
head = f'''
114+
<body bgcolor="#f0f0f8">
115+
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
116+
<tr bgcolor="#6622aa">
117+
<td valign=bottom>&nbsp;<br>
118+
<font color="#ffffff" face="helvetica, arial">&nbsp;<br>
119+
<big><big><strong>{html_escape(str(etype))}</strong></big></big></font></td>
120+
<td align=right valign=bottom>
121+
<font color="#ffffff" face="helvetica, arial">{pyver}<br>{date}</font></td>
122+
</tr></table>
112123
<p>A problem occurred in a Python script. Here is the sequence of
113124
function calls leading up to the error, in the order they occurred.</p>'''
114125

@@ -181,8 +192,8 @@ def reader(lnum=[lnum]):
181192
182193
183194
<!-- The above is a description of an error in a Python program, formatted
184-
for a Web browser because the 'cgitb' module was enabled. In case you
185-
are not reading this in a Web browser, here is the original traceback:
195+
for a web browser because the 'cgitb' module was enabled. In case you
196+
are not reading this in a web browser, here is the original traceback:
186197
187198
%s
188199
-->

Lib/chunk.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
default is 1, i.e. aligned.
4949
"""
5050

51+
import warnings
52+
53+
warnings._deprecated(__name__, remove=(3, 13))
54+
5155
class Chunk:
5256
def __init__(self, file, align=True, bigendian=True, inclheader=False):
5357
import struct
@@ -64,7 +68,7 @@ def __init__(self, file, align=True, bigendian=True, inclheader=False):
6468
try:
6569
self.chunksize = struct.unpack_from(strflag+'L', file.read(4))[0]
6670
except struct.error:
67-
raise EOFError
71+
raise EOFError from None
6872
if inclheader:
6973
self.chunksize = self.chunksize - 8 # subtract header
7074
self.size_read = 0

0 commit comments

Comments
 (0)