Update some libs and tests to `3.14.7` (#8559) · sheeeng/rustpython-rustpython@cc1e55e · GitHub
Skip to content

Commit cc1e55e

Browse files
authored
Update some libs and tests to 3.14.7 (RustPython#8559)
* Update some libs * Update some tests * more tests * test_pydoc.py * test_mimetypes.py * Restore json decoder * reapply updaye
1 parent acad681 commit cc1e55e

31 files changed

Lines changed: 1147 additions & 234 deletions

Lib/_pydatetime.py

Lines changed: 7 additions & 6 deletions

Lib/_pyio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,7 @@ def truncate(self, pos=None):
19041904
"""Truncate size to pos, where pos is an int."""
19051905
self._unsupported("truncate")
19061906

1907-
def readline(self):
1907+
def readline(self, size=-1, /):
19081908
"""Read until newline or EOF.
19091909
19101910
Returns an empty string if EOF is hit immediately.

Lib/argparse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,9 @@ def _prog_name(prog=None):
18291829
if modspec is None:
18301830
# simple script
18311831
return _os.path.basename(arg0)
1832+
if modspec.name != '__main__' and arg0 != modspec.origin:
1833+
# named module executed as main without altering sys.argv[0]
1834+
return _os.path.basename(arg0)
18321835
py = _os.path.basename(_sys.executable)
18331836
if modspec.name != '__main__':
18341837
# imported module or package

Lib/base64.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Base16, Base32, Base64 (RFC 3548), Base85 and Ascii85 data encodings"""
1+
"""Base16, Base32, Base64 (RFC 4648), Base85 and Ascii85 data encodings"""
22

33
# Modified 04-Oct-1995 by Jack Jansen to use binascii module
44
# Modified 30-Dec-2003 by Barry Warsaw to add full RFC 3548 support
@@ -147,7 +147,7 @@ def urlsafe_b64decode(s):
147147
characters present in the input.
148148
'''
149149
_B32_DECODE_MAP01_DOCSTRING = '''
150-
RFC 3548 allows for optional mapping of the digit 0 (zero) to the
150+
RFC 4648 allows for optional mapping of the digit 0 (zero) to the
151151
letter O (oh), and for optional mapping of the digit 1 (one) to
152152
either the letter I (eye) or letter L (el). The optional argument
153153
map01 when not None, specifies which letter the digit 1 should be
@@ -261,7 +261,7 @@ def b32hexdecode(s, casefold=False):
261261
extra_args='')
262262

263263

264-
# RFC 3548, Base 16 Alphabet specifies uppercase, but hexlify() returns
264+
# RFC 4648, Base 16 Alphabet specifies uppercase, but hexlify() returns
265265
# lowercase. The RFC also recommends against accepting input case
266266
# insensitively.
267267
def b16encode(s):

Lib/collections/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,9 @@ class Counter(dict):
553553
or multiset. Elements are stored as dictionary keys and their counts
554554
are stored as dictionary values.
555555
556+
When constructed from a Mapping or Counter, the original object's
557+
values will be used as the initial counts.
558+
556559
>>> c = Counter('abcdeabcdabcaba') # count elements from a string
557560
558561
>>> c.most_common(3) # three most common elements

Lib/configparser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,9 @@ def _write_section(self, fp, section_name, section_items, delimiter, unnamed=Fal
992992
value = self._interpolation.before_write(self, section_name, key,
993993
value)
994994
if value is not None or not self._allow_no_value:
995-
value = delimiter + str(value).replace('\n', '\n\t')
995+
# Convert all possible line-endings into '\n\t'
996+
value = (delimiter + str(value).replace('\r\n', '\n')
997+
.replace('\r', '\n').replace('\n', '\n\t'))
996998
else:
997999
value = ""
9981000
fp.write("{}{}\n".format(key, value))

Lib/csv.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,14 @@ def __init__(self):
243243
def sniff(self, sample, delimiters=None):
244244
"""
245245
Returns a dialect (or None) corresponding to the sample
246+
247+
If several delimiters fit the sample equally well, the
248+
delimiters listed in the preferred attribute are preferred, in
249+
that order, no matter how many times each of them occurs.
246250
"""
247251

252+
sample = sample.replace('\r\n', '\n').replace('\r', '\n')
253+
248254
quotechar, doublequote, delimiter, skipinitialspace = \
249255
self._guess_quote_and_delimiter(sample, delimiters)
250256
if not delimiter:
@@ -282,12 +288,16 @@ def _guess_quote_and_delimiter(self, data, delimiters):
282288
"""
283289
import re
284290

291+
# The body of a quoted field ends at the first quote which is
292+
# not doubled, as it does for a reader. A lazy ".*?" scans to
293+
# the end of the sample instead, from every start: quadratically.
294+
body = r'(?:(?P=quote){2}|(?!(?P=quote)).)*+'
285295
matches = []
286-
for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
287-
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # ".*?",
288-
r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', # ,".*?"
289-
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space)
290-
regexp = re.compile(restr, re.DOTALL | re.MULTILINE)
296+
for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\'])%s(?P=quote)(?P=delim)', # ,"...",
297+
r'(?:^|\n)(?P<quote>["\'])%s(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # "...",
298+
r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\'])%s(?P=quote)(?:$|\n)', # ,"..."
299+
r'(?:^|\n)(?P<quote>["\'])%s(?P=quote)(?:$|\n)'): # "..." (no delim, no space)
300+
regexp = re.compile(restr % body, re.DOTALL | re.MULTILINE)
291301
matches = regexp.findall(data)
292302
if matches:
293303
break
@@ -330,18 +340,22 @@ def _guess_quote_and_delimiter(self, data, delimiters):
330340
delim = ''
331341
skipinitialspace = 0
332342

333-
# if we see an extra quote between delimiters, we've got a
334-
# double quoted format
335-
dq_regexp = re.compile(
336-
r"((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$)" % \
337-
{'delim':re.escape(delim), 'quote':quotechar}, re.MULTILINE)
338-
339-
340-
341-
if dq_regexp.search(data):
342-
doublequote = True
343-
else:
344-
doublequote = False
343+
# A doubled quote character inside a quoted field means
344+
# a double quoted format. Match whole fields, so that a match
345+
# cannot slide across field boundaries.
346+
doublequote = False
347+
if delim:
348+
dq_regexp = re.compile(
349+
r"(?:(?<=%(delim)s)|^)%(space)s%(quote)s" # ,"
350+
r"((?:%(quote)s%(quote)s|[^%(quote)s]++)*+)" # the body
351+
r"%(quote)s(?:%(delim)s|$)" # ",
352+
% {'delim': re.escape(delim), 'quote': quotechar,
353+
# Skipping spaces after a space rescans them.
354+
'space': ' *+' if delim != ' ' else ''},
355+
re.MULTILINE)
356+
dquotechar = quotechar * 2
357+
doublequote = any(dquotechar in m[1]
358+
for m in dq_regexp.finditer(data))
345359

346360
return (quotechar, doublequote, delim, skipinitialspace)
347361

Lib/dataclasses.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,7 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen,
12471247
# classes with slots. These could be slightly more performant if we generated
12481248
# the code instead of iterating over fields. But that can be a project for
12491249
# another day, if performance becomes an issue.
1250+
12501251
def _dataclass_getstate(self):
12511252
return [getattr(self, f.name) for f in fields(self)]
12521253

Lib/difflib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,8 @@ def make_table(self,fromlines,tolines,fromdesc='',todesc='',context=False,
19771977

19781978
# change tabs to spaces before it gets more difficult after we insert
19791979
# markup
1980+
# it also removes trailing newlines, causing some diffs to be missed
1981+
# see: gh-71896
19801982
fromlines,tolines = self._tab_newline_replace(fromlines,tolines)
19811983

19821984
# create diffs iterator which generates side by side from/to data

Lib/glob.py

Lines changed: 4 additions & 4 deletions

0 commit comments

Comments
 (0)