]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Start using flake8, fix lint issues (#126)
authorSeth Michael Larson <sethmichaellarson@gmail.com>
Thu, 18 Jul 2019 10:41:50 +0000 (05:41 -0500)
committerTom Christie <tom@tomchristie.com>
Thu, 18 Jul 2019 10:41:50 +0000 (11:41 +0100)
22 files changed:
http3/__init__.py
http3/client.py
http3/concurrency.py
http3/config.py
http3/dispatch/connection.py
http3/dispatch/connection_pool.py
http3/dispatch/http11.py
http3/dispatch/http2.py
http3/interfaces.py
http3/status_codes.py
requirements.txt
scripts/lint
setup.py
tests/client/test_auth.py
tests/client/test_cookies.py
tests/client/test_redirects.py
tests/dispatch/test_connections.py
tests/dispatch/test_http2.py
tests/dispatch/test_threaded.py
tests/test_asgi.py
tests/test_multipart.py
tests/test_wsgi.py

index abc03caf58b2e9185957262bdbae1d2892bcc6f9..8de5276ec4e3faa5663c3a29e2ff025d422ba552 100644 (file)
@@ -60,3 +60,72 @@ from .models import (
     URLTypes,
 )
 from .status_codes import StatusCode, codes
+
+__all__ = [
+    "__description__",
+    "__title__",
+    "__version__",
+    "delete",
+    "get",
+    "head",
+    "options",
+    "patch",
+    "post",
+    "patch",
+    "put",
+    "request",
+    "AsyncClient",
+    "Client",
+    "AsyncioBackend",
+    "USER_AGENT",
+    "CertTypes",
+    "PoolLimits",
+    "SSLConfig",
+    "TimeoutConfig",
+    "VerifyTypes",
+    "HTTPConnection",
+    "ConnectionPool",
+    "ConnectTimeout",
+    "CookieConflict",
+    "DecodingError",
+    "InvalidURL",
+    "PoolTimeout",
+    "ProtocolError",
+    "ReadTimeout",
+    "RedirectBodyUnavailable",
+    "RedirectLoop",
+    "ResponseClosed",
+    "ResponseNotRead",
+    "StreamConsumed",
+    "Timeout",
+    "TooManyRedirects",
+    "WriteTimeout",
+    "AsyncDispatcher",
+    "BaseReader",
+    "BaseWriter",
+    "ConcurrencyBackend",
+    "Dispatcher",
+    "Protocol",
+    "URL",
+    "URLTypes",
+    "StatusCode",
+    "codes",
+    "TimeoutTypes",
+    "AsyncRequest",
+    "AsyncRequestData",
+    "AsyncResponse",
+    "AsyncResponseContent",
+    "AuthTypes",
+    "Cookies",
+    "CookieTypes",
+    "Headers",
+    "HeaderTypes",
+    "Origin",
+    "QueryParams",
+    "QueryParamTypes",
+    "Request",
+    "RequestData",
+    "Response",
+    "ResponseContent",
+    "RequestFiles",
+]
index 36569da23ceb395f618af5f00f814a4762ae5412..8e20cf2b97f617954154fd3d5ff032464cfdfeb1 100644 (file)
@@ -36,7 +36,6 @@ from .models import (
     Headers,
     HeaderTypes,
     QueryParamTypes,
-    Request,
     RequestData,
     RequestFiles,
     Response,
@@ -196,7 +195,8 @@ class BaseClient:
         if response.is_redirect:
 
             async def send_next() -> AsyncResponse:
-                nonlocal request, response, verify, cert, allow_redirects, timeout, history
+                nonlocal request, response, verify, cert
+                nonlocal allow_redirects, timeout, history
                 request = self.build_redirect_request(request, response)
                 response = await self.send_handling_redirects(
                     request,
index 928efcfe103e13e7ec8920fc8ea74e0eaef00d85..b8246b535036639275ae79ca2dd3b4384960d610 100644 (file)
@@ -14,7 +14,7 @@ import ssl
 import typing
 from types import TracebackType
 
-from .config import DEFAULT_TIMEOUT_CONFIG, PoolLimits, TimeoutConfig
+from .config import PoolLimits, TimeoutConfig
 from .exceptions import ConnectTimeout, PoolTimeout, ReadTimeout, WriteTimeout
 from .interfaces import (
     BaseBackgroundManager,
index 8ef3570861ad8158e8c76f02d42851e36d6d6181..fba47c9330669683b84b93733f58e8d8c69ebf6a 100644 (file)
@@ -76,6 +76,7 @@ class SSLConfig:
                     None, self.load_ssl_context_verify
                 )
 
+        assert self.ssl_context is not None
         return self.ssl_context
 
     def load_ssl_context_no_verify(self) -> ssl.SSLContext:
@@ -108,15 +109,15 @@ class SSLConfig:
         # Signal to server support for PHA in TLS 1.3. Raises an
         # AttributeError if only read-only access is implemented.
         try:
-            context.post_handshake_auth = True
-        except AttributeError:
+            context.post_handshake_auth = True  # type: ignore
+        except AttributeError:  # pragma: nocover
             pass
 
         # Disable using 'commonName' for SSLContext.check_hostname
         # when the 'subjectAltName' extension isn't available.
         try:
-            context.hostname_checks_common_name = False
-        except AttributeError:
+            context.hostname_checks_common_name = False  # type: ignore
+        except AttributeError:  # pragma: nocover
             pass
 
         if os.path.isfile(ca_bundle_path):
@@ -129,9 +130,11 @@ class SSLConfig:
                 context.load_cert_chain(certfile=self.cert)
             elif isinstance(self.cert, tuple) and len(self.cert) == 2:
                 context.load_cert_chain(certfile=self.cert[0], keyfile=self.cert[1])
-            else:
+            elif isinstance(self.cert, tuple) and len(self.cert) == 3:
                 context.load_cert_chain(
-                    certfile=self.cert[0], keyfile=self.cert[1], password=self.cert[2]
+                    certfile=self.cert[0],
+                    keyfile=self.cert[1],
+                    password=self.cert[2],  # type: ignore
                 )
 
         return context
@@ -202,7 +205,10 @@ class TimeoutConfig:
         class_name = self.__class__.__name__
         if len({self.connect_timeout, self.read_timeout, self.write_timeout}) == 1:
             return f"{class_name}(timeout={self.connect_timeout})"
-        return f"{class_name}(connect_timeout={self.connect_timeout}, read_timeout={self.read_timeout}, write_timeout={self.write_timeout})"
+        return (
+            f"{class_name}(connect_timeout={self.connect_timeout}, "
+            f"read_timeout={self.read_timeout}, write_timeout={self.write_timeout})"
+        )
 
 
 class PoolLimits:
@@ -231,7 +237,10 @@ class PoolLimits:
 
     def __repr__(self) -> str:
         class_name = self.__class__.__name__
-        return f"{class_name}(soft_limit={self.soft_limit}, hard_limit={self.hard_limit}, pool_timeout={self.pool_timeout})"
+        return (
+            f"{class_name}(soft_limit={self.soft_limit}, "
+            f"hard_limit={self.hard_limit}, pool_timeout={self.pool_timeout})"
+        )
 
 
 DEFAULT_SSL_CONFIG = SSLConfig(cert=None, verify=True)
index 68dea5c4d1aba5f538542bed061e6ae2e72bce89..b1400afdf4a7640beaf9b3c5dec0f6c1d1c3ef26 100644 (file)
@@ -1,12 +1,8 @@
 import functools
 import typing
 
-import h2.connection
-import h11
-
 from ..concurrency import AsyncioBackend
 from ..config import (
-    DEFAULT_SSL_CONFIG,
     DEFAULT_TIMEOUT_CONFIG,
     CertTypes,
     SSLConfig,
@@ -14,7 +10,6 @@ from ..config import (
     TimeoutTypes,
     VerifyTypes,
 )
-from ..exceptions import ConnectTimeout
 from ..interfaces import AsyncDispatcher, ConcurrencyBackend, Protocol
 from ..models import AsyncRequest, AsyncResponse, Origin
 from .http2 import HTTP2Connection
index d9794db49bbefda140bef4be7dfaccfcbde2b16f..0b827c128f0cedbddcdbe49f8124fe8d5ae6fca5 100644 (file)
@@ -2,7 +2,6 @@ import typing
 
 from ..concurrency import AsyncioBackend
 from ..config import (
-    DEFAULT_CA_BUNDLE_PATH,
     DEFAULT_POOL_LIMITS,
     DEFAULT_TIMEOUT_CONFIG,
     CertTypes,
@@ -10,8 +9,7 @@ from ..config import (
     TimeoutTypes,
     VerifyTypes,
 )
-from ..decoders import ACCEPT_ENCODING
-from ..exceptions import NotConnected, PoolTimeout
+from ..exceptions import NotConnected
 from ..interfaces import AsyncDispatcher, ConcurrencyBackend
 from ..models import AsyncRequest, AsyncResponse, Origin
 from .connection import HTTPConnection
index e4124412a6647f797df102a9fdeb651ab017a3fc..c23953562fbc981b6f2cee3c1f4ea0bd9793d09e 100644 (file)
@@ -3,8 +3,8 @@ import typing
 import h11
 
 from ..concurrency import TimeoutFlag
-from ..config import DEFAULT_TIMEOUT_CONFIG, TimeoutConfig, TimeoutTypes
-from ..exceptions import ConnectTimeout, NotConnected, ReadTimeout
+from ..config import TimeoutConfig, TimeoutTypes
+from ..exceptions import NotConnected
 from ..interfaces import BaseReader, BaseWriter, ConcurrencyBackend
 from ..models import AsyncRequest, AsyncResponse
 
@@ -71,7 +71,7 @@ class HTTP11Connection:
         event = h11.ConnectionClosed()
         try:
             self.h11_state.send(event)
-        except h11.LocalProtocolError as exc:  # pragma: no cover
+        except h11.LocalProtocolError:  # pragma: no cover
             # Premature client disconnect
             pass
         await self.writer.close()
index 3dd778d5a54d9b00a5fd7ba71218082e1838977c..35d487ad6b056dd16d45a883639bc2ef63cc327d 100644 (file)
@@ -5,8 +5,8 @@ import h2.connection
 import h2.events
 
 from ..concurrency import TimeoutFlag
-from ..config import DEFAULT_TIMEOUT_CONFIG, TimeoutConfig, TimeoutTypes
-from ..exceptions import ConnectTimeout, NotConnected, ReadTimeout
+from ..config import TimeoutConfig, TimeoutTypes
+from ..exceptions import NotConnected
 from ..interfaces import BaseReader, BaseWriter, ConcurrencyBackend
 from ..models import AsyncRequest, AsyncResponse
 
index 5d9b99c781bd5d973349c11d1c23fe25b0da4b81..02d11ce5b56d7b485983cfd665c95d6c0d4a1378 100644 (file)
@@ -5,11 +5,9 @@ from types import TracebackType
 
 from .config import CertTypes, PoolLimits, TimeoutConfig, TimeoutTypes, VerifyTypes
 from .models import (
-    URL,
     AsyncRequest,
     AsyncRequestData,
     AsyncResponse,
-    Headers,
     HeaderTypes,
     QueryParamTypes,
     Request,
index 1c547770685c710d9d5620b7652018162231a75e..e7b15dfc6ddf9b1d71e0845db8c19500b743fb53 100644 (file)
@@ -35,11 +35,16 @@ class StatusCode(IntEnum):
     @classmethod
     def is_redirect(cls, value: int) -> bool:
         return value in (
-            StatusCode.MOVED_PERMANENTLY,  # 301 (Cacheable redirect. Method may change to GET.)
-            StatusCode.FOUND,  # 302 (Uncacheable redirect. Method may change to GET.)
-            StatusCode.SEE_OTHER,  # 303 (Client should make a GET or HEAD request.)
-            StatusCode.TEMPORARY_REDIRECT,  # 307 (Equiv. 302, but retain method)
-            StatusCode.PERMANENT_REDIRECT,  # 308 (Equiv. 301, but retain method)
+            # 301 (Cacheable redirect. Method may change to GET.)
+            StatusCode.MOVED_PERMANENTLY,
+            # 302 (Uncacheable redirect. Method may change to GET.)
+            StatusCode.FOUND,
+            # 303 (Client should make a GET or HEAD request.)
+            StatusCode.SEE_OTHER,
+            # 307 (Equiv. 302, but retain method)
+            StatusCode.TEMPORARY_REDIRECT,
+            # 308 (Equiv. 301, but retain method)
+            StatusCode.PERMANENT_REDIRECT,
         )
 
     @classmethod
index 5e147046947be0c6abd7d84da25a127fcc7a98ee..13f45745f3bbd93e102dd1d947399c4c21d20da4 100644 (file)
@@ -16,6 +16,7 @@ mkdocs-material
 autoflake
 black
 cryptography
+flake8
 isort
 mypy
 pytest
index 89e1e93aad4196e8d415a469967e1844228c5e65..1c02eb6cd58c509740ba8d33336060cf4cdd8ca5 100755 (executable)
@@ -7,9 +7,10 @@ fi
 
 set -x
 
-${PREFIX}autoflake --in-place --recursive http3 tests
-${PREFIX}black http3 tests
-${PREFIX}isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --apply http3 tests
+${PREFIX}autoflake --in-place --recursive http3 tests setup.py
+${PREFIX}isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --apply http3 tests setup.py
+${PREFIX}black http3 tests setup.py
+${PREFIX}flake8 --max-line-length=88 --ignore=W503,E203 http3 tests setup.py
 ${PREFIX}mypy http3 --ignore-missing-imports --disallow-untyped-defs
 
 scripts/clean
index a6a33d0dc5ecc16e0f27404225b74d78049a1d4d..c2fe870780d7a0e7ffe645f646bd10464adc51ef 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -53,7 +53,7 @@ setup(
         "h11==0.8.*",
         "h2==3.*",
         "idna==2.*",
-        "rfc3986==1.*"
+        "rfc3986==1.*",
     ],
     classifiers=[
         "Development Status :: 3 - Alpha",
index 597aae7771b6408a3300fa7fdc855f1417d2c4b6..03c3e2dc29343e354c1cb007a015a5204cc659b3 100644 (file)
@@ -1,9 +1,6 @@
 import json
 
-import pytest
-
 from http3 import (
-    URL,
     AsyncDispatcher,
     AsyncRequest,
     AsyncResponse,
index f4f7ceb68ff44f6710a326afdd81848bd8b81837..77d8095ab6238f9cde64b3a3761169fc5e8d9e62 100644 (file)
@@ -1,10 +1,7 @@
 import json
 from http.cookiejar import Cookie, CookieJar
 
-import pytest
-
 from http3 import (
-    URL,
     AsyncDispatcher,
     AsyncRequest,
     AsyncResponse,
index 30967f3369a7aa253641c36fed437735a9d57215..8484af6ea325b3a3af248407bad0a340824d7bc1 100644 (file)
@@ -12,8 +12,6 @@ from http3 import (
     CertTypes,
     RedirectBodyUnavailable,
     RedirectLoop,
-    Request,
-    Response,
     TimeoutTypes,
     TooManyRedirects,
     VerifyTypes,
index 639ed91723782d06bfc901bd76507fa91b405954..f449e85945a21e1d56cee0937a2b1b048e31ddc1 100644 (file)
@@ -1,6 +1,6 @@
 import pytest
 
-from http3 import HTTPConnection, Request, SSLConfig
+from http3 import HTTPConnection
 
 
 @pytest.mark.asyncio
index 8da5b0d5cdbe24f1d8b6a221092f1d0968786bfe..574a0a1099565e304ec21ff66d6bd71dfbcd4127 100644 (file)
@@ -1,7 +1,5 @@
 import json
 
-import pytest
-
 from http3 import Client, Response
 
 from .utils import MockHTTP2Backend
index 04a9a2e66005996c5dad532e9f7f8ca0714875c9..a75190040c2bac2d3213f4d43d7966fb0b29905b 100644 (file)
@@ -1,7 +1,5 @@
 import json
 
-import pytest
-
 from http3 import (
     CertTypes,
     Client,
index 79318b9e4ab56783b9b8a450609a298e6ada24c8..3b7d1cc092e61e93d38aaaa27bfc7dd82b57d9af 100644 (file)
@@ -56,10 +56,10 @@ def test_asgi_upload():
 def test_asgi_exc():
     client = http3.Client(app=raise_exc)
     with pytest.raises(ValueError):
-        response = client.get("http://www.example.org/")
+        client.get("http://www.example.org/")
 
 
 def test_asgi_exc_after_response():
     client = http3.Client(app=raise_exc_after_response)
     with pytest.raises(ValueError):
-        response = client.get("http://www.example.org/")
+        client.get("http://www.example.org/")
index 50e1511b561d67d134805d2bf28e2b5b30a67585..fbccab769a662c0acfa2a370dc83590df1bac9f3 100644 (file)
@@ -1,8 +1,6 @@
 import cgi
 import io
 
-import pytest
-
 from http3 import (
     CertTypes,
     Client,
@@ -41,7 +39,8 @@ def test_multipart():
     pdict = {"boundary": boundary.encode("ascii"), "CONTENT-LENGTH": content_length}
     multipart = cgi.parse_multipart(io.BytesIO(response.content), pdict)
 
-    # Note that the expected return type for text fields appears to differs from 3.6 to 3.7+
+    # Note that the expected return type for text fields
+    # appears to differs from 3.6 to 3.7+
     assert multipart["text"] == ["abc"] or multipart["text"] == [b"abc"]
     assert multipart["file"] == [b"<file content>"]
 
@@ -62,6 +61,7 @@ def test_multipart_file_tuple():
     pdict = {"boundary": boundary.encode("ascii"), "CONTENT-LENGTH": content_length}
     multipart = cgi.parse_multipart(io.BytesIO(response.content), pdict)
 
-    # Note that the expected return type for text fields appears to differs from 3.6 to 3.7+
+    # Note that the expected return type for text fields
+    # appears to differs from 3.6 to 3.7+
     assert multipart["text"] == ["abc"] or multipart["text"] == [b"abc"]
     assert multipart["file"] == [b"<file content>"]
index 4a277c9a1db0d35aa294bbd4d51166b6a27a94f9..4e2a003c2b2321718cedb368aca0a971bacc350d 100644 (file)
@@ -61,7 +61,7 @@ def raise_exc(environ, start_response):
 
     try:
         raise ValueError()
-    except:
+    except ValueError:
         exc_info = sys.exc_info()
         start_response(status, response_headers, exc_info=exc_info)
 
@@ -92,4 +92,4 @@ def test_wsgi_upload_with_response_stream():
 def test_wsgi_exc():
     client = http3.Client(app=raise_exc)
     with pytest.raises(ValueError):
-        response = client.get("http://www.example.org/")
+        client.get("http://www.example.org/")