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

Commit 11e0f2a

Browse files
committed
Merge pull request #226 from Lukasa/linting
Add linting to the project.
2 parents 08b0c98 + 13374a8 commit 11e0f2a

34 files changed

+485
-244
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ matrix:
2323

2424
install:
2525
- ".travis/install.sh"
26+
before_script: "flake8 --max-complexity 15 --exclude 'hyper/packages/*' hyper test"
27+
2628
script:
2729
- >
2830
if [[ "$TEST_RELEASE" == true ]]; then

.travis/install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ fi
4848

4949
pip install .
5050
pip install -r test_requirements.txt
51+
pip install flake8

hyper/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
A module for providing an abstraction layer over the differences between
77
HTTP/1.1 and HTTP/2.
88
"""
9-
__version__ = '0.5.0'
9+
import logging
1010

1111
from .common.connection import HTTPConnection
1212
from .http20.connection import HTTP20Connection
@@ -16,8 +16,10 @@
1616

1717
# Throw import errors on Python <2.7 and 3.0-3.2.
1818
import sys as _sys
19-
if _sys.version_info < (2,7) or (3,0) <= _sys.version_info < (3,3):
20-
raise ImportError("hyper only supports Python 2.7 and Python 3.3 or higher.")
19+
if _sys.version_info < (2, 7) or (3, 0) <= _sys.version_info < (3, 3):
20+
raise ImportError(
21+
"hyper only supports Python 2.7 and Python 3.3 or higher."
22+
)
2123

2224
__all__ = [
2325
HTTPConnection,
@@ -29,5 +31,6 @@
2931
]
3032

3133
# Set default logging handler.
32-
import logging
3334
logging.getLogger(__name__).addHandler(logging.NullHandler())
35+
36+
__version__ = '0.5.0'

hyper/cli.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,25 @@ def make_troubleshooting_argument(parser):
111111
help="Do HTTP/2 directly in plaintext: skip plaintext upgrade")
112112

113113

114-
def set_url_info(args):
115-
def split_host_and_port(hostname):
116-
if ':' in hostname:
117-
return to_host_port_tuple(hostname, default_port=443)
118-
return hostname, None
119-
120-
class UrlInfo(object):
121-
def __init__(self):
122-
self.fragment = None
123-
self.host = 'localhost'
124-
self.netloc = None
125-
self.path = '/'
126-
self.port = 443
127-
self.query = None
128-
self.scheme = 'https'
129-
self.secure = False
114+
def split_host_and_port(hostname):
115+
if ':' in hostname:
116+
return to_host_port_tuple(hostname, default_port=443)
117+
return hostname, None
118+
119+
120+
class UrlInfo(object):
121+
def __init__(self):
122+
self.fragment = None
123+
self.host = 'localhost'
124+
self.netloc = None
125+
self.path = '/'
126+
self.port = 443
127+
self.query = None
128+
self.scheme = 'https'
129+
self.secure = False
130130

131+
132+
def set_url_info(args):
131133
info = UrlInfo()
132134
_result = urlsplit(args._url)
133135
for attr in vars(info).keys():
@@ -167,9 +169,9 @@ def set_request_data(args):
167169
if i.key:
168170
headers[i.key] = i.value
169171
else:
170-
# when overriding a HTTP/2 special header there will be a leading
171-
# colon, which tricks the command line parser into thinking
172-
# the header is empty
172+
# when overriding a HTTP/2 special header there will be a
173+
# leading colon, which tricks the command line parser into
174+
# thinking the header is empty
173175
k, v = i.value.split(':', 1)
174176
headers[':' + k] = v
175177
elif i.sep == SEP_QUERY:

hyper/common/bufsocket.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import select
1414
from .exceptions import ConnectionResetError, LineTooLongError
1515

16+
1617
class BufferedSocket(object):
1718
"""
1819
A buffered socket wrapper.
@@ -137,8 +138,7 @@ def recv(self, amt):
137138
else:
138139
should_read = True
139140

140-
if ((self._remaining_capacity > self._bytes_in_buffer) and
141-
(should_read)):
141+
if (self._remaining_capacity > self._bytes_in_buffer and should_read):
142142
count = self._sck.recv_into(self._buffer_view[self._buffer_end:])
143143

144144
# The socket just got closed. We should throw an exception if we
@@ -172,7 +172,6 @@ def fill(self):
172172

173173
return
174174

175-
176175
def readline(self):
177176
"""
178177
Read up to a newline from the network and returns it. The implicit

hyper/common/connection.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ..http20.connection import HTTP20Connection
1111
from ..tls import H2_NPN_PROTOCOLS, H2C_PROTOCOL
1212

13+
1314
class HTTPConnection(object):
1415
"""
1516
An object representing a single HTTP connection to a server.
@@ -24,26 +25,27 @@ class HTTPConnection(object):
2425
:param host: The host to connect to. This may be an IP address or a
2526
hostname, and optionally may include a port: for example,
2627
``'http2bin.org'``, ``'http2bin.org:443'`` or ``'127.0.0.1'``.
27-
:param port: (optional) The port to connect to. If not provided and one also
28-
isn't provided in the ``host`` parameter, defaults to 80.
28+
:param port: (optional) The port to connect to. If not provided and one
29+
also isn't provided in the ``host`` parameter, defaults to 80.
2930
:param secure: (optional) Whether the request should use TLS.
3031
Defaults to ``False`` for most requests, but to ``True`` for any
3132
request issued to port 443.
3233
:param window_manager: (optional) The class to use to manage flow control
3334
windows. This needs to be a subclass of the
34-
:class:`BaseFlowControlManager <hyper.http20.window.BaseFlowControlManager>`.
35-
If not provided,
35+
:class:`BaseFlowControlManager
36+
<hyper.http20.window.BaseFlowControlManager>`. If not provided,
3637
:class:`FlowControlManager <hyper.http20.window.FlowControlManager>`
3738
will be used.
3839
:param enable_push: (optional) Whether the server is allowed to push
3940
resources to the client (see
4041
:meth:`get_pushes() <hyper.HTTP20Connection.get_pushes>`).
4142
:param ssl_context: (optional) A class with custom certificate settings.
4243
If not provided then hyper's default ``SSLContext`` is used instead.
43-
:param proxy_host: (optional) The proxy to connect to. This can be an IP address
44-
or a host name and may include a port.
44+
:param proxy_host: (optional) The proxy to connect to. This can be an IP
45+
address or a host name and may include a port.
4546
:param proxy_port: (optional) The proxy port to connect to. If not provided
46-
and one also isn't provided in the ``proxy`` parameter, defaults to 8080.
47+
and one also isn't provided in the ``proxy`` parameter, defaults to
48+
8080.
4749
"""
4850
def __init__(self,
4951
host,

hyper/common/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
66
Contains hyper's exceptions.
77
"""
8+
9+
810
class ChunkedDecodeError(Exception):
911
"""
1012
An error was encountered while decoding a chunked response.
@@ -43,6 +45,7 @@ class ConnectionResetError(Exception):
4345
A HTTP connection was unexpectedly reset.
4446
"""
4547

48+
4649
class TLSUpgrade(Exception):
4750
"""
4851
We upgraded to a new protocol in the NPN/ALPN handshake.
@@ -52,6 +55,7 @@ def __init__(self, negotiated, sock):
5255
self.negotiated = negotiated
5356
self.sock = sock
5457

58+
5559
class HTTPUpgrade(Exception):
5660
"""
5761
We upgraded to a new protocol via the HTTP Upgrade response.

hyper/common/util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from hyper.compat import unicode, bytes, imap
99
from ..packages.rfc3986.uri import URIReference
1010
from ..compat import is_py3
11-
import re
1211

1312

1413
def to_bytestring(element):

hyper/compat.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
2+
# flake8: noqa
23
"""
34
hyper/compat
4-
~~~~~~~~~
5+
~~~~~~~~~~~~
56
67
Normalizes the Python 2/3 API for internal use.
78
"""
@@ -21,6 +22,7 @@
2122
is_py3 = _ver[0] == 3
2223
is_py3_3 = is_py3 and _ver[1] == 3
2324

25+
2426
@contextmanager
2527
def ignore_missing():
2628
try:

hyper/contrib.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ def get_all(self, name, default=None):
150150
def getheaders(self, name):
151151
return self.get_all(name, [])
152152

153-
154153
response.raw._original_response = orig = FakeOriginalResponse(None)
155154
orig.version = 20
156155
orig.status = resp.status

0 commit comments

Comments
 (0)