Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 532b202

Browse files
committed
Fixup linting errors in http20/connection.py.
1 parent ea867bf commit 532b202

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

hyper/http20/connection.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@
1919
from .stream import Stream
2020
from .response import HTTP20Response, HTTP20Push
2121
from .window import FlowControlManager
22-
from .exceptions import ConnectionError, ProtocolError
22+
from .exceptions import ConnectionError
2323
from . import errors
2424

2525
import errno
2626
import logging
2727
import socket
28+
import time
2829

2930
log = logging.getLogger(__name__)
3031

3132
DEFAULT_WINDOW_SIZE = 65535
3233

34+
TRANSIENT_SSL_ERRORS = (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE)
35+
3336

3437
class HTTP20Connection(object):
3538
"""
@@ -44,30 +47,31 @@ class HTTP20Connection(object):
4447
:param host: The host to connect to. This may be an IP address or a
4548
hostname, and optionally may include a port: for example,
4649
``'http2bin.org'``, ``'http2bin.org:443'`` or ``'127.0.0.1'``.
47-
:param port: (optional) The port to connect to. If not provided and one also
48-
isn't provided in the ``host`` parameter, defaults to 443.
50+
:param port: (optional) The port to connect to. If not provided and one
51+
also isn't provided in the ``host`` parameter, defaults to 443.
4952
:param secure: (optional) Whether the request should use TLS. Defaults to
5053
``False`` for most requests, but to ``True`` for any request issued to
5154
port 443.
5255
:param window_manager: (optional) The class to use to manage flow control
5356
windows. This needs to be a subclass of the
54-
:class:`BaseFlowControlManager <hyper.http20.window.BaseFlowControlManager>`.
55-
If not provided,
57+
:class:`BaseFlowControlManager
58+
<hyper.http20.window.BaseFlowControlManager>`. If not provided,
5659
:class:`FlowControlManager <hyper.http20.window.FlowControlManager>`
5760
will be used.
5861
:param enable_push: (optional) Whether the server is allowed to push
5962
resources to the client (see
6063
:meth:`get_pushes() <hyper.HTTP20Connection.get_pushes>`).
6164
:param ssl_context: (optional) A class with custom certificate settings.
6265
If not provided then hyper's default ``SSLContext`` is used instead.
63-
:param proxy_host: (optional) The proxy to connect to. This can be an IP address
64-
or a host name and may include a port.
66+
:param proxy_host: (optional) The proxy to connect to. This can be an IP
67+
address or a host name and may include a port.
6568
:param proxy_port: (optional) The proxy port to connect to. If not provided
66-
and one also isn't provided in the ``proxy`` parameter, defaults to 8080.
69+
and one also isn't provided in the ``proxy`` parameter, defaults to
70+
8080.
6771
"""
68-
def __init__(self, host, port=None, secure=None, window_manager=None, enable_push=False,
69-
ssl_context=None, proxy_host=None, proxy_port=None,
70-
force_proto=None, **kwargs):
72+
def __init__(self, host, port=None, secure=None, window_manager=None,
73+
enable_push=False, ssl_context=None, proxy_host=None,
74+
proxy_port=None, force_proto=None, **kwargs):
7175
"""
7276
Creates an HTTP/2 connection to a specific server.
7377
"""
@@ -89,7 +93,9 @@ def __init__(self, host, port=None, secure=None, window_manager=None, enable_pus
8993
# Setup proxy details if applicable.
9094
if proxy_host:
9195
if proxy_port is None:
92-
self.proxy_host, self.proxy_port = to_host_port_tuple(proxy_host, default_port=8080)
96+
self.proxy_host, self.proxy_port = to_host_port_tuple(
97+
proxy_host, default_port=8080
98+
)
9399
else:
94100
self.proxy_host, self.proxy_port = proxy_host, proxy_port
95101
else:
@@ -241,7 +247,7 @@ def connect(self):
241247
sock = socket.create_connection((host, port))
242248

243249
if self.secure:
244-
assert not self.proxy_host, "Using a proxy with HTTPS not yet supported."
250+
assert not self.proxy_host, "Proxy with HTTPS not supported."
245251
sock, proto = wrap_socket(sock, host, self.ssl_context,
246252
force_proto=self.force_proto)
247253
else:
@@ -426,7 +432,7 @@ def _send_cb(self, data, tolerate_peer_gone=False):
426432
self._sock.sendall(data)
427433
except socket.error as e:
428434
if (not tolerate_peer_gone or
429-
e.errno not in (errno.EPIPE, errno.ECONNRESET)):
435+
e.errno not in (errno.EPIPE, errno.ECONNRESET)):
430436
raise
431437

432438
def _adjust_receive_window(self, frame_len):
@@ -535,14 +541,14 @@ def _recv_cb(self):
535541
except ssl.SSLError as e: # pragma: no cover
536542
# these are transient errors that can occur while reading from
537543
# ssl connections.
538-
if e.args[0] in (ssl.SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE):
544+
if e.args[0] in TRANSIENT_SSL_ERRORS:
539545
continue
540546
else:
541547
raise
542548
except socket.error as e: # pragma: no cover
543549
if e.errno in (errno.EINTR, errno.EAGAIN):
544550
# if 'interrupted' or 'try again', continue
545-
sleep(retry_wait)
551+
time.sleep(retry_wait)
546552
continue
547553
elif e.errno == errno.ECONNRESET:
548554
break

0 commit comments

Comments
 (0)