aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/asyncio
diff options
context:
space:
mode:
authorarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-03-18 09:10:23 +0300
committerarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-03-18 09:10:23 +0300
commitfef2b3a8ed5955b63c71e8e541a5acf2e393925a (patch)
treee55d2882d5c2c71561a0aa89158ec174d81f92fd /contrib/tools/python3/src/Lib/asyncio
parent2acc0fc3cdc40434ea286f2fac62386e3fd9c19d (diff)
downloadydb-fef2b3a8ed5955b63c71e8e541a5acf2e393925a.tar.gz
intermediate changes
ref:102662f6c42fba80d7bfd4a328124cbb4294be48
Diffstat (limited to 'contrib/tools/python3/src/Lib/asyncio')
-rw-r--r--contrib/tools/python3/src/Lib/asyncio/base_events.py17
-rw-r--r--contrib/tools/python3/src/Lib/asyncio/futures.py4
-rw-r--r--contrib/tools/python3/src/Lib/asyncio/proactor_events.py5
-rw-r--r--contrib/tools/python3/src/Lib/asyncio/protocols.py4
-rw-r--r--contrib/tools/python3/src/Lib/asyncio/queues.py4
-rw-r--r--contrib/tools/python3/src/Lib/asyncio/selector_events.py19
-rw-r--r--contrib/tools/python3/src/Lib/asyncio/sslproto.py6
-rw-r--r--contrib/tools/python3/src/Lib/asyncio/tasks.py7
-rw-r--r--contrib/tools/python3/src/Lib/asyncio/transports.py6
9 files changed, 47 insertions, 25 deletions
diff --git a/contrib/tools/python3/src/Lib/asyncio/base_events.py b/contrib/tools/python3/src/Lib/asyncio/base_events.py
index 8c1fb49694..7a14e5e139 100644
--- a/contrib/tools/python3/src/Lib/asyncio/base_events.py
+++ b/contrib/tools/python3/src/Lib/asyncio/base_events.py
@@ -49,7 +49,7 @@ from . import trsock
from .log import logger
-__all__ = 'BaseEventLoop',
+__all__ = 'BaseEventLoop','Server',
# Minimum number of _scheduled timer handles before cleanup of
@@ -202,6 +202,11 @@ else:
pass
+def _check_ssl_socket(sock):
+ if ssl is not None and isinstance(sock, ssl.SSLSocket):
+ raise TypeError("Socket cannot be of type SSLSocket")
+
+
class _SendfileFallbackProtocol(protocols.Protocol):
def __init__(self, transp):
if not isinstance(transp, transports._FlowControlMixin):
@@ -864,6 +869,7 @@ class BaseEventLoop(events.AbstractEventLoop):
*, fallback=True):
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
+ _check_ssl_socket(sock)
self._check_sendfile_params(sock, file, offset, count)
try:
return await self._sock_sendfile_native(sock, file,
@@ -1005,6 +1011,9 @@ class BaseEventLoop(events.AbstractEventLoop):
raise ValueError(
'ssl_handshake_timeout is only meaningful with ssl')
+ if sock is not None:
+ _check_ssl_socket(sock)
+
if happy_eyeballs_delay is not None and interleave is None:
# If using happy eyeballs, default to interleave addresses by family
interleave = 1
@@ -1438,6 +1447,9 @@ class BaseEventLoop(events.AbstractEventLoop):
raise ValueError(
'ssl_handshake_timeout is only meaningful with ssl')
+ if sock is not None:
+ _check_ssl_socket(sock)
+
if host is not None or port is not None:
if sock is not None:
raise ValueError(
@@ -1540,6 +1552,9 @@ class BaseEventLoop(events.AbstractEventLoop):
raise ValueError(
'ssl_handshake_timeout is only meaningful with ssl')
+ if sock is not None:
+ _check_ssl_socket(sock)
+
transport, protocol = await self._create_connection_transport(
sock, protocol_factory, ssl, '', server_side=True,
ssl_handshake_timeout=ssl_handshake_timeout)
diff --git a/contrib/tools/python3/src/Lib/asyncio/futures.py b/contrib/tools/python3/src/Lib/asyncio/futures.py
index bed4da52fd..aaab09c28e 100644
--- a/contrib/tools/python3/src/Lib/asyncio/futures.py
+++ b/contrib/tools/python3/src/Lib/asyncio/futures.py
@@ -8,6 +8,7 @@ import concurrent.futures
import contextvars
import logging
import sys
+from types import GenericAlias
from . import base_futures
from . import events
@@ -106,8 +107,7 @@ class Future:
context['source_traceback'] = self._source_traceback
self._loop.call_exception_handler(context)
- def __class_getitem__(cls, type):
- return cls
+ __class_getitem__ = classmethod(GenericAlias)
@property
def _log_traceback(self):
diff --git a/contrib/tools/python3/src/Lib/asyncio/proactor_events.py b/contrib/tools/python3/src/Lib/asyncio/proactor_events.py
index b4cd414b82..e3f95cf21d 100644
--- a/contrib/tools/python3/src/Lib/asyncio/proactor_events.py
+++ b/contrib/tools/python3/src/Lib/asyncio/proactor_events.py
@@ -158,7 +158,7 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin,
# end then it may fail with ERROR_NETNAME_DELETED if we
# just close our end. First calling shutdown() seems to
# cure it, but maybe using DisconnectEx() would be better.
- if hasattr(self._sock, 'shutdown'):
+ if hasattr(self._sock, 'shutdown') and self._sock.fileno() != -1:
self._sock.shutdown(socket.SHUT_RDWR)
self._sock.close()
self._sock = None
@@ -450,7 +450,8 @@ class _ProactorWritePipeTransport(_ProactorBaseWritePipeTransport):
self.close()
-class _ProactorDatagramTransport(_ProactorBasePipeTransport):
+class _ProactorDatagramTransport(_ProactorBasePipeTransport,
+ transports.DatagramTransport):
max_size = 256 * 1024
def __init__(self, loop, sock, protocol, address=None,
waiter=None, extra=None):
diff --git a/contrib/tools/python3/src/Lib/asyncio/protocols.py b/contrib/tools/python3/src/Lib/asyncio/protocols.py
index 69fa43e8b6..09987b164c 100644
--- a/contrib/tools/python3/src/Lib/asyncio/protocols.py
+++ b/contrib/tools/python3/src/Lib/asyncio/protocols.py
@@ -109,10 +109,6 @@ class Protocol(BaseProtocol):
class BufferedProtocol(BaseProtocol):
"""Interface for stream protocol with manual buffer control.
- Important: this has been added to asyncio in Python 3.7
- *on a provisional basis*! Consider it as an experimental API that
- might be changed or removed in Python 3.8.
-
Event methods, such as `create_server` and `create_connection`,
accept factories that return protocols that implement this interface.
diff --git a/contrib/tools/python3/src/Lib/asyncio/queues.py b/contrib/tools/python3/src/Lib/asyncio/queues.py
index cd3f7c6a56..14ae87e0a2 100644
--- a/contrib/tools/python3/src/Lib/asyncio/queues.py
+++ b/contrib/tools/python3/src/Lib/asyncio/queues.py
@@ -3,6 +3,7 @@ __all__ = ('Queue', 'PriorityQueue', 'LifoQueue', 'QueueFull', 'QueueEmpty')
import collections
import heapq
import warnings
+from types import GenericAlias
from . import events
from . import locks
@@ -76,8 +77,7 @@ class Queue:
def __str__(self):
return f'<{type(self).__name__} {self._format()}>'
- def __class_getitem__(cls, type):
- return cls
+ __class_getitem__ = classmethod(GenericAlias)
def _format(self):
result = f'maxsize={self._maxsize!r}'
diff --git a/contrib/tools/python3/src/Lib/asyncio/selector_events.py b/contrib/tools/python3/src/Lib/asyncio/selector_events.py
index 59cb6b1bab..71080b8ad1 100644
--- a/contrib/tools/python3/src/Lib/asyncio/selector_events.py
+++ b/contrib/tools/python3/src/Lib/asyncio/selector_events.py
@@ -40,11 +40,6 @@ def _test_selector_event(selector, fd, event):
return bool(key.events & event)
-def _check_ssl_socket(sock):
- if ssl is not None and isinstance(sock, ssl.SSLSocket):
- raise TypeError("Socket cannot be of type SSLSocket")
-
-
class BaseSelectorEventLoop(base_events.BaseEventLoop):
"""Selector event loop.
@@ -357,7 +352,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
The maximum amount of data to be received at once is specified by
nbytes.
"""
- _check_ssl_socket(sock)
+ base_events._check_ssl_socket(sock)
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
try:
@@ -398,7 +393,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
The received data is written into *buf* (a writable buffer).
The return value is the number of bytes written.
"""
- _check_ssl_socket(sock)
+ base_events._check_ssl_socket(sock)
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
try:
@@ -439,7 +434,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
raised, and there is no way to determine how much data, if any, was
successfully processed by the receiving end of the connection.
"""
- _check_ssl_socket(sock)
+ base_events._check_ssl_socket(sock)
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
try:
@@ -488,13 +483,15 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
This method is a coroutine.
"""
- _check_ssl_socket(sock)
+ base_events._check_ssl_socket(sock)
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
if not hasattr(socket, 'AF_UNIX') or sock.family != socket.AF_UNIX:
resolved = await self._ensure_resolved(
- address, family=sock.family, proto=sock.proto, loop=self)
+ address, family=sock.family, type=sock.type, proto=sock.proto,
+ loop=self,
+ )
_, _, _, _, address = resolved[0]
fut = self.create_future()
@@ -553,7 +550,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
object usable to send and receive data on the connection, and address
is the address bound to the socket on the other end of the connection.
"""
- _check_ssl_socket(sock)
+ base_events._check_ssl_socket(sock)
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
fut = self.create_future()
diff --git a/contrib/tools/python3/src/Lib/asyncio/sslproto.py b/contrib/tools/python3/src/Lib/asyncio/sslproto.py
index cad25b2653..00fc16c014 100644
--- a/contrib/tools/python3/src/Lib/asyncio/sslproto.py
+++ b/contrib/tools/python3/src/Lib/asyncio/sslproto.py
@@ -367,6 +367,12 @@ class _SSLProtocolTransport(transports._FlowControlMixin,
"""Return the current size of the write buffer."""
return self._ssl_protocol._transport.get_write_buffer_size()
+ def get_write_buffer_limits(self):
+ """Get the high and low watermarks for write flow control.
+ Return a tuple (low, high) where low and high are
+ positive number of bytes."""
+ return self._ssl_protocol._transport.get_write_buffer_limits()
+
@property
def _protocol_paused(self):
# Required for sendfile fallback pause_writing/resume_writing logic
diff --git a/contrib/tools/python3/src/Lib/asyncio/tasks.py b/contrib/tools/python3/src/Lib/asyncio/tasks.py
index 27a3c8c5a8..53252f2079 100644
--- a/contrib/tools/python3/src/Lib/asyncio/tasks.py
+++ b/contrib/tools/python3/src/Lib/asyncio/tasks.py
@@ -17,6 +17,7 @@ import itertools
import types
import warnings
import weakref
+from types import GenericAlias
from . import base_tasks
from . import coroutines
@@ -147,8 +148,7 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
self._loop.call_exception_handler(context)
super().__del__()
- def __class_getitem__(cls, type):
- return cls
+ __class_getitem__ = classmethod(GenericAlias)
def _repr_info(self):
return base_tasks._task_repr_info(self)
@@ -768,7 +768,7 @@ def _gather(*coros_or_futures, loop=None, return_exceptions=False):
nonlocal nfinished
nfinished += 1
- if outer.done():
+ if outer is None or outer.done():
if not fut.cancelled():
# Mark exception retrieved.
fut.exception()
@@ -823,6 +823,7 @@ def _gather(*coros_or_futures, loop=None, return_exceptions=False):
children = []
nfuts = 0
nfinished = 0
+ outer = None # bpo-46672
for arg in coros_or_futures:
if arg not in arg_to_fut:
fut = ensure_future(arg, loop=loop)
diff --git a/contrib/tools/python3/src/Lib/asyncio/transports.py b/contrib/tools/python3/src/Lib/asyncio/transports.py
index 45e155c94c..73b1fa2de4 100644
--- a/contrib/tools/python3/src/Lib/asyncio/transports.py
+++ b/contrib/tools/python3/src/Lib/asyncio/transports.py
@@ -99,6 +99,12 @@ class WriteTransport(BaseTransport):
"""Return the current size of the write buffer."""
raise NotImplementedError
+ def get_write_buffer_limits(self):
+ """Get the high and low watermarks for write flow control.
+ Return a tuple (low, high) where low and high are
+ positive number of bytes."""
+ raise NotImplementedError
+
def write(self, data):
"""Write some data bytes to the transport.