Skip to content

Commit 0f01dd6

Browse files
authored
update to python 3.8.7 (#179)
1 parent 9ae4551 commit 0f01dd6

File tree

137 files changed

+2474
-1216
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+2474
-1216
lines changed

PythonLib/full/ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def _splitlines_no_ff(source):
285285

286286

287287
def _pad_whitespace(source):
288-
"""Replace all chars except '\f\t' in a line with spaces."""
288+
r"""Replace all chars except '\f\t' in a line with spaces."""
289289
result = ''
290290
for c in source:
291291
if c in '\f\t':

PythonLib/full/asyncio/base_futures.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
__all__ = ()
22

33
import reprlib
4+
from _thread import get_ident
45

56
from . import format_helpers
67

@@ -41,6 +42,16 @@ def format_cb(callback):
4142
return f'cb=[{cb}]'
4243

4344

45+
# bpo-42183: _repr_running is needed for repr protection
46+
# when a Future or Task result contains itself directly or indirectly.
47+
# The logic is borrowed from @reprlib.recursive_repr decorator.
48+
# Unfortunately, the direct decorator usage is impossible because of
49+
# AttributeError: '_asyncio.Task' object has no attribute '__module__' error.
50+
#
51+
# After fixing this thing we can return to the decorator based approach.
52+
_repr_running = set()
53+
54+
4455
def _future_repr_info(future):
4556
# (Future) -> str
4657
"""helper function for Future.__repr__"""
@@ -49,9 +60,17 @@ def _future_repr_info(future):
4960
if future._exception is not None:
5061
info.append(f'exception={future._exception!r}')
5162
else:
52-
# use reprlib to limit the length of the output, especially
53-
# for very long strings
54-
result = reprlib.repr(future._result)
63+
key = id(future), get_ident()
64+
if key in _repr_running:
65+
result = '...'
66+
else:
67+
_repr_running.add(key)
68+
try:
69+
# use reprlib to limit the length of the output, especially
70+
# for very long strings
71+
result = reprlib.repr(future._result)
72+
finally:
73+
_repr_running.discard(key)
5574
info.append(f'result={result}')
5675
if future._callbacks:
5776
info.append(_format_callbacks(future._callbacks))

PythonLib/full/asyncio/exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ class IncompleteReadError(EOFError):
3434
- expected: total number of expected bytes (or None if unknown)
3535
"""
3636
def __init__(self, partial, expected):
37+
r_expected = 'undefined' if expected is None else repr(expected)
3738
super().__init__(f'{len(partial)} bytes read on a total of '
38-
f'{expected!r} expected bytes')
39+
f'{r_expected} expected bytes')
3940
self.partial = partial
4041
self.expected = expected
4142

PythonLib/full/asyncio/tasks.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def create_task(coro, *, name=None):
394394
async def wait(fs, *, loop=None, timeout=None, return_when=ALL_COMPLETED):
395395
"""Wait for the Futures and coroutines given by fs to complete.
396396
397-
The sequence futures must not be empty.
397+
The fs iterable must not be empty.
398398
399399
Coroutines will be wrapped in Tasks.
400400
@@ -484,7 +484,10 @@ async def wait_for(fut, timeout, *, loop=None):
484484
return fut.result()
485485
else:
486486
fut.remove_done_callback(cb)
487-
fut.cancel()
487+
# We must ensure that the task is not running
488+
# after wait_for() returns.
489+
# See https://bugs.python.org/issue32751
490+
await _cancel_and_wait(fut, loop=loop)
488491
raise
489492

490493
if fut.done():
@@ -580,7 +583,7 @@ def as_completed(fs, *, loop=None, timeout=None):
580583
Note: The futures 'f' are not necessarily members of fs.
581584
"""
582585
if futures.isfuture(fs) or coroutines.iscoroutine(fs):
583-
raise TypeError(f"expect a list of futures, not {type(fs).__name__}")
586+
raise TypeError(f"expect an iterable of futures, not {type(fs).__name__}")
584587

585588
from .queues import Queue # Import here to avoid circular import problem.
586589
done = Queue(loop=loop)

PythonLib/full/asyncio/unix_events.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,13 +1152,15 @@ def is_active(self):
11521152

11531153
def close(self):
11541154
self._callbacks.clear()
1155-
if self._saved_sighandler is not None:
1156-
handler = signal.getsignal(signal.SIGCHLD)
1157-
if handler != self._sig_chld:
1158-
logger.warning("SIGCHLD handler was changed by outside code")
1159-
else:
1160-
signal.signal(signal.SIGCHLD, self._saved_sighandler)
1161-
self._saved_sighandler = None
1155+
if self._saved_sighandler is None:
1156+
return
1157+
1158+
handler = signal.getsignal(signal.SIGCHLD)
1159+
if handler != self._sig_chld:
1160+
logger.warning("SIGCHLD handler was changed by outside code")
1161+
else:
1162+
signal.signal(signal.SIGCHLD, self._saved_sighandler)
1163+
self._saved_sighandler = None
11621164

11631165
def __enter__(self):
11641166
return self
@@ -1185,15 +1187,17 @@ def attach_loop(self, loop):
11851187
# The reason to do it here is that attach_loop() is called from
11861188
# unix policy only for the main thread.
11871189
# Main thread is required for subscription on SIGCHLD signal
1190+
if self._saved_sighandler is not None:
1191+
return
1192+
1193+
self._saved_sighandler = signal.signal(signal.SIGCHLD, self._sig_chld)
11881194
if self._saved_sighandler is None:
1189-
self._saved_sighandler = signal.signal(signal.SIGCHLD, self._sig_chld)
1190-
if self._saved_sighandler is None:
1191-
logger.warning("Previous SIGCHLD handler was set by non-Python code, "
1192-
"restore to default handler on watcher close.")
1193-
self._saved_sighandler = signal.SIG_DFL
1195+
logger.warning("Previous SIGCHLD handler was set by non-Python code, "
1196+
"restore to default handler on watcher close.")
1197+
self._saved_sighandler = signal.SIG_DFL
11941198

1195-
# Set SA_RESTART to limit EINTR occurrences.
1196-
signal.siginterrupt(signal.SIGCHLD, False)
1199+
# Set SA_RESTART to limit EINTR occurrences.
1200+
signal.siginterrupt(signal.SIGCHLD, False)
11971201

11981202
def _do_waitpid_all(self):
11991203
for pid in list(self._callbacks):

PythonLib/full/binhex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ def _flush(self, force):
100100
first = 0
101101
while first <= len(self.hqxdata) - self.linelen:
102102
last = first + self.linelen
103-
self.ofp.write(self.hqxdata[first:last] + b'\n')
103+
self.ofp.write(self.hqxdata[first:last] + b'\r')
104104
self.linelen = LINELEN
105105
first = last
106106
self.hqxdata = self.hqxdata[first:]
107107
if force:
108-
self.ofp.write(self.hqxdata + b':\n')
108+
self.ofp.write(self.hqxdata + b':\r')
109109

110110
def close(self):
111111
if self.data:

PythonLib/full/cProfile.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ def main():
168168
(options, args) = parser.parse_args()
169169
sys.argv[:] = args
170170

171+
# The script that we're profiling may chdir, so capture the absolute path
172+
# to the output file at startup.
173+
if options.outfile is not None:
174+
options.outfile = os.path.abspath(options.outfile)
175+
171176
if len(args) > 0:
172177
if options.module:
173178
code = "run_module(modname, run_name='__main__')"

PythonLib/full/ctypes/test/test_find.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
import unittest.mock
23
import os.path
34
import sys
45
import test.support
@@ -72,7 +73,7 @@ def test_shell_injection(self):
7273

7374
@unittest.skipUnless(sys.platform.startswith('linux'),
7475
'Test only valid for Linux')
75-
class LibPathFindTest(unittest.TestCase):
76+
class FindLibraryLinux(unittest.TestCase):
7677
def test_find_on_libpath(self):
7778
import subprocess
7879
import tempfile
@@ -111,6 +112,15 @@ def test_find_on_libpath(self):
111112
# LD_LIBRARY_PATH)
112113
self.assertEqual(find_library(libname), 'lib%s.so' % libname)
113114

115+
def test_find_library_with_gcc(self):
116+
with unittest.mock.patch("ctypes.util._findSoname_ldconfig", lambda *args: None):
117+
self.assertNotEqual(find_library('c'), None)
118+
119+
def test_find_library_with_ld(self):
120+
with unittest.mock.patch("ctypes.util._findSoname_ldconfig", lambda *args: None), \
121+
unittest.mock.patch("ctypes.util._findLib_gcc", lambda *args: None):
122+
self.assertNotEqual(find_library('c'), None)
123+
114124

115125
if __name__ == "__main__":
116126
unittest.main()

PythonLib/full/ctypes/test/test_wintypes.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import sys
21
import unittest
32

3+
# also work on POSIX
4+
45
from ctypes import *
6+
from ctypes import wintypes
7+
58

6-
@unittest.skipUnless(sys.platform.startswith('win'), 'Windows-only test')
79
class WinTypesTest(unittest.TestCase):
810
def test_variant_bool(self):
9-
from ctypes import wintypes
1011
# reads 16-bits from memory, anything non-zero is True
1112
for true_value in (1, 32767, 32768, 65535, 65537):
1213
true = POINTER(c_int16)(c_int16(true_value))
@@ -37,5 +38,6 @@ def test_variant_bool(self):
3738
vb.value = []
3839
self.assertIs(vb.value, False)
3940

41+
4042
if __name__ == "__main__":
4143
unittest.main()

PythonLib/full/ctypes/util.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ def find_library(name):
9393
# Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
9494
import re, tempfile
9595

96+
def _is_elf(filename):
97+
"Return True if the given file is an ELF file"
98+
elf_header = b'\x7fELF'
99+
with open(filename, 'br') as thefile:
100+
return thefile.read(4) == elf_header
101+
96102
def _findLib_gcc(name):
97103
# Run GCC's linker with the -t (aka --trace) option and examine the
98104
# library name it prints out. The GCC command will fail because we
@@ -130,10 +136,17 @@ def _findLib_gcc(name):
130136
# Raised if the file was already removed, which is the normal
131137
# behaviour of GCC if linking fails
132138
pass
133-
res = re.search(expr, trace)
139+
res = re.findall(expr, trace)
134140
if not res:
135141
return None
136-
return os.fsdecode(res.group(0))
142+
143+
for file in res:
144+
# Check if the given file is an elf file: gcc can report
145+
# some files that are linker scripts and not actual
146+
# shared objects. See bpo-41976 for more details
147+
if not _is_elf(file):
148+
continue
149+
return os.fsdecode(file)
137150

138151

139152
if sys.platform == "sunos5":
@@ -299,17 +312,22 @@ def _findLib_ld(name):
299312
stderr=subprocess.PIPE,
300313
universal_newlines=True)
301314
out, _ = p.communicate()
302-
res = re.search(expr, os.fsdecode(out))
303-
if res:
304-
result = res.group(0)
305-
except Exception as e:
315+
res = re.findall(expr, os.fsdecode(out))
316+
for file in res:
317+
# Check if the given file is an elf file: gcc can report
318+
# some files that are linker scripts and not actual
319+
# shared objects. See bpo-41976 for more details
320+
if not _is_elf(file):
321+
continue
322+
return os.fsdecode(file)
323+
except Exception:
306324
pass # result will be None
307325
return result
308326

309327
def find_library(name):
310328
# See issue #9998
311329
return _findSoname_ldconfig(name) or \
312-
_get_soname(_findLib_gcc(name) or _findLib_ld(name))
330+
_get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name))
313331

314332
################################################################
315333
# test code

0 commit comments

Comments
 (0)