summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2020-08-15 21:07:51 -0700
committerBert JW Regeer <bertjw@regeer.org>2020-08-15 21:07:51 -0700
commit1b4bcce97cceaae588b5508d42308f13be926ce2 (patch)
tree5c3b51411d12cb29a672ae817c2602805b8b5041
parent2ed8a2b60ca7dd3f7b0a3cb4ce1d104ee52d0c58 (diff)
downloadwaitress-1b4bcce97cceaae588b5508d42308f13be926ce2.tar.gz
Add isort to the project
-rw-r--r--pyproject.toml15
-rw-r--r--src/waitress/__init__.py3
-rw-r--r--src/waitress/adjustments.py6
-rw-r--r--src/waitress/channel.py13
-rw-r--r--src/waitress/compat.py9
-rw-r--r--src/waitress/parser.py3
-rw-r--r--src/waitress/proxy_headers.py3
-rw-r--r--src/waitress/server.py5
-rw-r--r--src/waitress/task.py2
-rw-r--r--src/waitress/trigger.py2
-rw-r--r--src/waitress/wasyncore.py36
-rw-r--r--tests/fixtureapps/getline.py4
-rw-r--r--tests/test_buffers.py2
-rw-r--r--tests/test_channel.py2
-rw-r--r--tests/test_functional.py1
-rw-r--r--tests/test_parser.py4
-rw-r--r--tests/test_runner.py4
-rw-r--r--tests/test_server.py4
-rw-r--r--tests/test_task.py2
-rw-r--r--tests/test_trigger.py2
-rw-r--r--tests/test_utilities.py7
-rw-r--r--tests/test_wasyncore.py17
-rw-r--r--tox.ini13
23 files changed, 81 insertions, 78 deletions
diff --git a/pyproject.toml b/pyproject.toml
index 1bc058b..b68b905 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -10,3 +10,18 @@ exclude = '''
| .tox
)/
'''
+
+ # This next section only exists for people that have their editors
+# automatically call isort, black already sorts entries on its own when run.
+[tool.isort]
+profile = "black"
+multi_line_output = 3
+src_paths = ["src", "tests"]
+skip_glob = ["docs/*"]
+include_trailing_comma = true
+force_grid_wrap = false
+combine_as_imports = true
+line_length = 88
+force_sort_within_sections = true
+default_section = "THIRDPARTY"
+known_first_party = "waitress"
diff --git a/src/waitress/__init__.py b/src/waitress/__init__.py
index e6e5911..bbb99da 100644
--- a/src/waitress/__init__.py
+++ b/src/waitress/__init__.py
@@ -1,6 +1,7 @@
-from waitress.server import create_server
import logging
+from waitress.server import create_server
+
def serve(app, **kw):
_server = kw.pop("_server", create_server) # test shim
diff --git a/src/waitress/adjustments.py b/src/waitress/adjustments.py
index 6851a7c..f121b6e 100644
--- a/src/waitress/adjustments.py
+++ b/src/waitress/adjustments.py
@@ -17,12 +17,8 @@ import getopt
import socket
import warnings
+from .compat import HAS_IPV6, WIN, string_types
from .proxy_headers import PROXY_HEADERS
-from .compat import (
- WIN,
- string_types,
- HAS_IPV6,
-)
truthy = frozenset(("t", "true", "y", "yes", "on", "1"))
diff --git a/src/waitress/channel.py b/src/waitress/channel.py
index d91d0a1..7332e40 100644
--- a/src/waitress/channel.py
+++ b/src/waitress/channel.py
@@ -16,18 +16,9 @@ import threading
import time
import traceback
-from waitress.buffers import (
- OverflowableBuffer,
- ReadOnlyFileBasedBuffer,
-)
-
+from waitress.buffers import OverflowableBuffer, ReadOnlyFileBasedBuffer
from waitress.parser import HTTPRequestParser
-
-from waitress.task import (
- ErrorTask,
- WSGITask,
-)
-
+from waitress.task import ErrorTask, WSGITask
from waitress.utilities import InternalServerError
from . import wasyncore
diff --git a/src/waitress/compat.py b/src/waitress/compat.py
index aaf7a78..7c2630c 100644
--- a/src/waitress/compat.py
+++ b/src/waitress/compat.py
@@ -1,3 +1,6 @@
+import _thread as thread
+from http import client as httplib
+from io import StringIO as NativeIO
import os
import platform
@@ -5,13 +8,9 @@ import platform
# Python on Windows may not define IPPROTO_IPV6 in socket.
import socket
import sys
-import warnings
-from http import client as httplib
-from io import StringIO as NativeIO
from urllib import parse as urlparse
from urllib.parse import unquote_to_bytes
-
-import _thread as thread
+import warnings
# True if we are running on Windows
WIN = platform.system() == "Windows"
diff --git a/src/waitress/parser.py b/src/waitress/parser.py
index c2789eb..4530b23 100644
--- a/src/waitress/parser.py
+++ b/src/waitress/parser.py
@@ -16,8 +16,8 @@
This server uses asyncore to accept connections and do initial
processing but threads to do work.
"""
-import re
from io import BytesIO
+import re
from waitress.buffers import OverflowableBuffer
from waitress.compat import tostr, unquote_bytes_to_wsgi, urlparse
@@ -29,6 +29,7 @@ from waitress.utilities import (
ServerNotImplemented,
find_double_newline,
)
+
from .rfc7230 import HEADER_FIELD
diff --git a/src/waitress/proxy_headers.py b/src/waitress/proxy_headers.py
index d411da0..13cb2ed 100644
--- a/src/waitress/proxy_headers.py
+++ b/src/waitress/proxy_headers.py
@@ -1,7 +1,6 @@
from collections import namedtuple
-from .utilities import logger, undquote, BadRequest
-
+from .utilities import BadRequest, logger, undquote
PROXY_HEADERS = frozenset(
{
diff --git a/src/waitress/server.py b/src/waitress/server.py
index 7ab33d7..06bb957 100644
--- a/src/waitress/server.py
+++ b/src/waitress/server.py
@@ -20,13 +20,10 @@ import time
from waitress import trigger
from waitress.adjustments import Adjustments
from waitress.channel import HTTPChannel
+from waitress.compat import IPPROTO_IPV6, IPV6_V6ONLY
from waitress.task import ThreadedTaskDispatcher
from waitress.utilities import cleanup_unix_socket
-from waitress.compat import (
- IPPROTO_IPV6,
- IPV6_V6ONLY,
-)
from . import wasyncore
from .proxy_headers import proxy_headers_middleware
diff --git a/src/waitress/task.py b/src/waitress/task.py
index 604bc8e..b82109f 100644
--- a/src/waitress/task.py
+++ b/src/waitress/task.py
@@ -12,11 +12,11 @@
#
##############################################################################
+from collections import deque
import socket
import sys
import threading
import time
-from collections import deque
from .buffers import ReadOnlyFileBasedBuffer
from .compat import tobytes
diff --git a/src/waitress/trigger.py b/src/waitress/trigger.py
index 09c291e..24c4d0d 100644
--- a/src/waitress/trigger.py
+++ b/src/waitress/trigger.py
@@ -12,9 +12,9 @@
#
##############################################################################
+import errno
import os
import socket
-import errno
import threading
from . import wasyncore
diff --git a/src/waitress/wasyncore.py b/src/waitress/wasyncore.py
index debe0e4..9a68c51 100644
--- a/src/waitress/wasyncore.py
+++ b/src/waitress/wasyncore.py
@@ -51,33 +51,31 @@ in the stdlib will be dropped soon. It is neither a copy of the 2.7 asyncore
nor the 3.X asyncore; it is a version compatible with either 2.7 or 3.X.
"""
-from . import compat
-from . import utilities
-
-import logging
-import select
-import socket
-import sys
-import time
-import warnings
-
-import os
from errno import (
+ EAGAIN,
EALREADY,
- EINPROGRESS,
- EWOULDBLOCK,
+ EBADF,
+ ECONNABORTED,
ECONNRESET,
+ EINPROGRESS,
+ EINTR,
EINVAL,
- ENOTCONN,
- ESHUTDOWN,
EISCONN,
- EBADF,
- ECONNABORTED,
+ ENOTCONN,
EPIPE,
- EAGAIN,
- EINTR,
+ ESHUTDOWN,
+ EWOULDBLOCK,
errorcode,
)
+import logging
+import os
+import select
+import socket
+import sys
+import time
+import warnings
+
+from . import compat, utilities
_DISCONNECTED = frozenset({ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE, EBADF})
diff --git a/tests/fixtureapps/getline.py b/tests/fixtureapps/getline.py
index 5e0ad3a..bb5b39c 100644
--- a/tests/fixtureapps/getline.py
+++ b/tests/fixtureapps/getline.py
@@ -2,9 +2,9 @@ import sys
if __name__ == "__main__":
try:
- from urllib.request import urlopen, URLError
+ from urllib.request import URLError, urlopen
except ImportError:
- from urllib2 import urlopen, URLError
+ from urllib2 import URLError, urlopen
url = sys.argv[1]
headers = {"Content-Type": "text/plain; charset=utf-8"}
diff --git a/tests/test_buffers.py b/tests/test_buffers.py
index 029acfc..01cdc2d 100644
--- a/tests/test_buffers.py
+++ b/tests/test_buffers.py
@@ -1,5 +1,5 @@
-import unittest
import io
+import unittest
class TestFileBasedBuffer(unittest.TestCase):
diff --git a/tests/test_channel.py b/tests/test_channel.py
index 4d8aa23..df3d450 100644
--- a/tests/test_channel.py
+++ b/tests/test_channel.py
@@ -1,5 +1,5 @@
-import unittest
import io
+import unittest
class TestHTTPChannel(unittest.TestCase):
diff --git a/tests/test_functional.py b/tests/test_functional.py
index add50f3..9d94b8e 100644
--- a/tests/test_functional.py
+++ b/tests/test_functional.py
@@ -9,6 +9,7 @@ import subprocess
import sys
import time
import unittest
+
from waitress import server
from waitress.compat import httplib, tobytes
from waitress.utilities import cleanup_unix_socket
diff --git a/tests/test_parser.py b/tests/test_parser.py
index ae0b263..e0e4d25 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -20,8 +20,8 @@ from waitress.compat import text_, tobytes
class TestHTTPRequestParser(unittest.TestCase):
def setUp(self):
- from waitress.parser import HTTPRequestParser
from waitress.adjustments import Adjustments
+ from waitress.parser import HTTPRequestParser
my_adj = Adjustments()
self.parser = HTTPRequestParser(my_adj)
@@ -595,8 +595,8 @@ class Test_crack_first_line(unittest.TestCase):
class TestHTTPRequestParserIntegration(unittest.TestCase):
def setUp(self):
- from waitress.parser import HTTPRequestParser
from waitress.adjustments import Adjustments
+ from waitress.parser import HTTPRequestParser
my_adj = Adjustments()
self.parser = HTTPRequestParser(my_adj)
diff --git a/tests/test_runner.py b/tests/test_runner.py
index e53018b..e77d103 100644
--- a/tests/test_runner.py
+++ b/tests/test_runner.py
@@ -119,7 +119,7 @@ class Test_run(unittest.TestCase):
)
def test_simple_call(self):
- import tests.fixtureapps.runner as _apps
+ from tests.fixtureapps import runner as _apps
def check_server(app, **kw):
self.assertIs(app, _apps.app)
@@ -133,7 +133,7 @@ class Test_run(unittest.TestCase):
self.assertEqual(runner.run(argv=argv, _serve=check_server), 0)
def test_returned_app(self):
- import tests.fixtureapps.runner as _apps
+ from tests.fixtureapps import runner as _apps
def check_server(app, **kw):
self.assertIs(app, _apps.app)
diff --git a/tests/test_server.py b/tests/test_server.py
index 7242aa7..05f6b4e 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -274,8 +274,8 @@ class TestWSGIServer(unittest.TestCase):
self.assertEqual(zombie.will_close, True)
def test_backward_compatibility(self):
- from waitress.server import WSGIServer, TcpWSGIServer
from waitress.adjustments import Adjustments
+ from waitress.server import TcpWSGIServer, WSGIServer
self.assertTrue(WSGIServer is TcpWSGIServer)
self.inst = WSGIServer(None, _start=False, port=1234)
@@ -411,8 +411,8 @@ if hasattr(socket, "AF_UNIX"):
def test_create_with_unix_socket(self):
from waitress.server import (
- MultiSocketServer,
BaseWSGIServer,
+ MultiSocketServer,
TcpWSGIServer,
UnixWSGIServer,
)
diff --git a/tests/test_task.py b/tests/test_task.py
index 6848db2..0965bf5 100644
--- a/tests/test_task.py
+++ b/tests/test_task.py
@@ -1,5 +1,5 @@
-import unittest
import io
+import unittest
class TestThreadedTaskDispatcher(unittest.TestCase):
diff --git a/tests/test_trigger.py b/tests/test_trigger.py
index af740f6..265679a 100644
--- a/tests/test_trigger.py
+++ b/tests/test_trigger.py
@@ -1,6 +1,6 @@
-import unittest
import os
import sys
+import unittest
if not sys.platform.startswith("win"):
diff --git a/tests/test_utilities.py b/tests/test_utilities.py
index 15cd24f..ea08477 100644
--- a/tests/test_utilities.py
+++ b/tests/test_utilities.py
@@ -39,16 +39,17 @@ class Test_parse_http_date(unittest.TestCase):
class Test_build_http_date(unittest.TestCase):
def test_rountdrip(self):
- from waitress.utilities import build_http_date, parse_http_date
from time import time
+ from waitress.utilities import build_http_date, parse_http_date
+
t = int(time())
self.assertEqual(t, parse_http_date(build_http_date(t)))
class Test_unpack_rfc850(unittest.TestCase):
def _callFUT(self, val):
- from waitress.utilities import unpack_rfc850, rfc850_reg
+ from waitress.utilities import rfc850_reg, unpack_rfc850
return unpack_rfc850(rfc850_reg.match(val.lower()))
@@ -60,7 +61,7 @@ class Test_unpack_rfc850(unittest.TestCase):
class Test_unpack_rfc_822(unittest.TestCase):
def _callFUT(self, val):
- from waitress.utilities import unpack_rfc822, rfc822_reg
+ from waitress.utilities import rfc822_reg, unpack_rfc822
return unpack_rfc822(rfc822_reg.match(val.lower()))
diff --git a/tests/test_wasyncore.py b/tests/test_wasyncore.py
index a7713a8..a7e2878 100644
--- a/tests/test_wasyncore.py
+++ b/tests/test_wasyncore.py
@@ -1,21 +1,20 @@
-from waitress import wasyncore as asyncore
-from waitress import compat
import contextlib
+import errno
import functools
import gc
-import unittest
-import select
+from io import BytesIO
import os
-import socket
-import sys
-import time
-import errno
import re
+import select
+import socket
import struct
+import sys
import threading
+import time
+import unittest
import warnings
-from io import BytesIO
+from waitress import compat, wasyncore as asyncore
TIMEOUT = 3
HAS_UNIX_SOCKETS = hasattr(socket, "AF_UNIX")
diff --git a/tox.ini b/tox.ini
index 2040825..ff0ff14 100644
--- a/tox.ini
+++ b/tox.ini
@@ -2,6 +2,7 @@
envlist =
lint,
py35,py36,py37,py38,pypy3,
+ py39,
docs,
coverage
isolated_build = True
@@ -31,6 +32,7 @@ depends = py38
skip_install = True
commands =
black --check --diff .
+ isort --check-only --df src/waitress tests
check-manifest
# flake8 src/waitress/ tests
# build sdist/wheel
@@ -38,12 +40,13 @@ commands =
twine check dist/*
deps =
black
- readme_renderer
check-manifest
- pep517
- twine
flake8
flake8-bugbear
+ isort
+ pep517
+ readme_renderer
+ twine
[testenv:docs]
whitelist_externals =
@@ -61,12 +64,14 @@ deps =
flake8
flake8-bugbear
-[testenv:run-black]
+[testenv:run-format]
skip_install = True
commands =
+ isort src/waitress tests
black .
deps =
black
+ isort
[testenv:build]
skip_install = true