Skip to content

Commit d0719cf

Browse files
committed
1 parent 04c7d12 commit d0719cf

File tree

139 files changed

+938
-584
lines changed

Some content is hidden

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

139 files changed

+938
-584
lines changed

PythonLib/full/_collections_abc.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,10 @@ def __getitem__(self, item):
500500
if subparams:
501501
subargs = tuple(subst[x] for x in subparams)
502502
arg = arg[subargs]
503-
new_args.append(arg)
503+
if isinstance(arg, tuple):
504+
new_args.extend(arg)
505+
else:
506+
new_args.append(arg)
504507

505508
# args[0] occurs due to things like Z[[int, str, bool]] from PEP 612
506509
if not isinstance(new_args[0], list):
@@ -868,7 +871,7 @@ class KeysView(MappingView, Set):
868871
__slots__ = ()
869872

870873
@classmethod
871-
def _from_iterable(self, it):
874+
def _from_iterable(cls, it):
872875
return set(it)
873876

874877
def __contains__(self, key):
@@ -886,7 +889,7 @@ class ItemsView(MappingView, Set):
886889
__slots__ = ()
887890

888891
@classmethod
889-
def _from_iterable(self, it):
892+
def _from_iterable(cls, it):
890893
return set(it)
891894

892895
def __contains__(self, item):

PythonLib/full/_pyio.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ class UnsupportedOperation(OSError, ValueError):
338338

339339
class IOBase(metaclass=abc.ABCMeta):
340340

341-
"""The abstract base class for all I/O classes, acting on streams of
342-
bytes. There is no public constructor.
341+
"""The abstract base class for all I/O classes.
343342
344343
This class provides dummy implementations for many methods that
345344
derived classes can override selectively; the default implementations
@@ -1845,7 +1844,7 @@ class TextIOBase(IOBase):
18451844
"""Base class for text I/O.
18461845
18471846
This class provides a character and line based interface to stream
1848-
I/O. There is no public constructor.
1847+
I/O.
18491848
"""
18501849

18511850
def read(self, size=-1):

PythonLib/full/argparse.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ def _get_action_name(argument):
726726
if argument is None:
727727
return None
728728
elif argument.option_strings:
729-
return '/'.join(argument.option_strings)
729+
return '/'.join(argument.option_strings)
730730
elif argument.metavar not in (None, SUPPRESS):
731731
return argument.metavar
732732
elif argument.dest not in (None, SUPPRESS):
@@ -878,7 +878,7 @@ def __init__(self,
878878
option_string = '--no-' + option_string[2:]
879879
_option_strings.append(option_string)
880880

881-
if help is not None and default is not None:
881+
if help is not None and default is not None and default is not SUPPRESS:
882882
help += " (default: %(default)s)"
883883

884884
super().__init__(
@@ -1256,9 +1256,9 @@ def __call__(self, string):
12561256
# the special argument "-" means sys.std{in,out}
12571257
if string == '-':
12581258
if 'r' in self._mode:
1259-
return _sys.stdin
1260-
elif 'w' in self._mode:
1261-
return _sys.stdout
1259+
return _sys.stdin.buffer if 'b' in self._mode else _sys.stdin
1260+
elif any(c in self._mode for c in 'wax'):
1261+
return _sys.stdout.buffer if 'b' in self._mode else _sys.stdout
12621262
else:
12631263
msg = _('argument "-" with mode %r') % self._mode
12641264
raise ValueError(msg)

PythonLib/full/asyncio/base_events.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from .log import logger
5050

5151

52-
__all__ = 'BaseEventLoop',
52+
__all__ = 'BaseEventLoop','Server',
5353

5454

5555
# Minimum number of _scheduled timer handles before cleanup of
@@ -202,6 +202,11 @@ def _set_nodelay(sock):
202202
pass
203203

204204

205+
def _check_ssl_socket(sock):
206+
if ssl is not None and isinstance(sock, ssl.SSLSocket):
207+
raise TypeError("Socket cannot be of type SSLSocket")
208+
209+
205210
class _SendfileFallbackProtocol(protocols.Protocol):
206211
def __init__(self, transp):
207212
if not isinstance(transp, transports._FlowControlMixin):
@@ -863,6 +868,7 @@ async def sock_sendfile(self, sock, file, offset=0, count=None,
863868
*, fallback=True):
864869
if self._debug and sock.gettimeout() != 0:
865870
raise ValueError("the socket must be non-blocking")
871+
_check_ssl_socket(sock)
866872
self._check_sendfile_params(sock, file, offset, count)
867873
try:
868874
return await self._sock_sendfile_native(sock, file,
@@ -1004,6 +1010,9 @@ async def create_connection(
10041010
raise ValueError(
10051011
'ssl_handshake_timeout is only meaningful with ssl')
10061012

1013+
if sock is not None:
1014+
_check_ssl_socket(sock)
1015+
10071016
if happy_eyeballs_delay is not None and interleave is None:
10081017
# If using happy eyeballs, default to interleave addresses by family
10091018
interleave = 1
@@ -1437,6 +1446,9 @@ async def create_server(
14371446
raise ValueError(
14381447
'ssl_handshake_timeout is only meaningful with ssl')
14391448

1449+
if sock is not None:
1450+
_check_ssl_socket(sock)
1451+
14401452
if host is not None or port is not None:
14411453
if sock is not None:
14421454
raise ValueError(
@@ -1531,6 +1543,9 @@ async def connect_accepted_socket(
15311543
raise ValueError(
15321544
'ssl_handshake_timeout is only meaningful with ssl')
15331545

1546+
if sock is not None:
1547+
_check_ssl_socket(sock)
1548+
15341549
transport, protocol = await self._create_connection_transport(
15351550
sock, protocol_factory, ssl, '', server_side=True,
15361551
ssl_handshake_timeout=ssl_handshake_timeout)

PythonLib/full/asyncio/futures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import contextvars
99
import logging
1010
import sys
11+
from types import GenericAlias
1112

1213
from . import base_futures
1314
from . import events
@@ -106,8 +107,7 @@ def __del__(self):
106107
context['source_traceback'] = self._source_traceback
107108
self._loop.call_exception_handler(context)
108109

109-
def __class_getitem__(cls, type):
110-
return cls
110+
__class_getitem__ = classmethod(GenericAlias)
111111

112112
@property
113113
def _log_traceback(self):

PythonLib/full/asyncio/proactor_events.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _call_connection_lost(self, exc):
158158
# end then it may fail with ERROR_NETNAME_DELETED if we
159159
# just close our end. First calling shutdown() seems to
160160
# cure it, but maybe using DisconnectEx() would be better.
161-
if hasattr(self._sock, 'shutdown'):
161+
if hasattr(self._sock, 'shutdown') and self._sock.fileno() != -1:
162162
self._sock.shutdown(socket.SHUT_RDWR)
163163
self._sock.close()
164164
self._sock = None
@@ -452,7 +452,8 @@ def _pipe_closed(self, fut):
452452
self.close()
453453

454454

455-
class _ProactorDatagramTransport(_ProactorBasePipeTransport):
455+
class _ProactorDatagramTransport(_ProactorBasePipeTransport,
456+
transports.DatagramTransport):
456457
max_size = 256 * 1024
457458
def __init__(self, loop, sock, protocol, address=None,
458459
waiter=None, extra=None):

PythonLib/full/asyncio/protocols.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ def eof_received(self):
109109
class BufferedProtocol(BaseProtocol):
110110
"""Interface for stream protocol with manual buffer control.
111111
112-
Important: this has been added to asyncio in Python 3.7
113-
*on a provisional basis*! Consider it as an experimental API that
114-
might be changed or removed in Python 3.8.
115-
116112
Event methods, such as `create_server` and `create_connection`,
117113
accept factories that return protocols that implement this interface.
118114

PythonLib/full/asyncio/queues.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import collections
44
import heapq
5+
from types import GenericAlias
56

67
from . import locks
78
from . import mixins
@@ -69,8 +70,7 @@ def __repr__(self):
6970
def __str__(self):
7071
return f'<{type(self).__name__} {self._format()}>'
7172

72-
def __class_getitem__(cls, type):
73-
return cls
73+
__class_getitem__ = classmethod(GenericAlias)
7474

7575
def _format(self):
7676
result = f'maxsize={self._maxsize!r}'

PythonLib/full/asyncio/selector_events.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ def _test_selector_event(selector, fd, event):
4040
return bool(key.events & event)
4141

4242

43-
def _check_ssl_socket(sock):
44-
if ssl is not None and isinstance(sock, ssl.SSLSocket):
45-
raise TypeError("Socket cannot be of type SSLSocket")
46-
47-
4843
class BaseSelectorEventLoop(base_events.BaseEventLoop):
4944
"""Selector event loop.
5045
@@ -357,7 +352,7 @@ async def sock_recv(self, sock, n):
357352
The maximum amount of data to be received at once is specified by
358353
nbytes.
359354
"""
360-
_check_ssl_socket(sock)
355+
base_events._check_ssl_socket(sock)
361356
if self._debug and sock.gettimeout() != 0:
362357
raise ValueError("the socket must be non-blocking")
363358
try:
@@ -398,7 +393,7 @@ async def sock_recv_into(self, sock, buf):
398393
The received data is written into *buf* (a writable buffer).
399394
The return value is the number of bytes written.
400395
"""
401-
_check_ssl_socket(sock)
396+
base_events._check_ssl_socket(sock)
402397
if self._debug and sock.gettimeout() != 0:
403398
raise ValueError("the socket must be non-blocking")
404399
try:
@@ -439,7 +434,7 @@ async def sock_sendall(self, sock, data):
439434
raised, and there is no way to determine how much data, if any, was
440435
successfully processed by the receiving end of the connection.
441436
"""
442-
_check_ssl_socket(sock)
437+
base_events._check_ssl_socket(sock)
443438
if self._debug and sock.gettimeout() != 0:
444439
raise ValueError("the socket must be non-blocking")
445440
try:
@@ -488,13 +483,15 @@ async def sock_connect(self, sock, address):
488483
489484
This method is a coroutine.
490485
"""
491-
_check_ssl_socket(sock)
486+
base_events._check_ssl_socket(sock)
492487
if self._debug and sock.gettimeout() != 0:
493488
raise ValueError("the socket must be non-blocking")
494489

495490
if not hasattr(socket, 'AF_UNIX') or sock.family != socket.AF_UNIX:
496491
resolved = await self._ensure_resolved(
497-
address, family=sock.family, proto=sock.proto, loop=self)
492+
address, family=sock.family, type=sock.type, proto=sock.proto,
493+
loop=self,
494+
)
498495
_, _, _, _, address = resolved[0]
499496

500497
fut = self.create_future()
@@ -553,7 +550,7 @@ async def sock_accept(self, sock):
553550
object usable to send and receive data on the connection, and address
554551
is the address bound to the socket on the other end of the connection.
555552
"""
556-
_check_ssl_socket(sock)
553+
base_events._check_ssl_socket(sock)
557554
if self._debug and sock.gettimeout() != 0:
558555
raise ValueError("the socket must be non-blocking")
559556
fut = self.create_future()

PythonLib/full/asyncio/sslproto.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,12 @@ def get_write_buffer_size(self):
367367
"""Return the current size of the write buffer."""
368368
return self._ssl_protocol._transport.get_write_buffer_size()
369369

370+
def get_write_buffer_limits(self):
371+
"""Get the high and low watermarks for write flow control.
372+
Return a tuple (low, high) where low and high are
373+
positive number of bytes."""
374+
return self._ssl_protocol._transport.get_write_buffer_limits()
375+
370376
@property
371377
def _protocol_paused(self):
372378
# Required for sendfile fallback pause_writing/resume_writing logic

0 commit comments

Comments
 (0)