Skip to content

Commit

Permalink
Add isort to the project
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalresistor committed Aug 16, 2020
1 parent 2ed8a2b commit 1b4bcce
Show file tree
Hide file tree
Showing 23 changed files with 81 additions and 78 deletions.
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion src/waitress/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/waitress/adjustments.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
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"))

Expand Down
13 changes: 2 additions & 11 deletions src/waitress/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,9 @@
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
Expand Down
9 changes: 4 additions & 5 deletions src/waitress/compat.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import _thread as thread
from http import client as httplib
from io import StringIO as NativeIO
import os
import platform

# Fix for issue reported in https://github.com/Pylons/waitress/issues/138,
# 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"
Expand Down
3 changes: 2 additions & 1 deletion src/waitress/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,6 +29,7 @@
ServerNotImplemented,
find_double_newline,
)

from .rfc7230 import HEADER_FIELD


Expand Down
3 changes: 1 addition & 2 deletions src/waitress/proxy_headers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections import namedtuple

from .utilities import logger, undquote, BadRequest

from .utilities import BadRequest, logger, undquote

PROXY_HEADERS = frozenset(
{
Expand Down
5 changes: 1 addition & 4 deletions src/waitress/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@
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

Expand Down
2 changes: 1 addition & 1 deletion src/waitress/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/waitress/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#
##############################################################################

import errno
import os
import socket
import errno
import threading

from . import wasyncore
Expand Down
36 changes: 17 additions & 19 deletions src/waitress/wasyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,31 @@
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})

Expand Down
4 changes: 2 additions & 2 deletions tests/fixtureapps/getline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

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"}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_buffers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
import io
import unittest


class TestFileBasedBuffer(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_channel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
import io
import unittest


class TestHTTPChannel(unittest.TestCase):
Expand Down
1 change: 1 addition & 0 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys
import time
import unittest

from waitress import server
from waitress.compat import httplib, tobytes
from waitress.utilities import cleanup_unix_socket
Expand Down
4 changes: 2 additions & 2 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

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)
Expand Down Expand Up @@ -595,8 +595,8 @@ def test_crack_first_line_missing_version(self):

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)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_bad_app_object(self):
)

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)
Expand All @@ -133,7 +133,7 @@ def check_server(app, **kw):
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)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ class DummyChannel:
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)
Expand Down Expand Up @@ -411,8 +411,8 @@ def test_creates_new_sockinfo(self):

def test_create_with_unix_socket(self):
from waitress.server import (
MultiSocketServer,
BaseWSGIServer,
MultiSocketServer,
TcpWSGIServer,
UnixWSGIServer,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_task.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
import io
import unittest


class TestThreadedTaskDispatcher(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_trigger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
import os
import sys
import unittest

if not sys.platform.startswith("win"):

Expand Down
7 changes: 4 additions & 3 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ def test_neither(self):

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()))

Expand All @@ -60,7 +61,7 @@ def test_it(self):

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()))

Expand Down
17 changes: 8 additions & 9 deletions tests/test_wasyncore.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Loading

0 comments on commit 1b4bcce

Please sign in to comment.