From 08e78417186c872e0c220525dabcf84609790259 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Tue, 28 Nov 2017 18:00:15 -0800 Subject: [PATCH] Fix import ordering --- daphne/cli.py | 10 +++++----- daphne/http_protocol.py | 12 +++++------- daphne/server.py | 10 ++++------ daphne/test_application.py | 2 +- daphne/twisted/plugins/fd_endpoint.py | 10 +++++----- daphne/utils.py | 3 ++- daphne/ws_protocol.py | 9 ++++----- setup.cfg | 9 +++++++++ tests/http_base.py | 4 ++-- tests/http_strategies.py | 7 ++----- tests/test_http_request.py | 2 +- tests/test_utils.py | 3 ++- 12 files changed, 42 insertions(+), 39 deletions(-) diff --git a/daphne/cli.py b/daphne/cli.py index 99e2454..1c51940 100755 --- a/daphne/cli.py +++ b/daphne/cli.py @@ -1,11 +1,11 @@ -import sys import argparse import logging -from .server import Server -from .endpoints import build_endpoint_description_strings -from .access import AccessLogGenerator -from .utils import import_by_path +import sys +from .access import AccessLogGenerator +from .endpoints import build_endpoint_description_strings +from .server import Server +from .utils import import_by_path logger = logging.getLogger(__name__) diff --git a/daphne/http_protocol.py b/daphne/http_protocol.py index 7f7fa89..078cfea 100755 --- a/daphne/http_protocol.py +++ b/daphne/http_protocol.py @@ -1,22 +1,20 @@ -from __future__ import unicode_literals - import logging import random -import six import string import time import traceback -from zope.interface import implementer - -from six.moves.urllib_parse import unquote, unquote_plus +import six from twisted.internet.defer import ensureDeferred from twisted.internet.interfaces import IProtocolNegotiationFactory from twisted.protocols.policies import ProtocolWrapper from twisted.web import http +from zope.interface import implementer + +from six.moves.urllib_parse import unquote, unquote_plus from .utils import parse_x_forwarded_for -from .ws_protocol import WebSocketProtocol, WebSocketFactory +from .ws_protocol import WebSocketFactory, WebSocketProtocol logger = logging.getLogger(__name__) diff --git a/daphne/server.py b/daphne/server.py index 23512fa..7f443c7 100755 --- a/daphne/server.py +++ b/daphne/server.py @@ -1,8 +1,6 @@ -from __future__ import unicode_literals - # This has to be done first as Twisted is import-order-sensitive with reactors -from twisted.internet import asyncioreactor -asyncioreactor.install() +from twisted.internet import asyncioreactor # isort:skip +asyncioreactor.install() # isort:skip import asyncio import collections @@ -12,9 +10,9 @@ import string import traceback import warnings -from twisted.internet import reactor, defer +from twisted.internet import defer, reactor from twisted.internet.endpoints import serverFromString -from twisted.logger import globalLogBeginner, STDLibLogObserver +from twisted.logger import STDLibLogObserver, globalLogBeginner from twisted.web import http from .http_protocol import HTTPFactory diff --git a/daphne/test_application.py b/daphne/test_application.py index cbd2bdb..a97ee58 100644 --- a/daphne/test_application.py +++ b/daphne/test_application.py @@ -1,8 +1,8 @@ -from concurrent.futures import CancelledError import logging import os import pickle import tempfile +from concurrent.futures import CancelledError class TestApplication: diff --git a/daphne/twisted/plugins/fd_endpoint.py b/daphne/twisted/plugins/fd_endpoint.py index 096e778..ff5a4c7 100644 --- a/daphne/twisted/plugins/fd_endpoint.py +++ b/daphne/twisted/plugins/fd_endpoint.py @@ -1,9 +1,9 @@ +import socket + +from twisted.internet import endpoints +from twisted.internet.interfaces import IStreamServerEndpointStringParser from twisted.plugin import IPlugin from zope.interface import implementer -from twisted.internet.interfaces import IStreamServerEndpointStringParser -from twisted.internet import endpoints - -import socket @implementer(IPlugin, IStreamServerEndpointStringParser) @@ -21,4 +21,4 @@ class _FDParser(object): return self._parseServer(reactor, *args, **kwargs) -parser = _FDParser() \ No newline at end of file +parser = _FDParser() diff --git a/daphne/utils.py b/daphne/utils.py index 7f0332b..450416e 100644 --- a/daphne/utils.py +++ b/daphne/utils.py @@ -1,5 +1,6 @@ -import sys import importlib +import sys + from twisted.web.http_headers import Headers diff --git a/daphne/ws_protocol.py b/daphne/ws_protocol.py index 36b38aa..1de218c 100755 --- a/daphne/ws_protocol.py +++ b/daphne/ws_protocol.py @@ -1,13 +1,12 @@ -from __future__ import unicode_literals - import logging -import six import time import traceback -from six.moves.urllib_parse import unquote, urlencode + +import six +from autobahn.twisted.websocket import ConnectionDeny, WebSocketServerFactory, WebSocketServerProtocol from twisted.internet import defer -from autobahn.twisted.websocket import WebSocketServerProtocol, WebSocketServerFactory, ConnectionDeny +from six.moves.urllib_parse import unquote, urlencode from .utils import parse_x_forwarded_for diff --git a/setup.cfg b/setup.cfg index d0ede1c..34d6b8a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,3 +3,12 @@ universal=1 [tool:pytest] addopts = tests/ + +[isort] +line_length = 120 +multi_line_output = 3 + +[flake8] +exclude = venv/*,tox/*,docs/*,testproject/*,js_client/* +ignore = E123,E128,E402,W503,E731,W601 +max-line-length = 120 diff --git a/tests/http_base.py b/tests/http_base.py index 74be5eb..4d21b9e 100644 --- a/tests/http_base.py +++ b/tests/http_base.py @@ -1,10 +1,10 @@ -from http.client import HTTPConnection -from urllib import parse import socket import struct import subprocess import time import unittest +from http.client import HTTPConnection +from urllib import parse from daphne.test_application import TestApplication diff --git a/tests/http_strategies.py b/tests/http_strategies.py index e4b3d9c..4789c05 100644 --- a/tests/http_strategies.py +++ b/tests/http_strategies.py @@ -1,12 +1,9 @@ -""" -Assorted Hypothesis strategies useful for generating HTTP requests and responses -""" -from __future__ import unicode_literals -from six.moves.urllib import parse import string from hypothesis import strategies +from six.moves.urllib import parse + HTTP_METHODS = ["OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE", "TRACE", "CONNECT"] # Unicode characters of the "Letter" category diff --git a/tests/test_http_request.py b/tests/test_http_request.py index 6768e9e..924519c 100644 --- a/tests/test_http_request.py +++ b/tests/test_http_request.py @@ -3,7 +3,7 @@ import collections from urllib import parse -from hypothesis import given, assume, settings +from hypothesis import assume, given, settings import http_strategies from http_base import DaphneTestCase diff --git a/tests/test_utils.py b/tests/test_utils.py index 5f0b364..786b8c9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,8 +1,9 @@ # coding: utf8 -from twisted.web.http_headers import Headers from unittest import TestCase +from twisted.web.http_headers import Headers + from daphne.utils import parse_x_forwarded_for