summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2017-12-20 18:24:43 (GMT)
committerGitHub <noreply@github.com>2017-12-20 18:24:43 (GMT)
commit51eb1c6b9c0b382dfd6e0428eacff0c7891a6fc3 (patch)
treec9043b4a9f959fe562a695ec35cb0718101110e9 /Lib/asyncio
parenta7a751dd7b08a5bb6cb399c1b2a6ca7b24aba51d (diff)
downloadcpython-51eb1c6b9c0b382dfd6e0428eacff0c7891a6fc3.zip
cpython-51eb1c6b9c0b382dfd6e0428eacff0c7891a6fc3.tar.gz
cpython-51eb1c6b9c0b382dfd6e0428eacff0c7891a6fc3.tar.bz2
bpo-29970: Make ssh_handshake_timeout None by default (#4939)
* Make ssh_handshake_timeout None by default. * Raise ValueError if ssl_handshake_timeout is used without ssl. * Raise ValueError if ssl_handshake_timeout is not positive.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/base_events.py24
-rw-r--r--Lib/asyncio/events.py9
-rw-r--r--Lib/asyncio/proactor_events.py4
-rw-r--r--Lib/asyncio/sslproto.py9
-rw-r--r--Lib/asyncio/unix_events.py11
5 files changed, 41 insertions, 16 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 6246f4e..2ab8a76 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -29,7 +29,6 @@ import sys
import warnings
import weakref
-from . import constants
from . import coroutines
from . import events
from . import futures
@@ -280,7 +279,7 @@ class BaseEventLoop(events.AbstractEventLoop):
self, rawsock, protocol, sslcontext, waiter=None,
*, server_side=False, server_hostname=None,
extra=None, server=None,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
"""Create SSL transport."""
raise NotImplementedError
@@ -643,7 +642,7 @@ class BaseEventLoop(events.AbstractEventLoop):
*, ssl=None, family=0,
proto=0, flags=0, sock=None,
local_addr=None, server_hostname=None,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
"""Connect to a TCP server.
Create a streaming transport connection to a given Internet host and
@@ -674,6 +673,10 @@ class BaseEventLoop(events.AbstractEventLoop):
'when using ssl without a host')
server_hostname = host
+ if ssl_handshake_timeout is not None and not ssl:
+ raise ValueError(
+ 'ssl_handshake_timeout is only meaningful with ssl')
+
if host is not None or port is not None:
if sock is not None:
raise ValueError(
@@ -769,7 +772,7 @@ class BaseEventLoop(events.AbstractEventLoop):
async def _create_connection_transport(
self, sock, protocol_factory, ssl,
server_hostname, server_side=False,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
sock.setblocking(False)
@@ -948,7 +951,7 @@ class BaseEventLoop(events.AbstractEventLoop):
ssl=None,
reuse_address=None,
reuse_port=None,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
"""Create a TCP server.
The host parameter can be a string, in that case the TCP server is
@@ -966,6 +969,11 @@ class BaseEventLoop(events.AbstractEventLoop):
"""
if isinstance(ssl, bool):
raise TypeError('ssl argument must be an SSLContext or None')
+
+ if ssl_handshake_timeout is not None and ssl is None:
+ raise ValueError(
+ 'ssl_handshake_timeout is only meaningful with ssl')
+
if host is not None or port is not None:
if sock is not None:
raise ValueError(
@@ -1046,7 +1054,7 @@ class BaseEventLoop(events.AbstractEventLoop):
async def connect_accepted_socket(
self, protocol_factory, sock,
*, ssl=None,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
"""Handle an accepted connection.
This is used by servers that accept connections outside of
@@ -1058,6 +1066,10 @@ class BaseEventLoop(events.AbstractEventLoop):
if sock.type != socket.SOCK_STREAM:
raise ValueError(f'A Stream Socket was expected, got {sock!r}')
+ if ssl_handshake_timeout is not None and not ssl:
+ raise ValueError(
+ 'ssl_handshake_timeout is only meaningful with ssl')
+
transport, protocol = await self._create_connection_transport(
sock, protocol_factory, ssl, '', server_side=True,
ssl_handshake_timeout=ssl_handshake_timeout)
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index c9033c0..3a5dbad 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -17,7 +17,6 @@ import subprocess
import sys
import threading
-from . import constants
from . import format_helpers
@@ -255,7 +254,7 @@ class AbstractEventLoop:
*, ssl=None, family=0, proto=0,
flags=0, sock=None, local_addr=None,
server_hostname=None,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
raise NotImplementedError
async def create_server(
@@ -263,7 +262,7 @@ class AbstractEventLoop:
*, family=socket.AF_UNSPEC,
flags=socket.AI_PASSIVE, sock=None, backlog=100,
ssl=None, reuse_address=None, reuse_port=None,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
"""A coroutine which creates a TCP server bound to host and port.
The return value is a Server object which can be used to stop
@@ -310,13 +309,13 @@ class AbstractEventLoop:
self, protocol_factory, path=None, *,
ssl=None, sock=None,
server_hostname=None,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
raise NotImplementedError
async def create_unix_server(
self, protocol_factory, path=None, *,
sock=None, backlog=100, ssl=None,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
"""A coroutine which creates a UNIX Domain Socket server.
The return value is a Server object, which can be used to stop
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
index bc319b0..2661cdd 100644
--- a/Lib/asyncio/proactor_events.py
+++ b/Lib/asyncio/proactor_events.py
@@ -393,7 +393,7 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
self, rawsock, protocol, sslcontext, waiter=None,
*, server_side=False, server_hostname=None,
extra=None, server=None,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
ssl_protocol = sslproto.SSLProtocol(
self, protocol, sslcontext, waiter,
server_side, server_hostname,
@@ -491,7 +491,7 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
def _start_serving(self, protocol_factory, sock,
sslcontext=None, server=None, backlog=100,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
def loop(f=None):
try:
diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py
index 8bcc6cc..2d377c4 100644
--- a/Lib/asyncio/sslproto.py
+++ b/Lib/asyncio/sslproto.py
@@ -402,10 +402,17 @@ class SSLProtocol(protocols.Protocol):
def __init__(self, loop, app_protocol, sslcontext, waiter,
server_side=False, server_hostname=None,
call_connection_made=True,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
if ssl is None:
raise RuntimeError('stdlib ssl module not available')
+ if ssl_handshake_timeout is None:
+ ssl_handshake_timeout = constants.SSL_HANDSHAKE_TIMEOUT
+ elif ssl_handshake_timeout <= 0:
+ raise ValueError(
+ f"ssl_handshake_timeout should be a positive number, "
+ f"got {ssl_handshake_timeout}")
+
if not sslcontext:
sslcontext = _create_transport_context(
server_side, server_hostname)
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index e234458..69c719c 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -196,7 +196,7 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
self, protocol_factory, path=None, *,
ssl=None, sock=None,
server_hostname=None,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
assert server_hostname is None or isinstance(server_hostname, str)
if ssl:
if server_hostname is None:
@@ -205,6 +205,9 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
else:
if server_hostname is not None:
raise ValueError('server_hostname is only meaningful with ssl')
+ if ssl_handshake_timeout is not None:
+ raise ValueError(
+ 'ssl_handshake_timeout is only meaningful with ssl')
if path is not None:
if sock is not None:
@@ -237,10 +240,14 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
async def create_unix_server(
self, protocol_factory, path=None, *,
sock=None, backlog=100, ssl=None,
- ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
+ ssl_handshake_timeout=None):
if isinstance(ssl, bool):
raise TypeError('ssl argument must be an SSLContext or None')
+ if ssl_handshake_timeout is not None and not ssl:
+ raise ValueError(
+ 'ssl_handshake_timeout is only meaningful with ssl')
+
if path is not None:
if sock is not None:
raise ValueError(