Skip to content

Commit 54e74a9

Browse files
[isort] Lib modules (#1016)
* isort `proxy.py` main class * isort init and main * isort common * pre-commit fix * isort dashboard and testing * isort plugins * isort core * Only sort top level http py files * isort http exception and websocket * Remove proxy auth plugin from proxy package exports and force discover `PLUGIN_PROXY_AUTH` flags * isort parser and web server * no setattr * isort all * Enable pre-commit isort hook * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 77b69e6 commit 54e74a9

File tree

124 files changed

+428
-419
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+428
-419
lines changed

.pre-commit-config.yaml

+7-9
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ repos:
77
args:
88
- --py36-plus
99

10-
# - repo: https://github.com/timothycrosley/isort.git
11-
# rev: 5.10.0
12-
# hooks:
13-
# - id: isort
14-
# args:
15-
# - --honor-noqa
10+
- repo: https://github.com/timothycrosley/isort.git
11+
rev: 5.10.0
12+
hooks:
13+
- id: isort
14+
args:
15+
- --honor-noqa
1616

1717
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
1818
rev: v1.1.7
@@ -24,8 +24,7 @@ repos:
2424
helper/proxy\.pac|
2525
Makefile|
2626
proxy/common/pki\.py|
27-
README\.md|
28-
.+\.(plist|pbxproj)
27+
README\.md
2928
$
3029
3130
- repo: https://github.com/pre-commit/pre-commit-hooks.git
@@ -36,7 +35,6 @@ repos:
3635
exclude: |
3736
(?x)
3837
^
39-
\.github/workflows/codeql-analysis\.yml|
4038
dashboard/src/core/plugins/inspect_traffic\.json
4139
$
4240
- id: check-merge-conflict

benchmark/_blacksheep.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import uvicorn
12-
1312
from blacksheep.server import Application
1413
from blacksheep.server.responses import text
1514

benchmark/_proxy.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"""
1111
import time
1212
import ipaddress
13+
1314
import proxy
1415

1516

benchmark/_starlette.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import uvicorn
12-
13-
from starlette.applications import Starlette
14-
from starlette.responses import Response
1512
from starlette.routing import Route
13+
from starlette.responses import Response
14+
from starlette.applications import Starlette
1615

1716

1817
async def homepage(request): # type: ignore[no-untyped-def]

benchmark/_tornado.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
import tornado.ioloop
1211
import tornado.web
12+
import tornado.ioloop
1313

1414

1515
# pylint: disable=W0223

docs/_ext/spelling_stub_ext.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from typing import List
44

5+
from sphinx.util.nodes import nodes
56
from sphinx.application import Sphinx
67
from sphinx.util.docutils import SphinxDirective
7-
from sphinx.util.nodes import nodes
88

99

1010
class SpellingNoOpDirective(SphinxDirective):

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"""Configuration for the Sphinx documentation generator."""
55

66
import sys
7-
from functools import partial
87
from pathlib import Path
8+
from functools import partial
99

1010
from setuptools_scm import get_version
1111

examples/web_scraper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import time
1212

1313
from proxy import Proxy
14-
from proxy.common.types import Readables, Writables, SelectableEvents
1514
from proxy.core.work import Work
15+
from proxy.common.types import Readables, Writables, SelectableEvents
1616
from proxy.core.connection import TcpClientConnection
1717

1818

proxy/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
from .proxy import entry_point, main, Proxy, sleep_loop
11+
from .proxy import Proxy, main, sleep_loop, entry_point
1212
from .testing import TestCase
1313

14+
1415
__all__ = [
1516
# PyPi package entry_point. See
1617
# https://github.com/abhinavsingh/proxy.py#from-command-line-when-installed-using-pip

proxy/__main__.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"""
1111
from .proxy import entry_point
1212

13+
1314
if __name__ == '__main__':
1415
entry_point()

proxy/common/_scm_version.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
# autogenerated on build and absent on mypy checks time
33
from typing import Tuple, Union
44

5+
56
version: str
67
version_tuple: Tuple[Union[int, str], ...]

proxy/common/_version.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
"""
1313
from typing import Tuple, Union
1414

15+
1516
try:
1617
# pylint: disable=unused-import
17-
from ._scm_version import version as __version__, version_tuple as _ver_tup # noqa: WPS433, WPS436
18+
from ._scm_version import version as __version__ # noqa: WPS433, WPS436
19+
from ._scm_version import version_tuple as _ver_tup # noqa: WPS433, WPS436
1820
except ImportError: # pragma: no cover
1921
from pkg_resources import get_distribution as _get_dist # noqa: WPS433
2022
__version__ = _get_dist('proxy.py').version # noqa: WPS440

proxy/common/backports.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
"""
1111
import time
1212
import threading
13-
14-
from typing import Any, Deque
1513
from queue import Empty
14+
from typing import Any, Deque
1615
from collections import deque
1716

1817

proxy/common/constants.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
import os
1212
import sys
1313
import time
14-
import secrets
1514
import pathlib
15+
import secrets
1616
import platform
17-
import sysconfig
1817
import ipaddress
19-
18+
import sysconfig
2019
from typing import Any, List
2120

2221
from .version import __version__
2322

23+
2424
SYS_PLATFORM = platform.system()
2525
IS_WINDOWS = SYS_PLATFORM == 'Windows'
2626

@@ -150,9 +150,9 @@ def _env_threadless_compliant() -> bool:
150150
'HttpWebServerBasePlugin',
151151
'WebSocketTransportBasePlugin',
152152
]
153-
PLUGIN_PROXY_AUTH = 'proxy.http.proxy.AuthPlugin'
154153
PLUGIN_DASHBOARD = 'proxy.dashboard.ProxyDashboard'
155154
PLUGIN_HTTP_PROXY = 'proxy.http.proxy.HttpProxyPlugin'
155+
PLUGIN_PROXY_AUTH = 'proxy.http.proxy.auth.AuthPlugin'
156156
PLUGIN_WEB_SERVER = 'proxy.http.server.HttpWebServerPlugin'
157157
PLUGIN_PAC_FILE = 'proxy.http.server.HttpWebServerPacFilePlugin'
158158
PLUGIN_DEVTOOLS_PROTOCOL = 'proxy.http.inspector.devtools.DevtoolsProtocolPlugin'

proxy/common/flag.py

+20-12
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,22 @@
1616
import ipaddress
1717
import collections
1818
import multiprocessing
19+
from typing import Any, List, Optional, cast
1920

20-
from typing import Optional, List, Any, cast
21-
22-
from .plugins import Plugins
2321
from .types import IpAddress
2422
from .utils import bytes_, is_py2, is_threadless, set_open_file_limit
25-
from .constants import COMMA, DEFAULT_DATA_DIRECTORY_PATH, DEFAULT_NUM_ACCEPTORS, DEFAULT_NUM_WORKERS
26-
from .constants import DEFAULT_DEVTOOLS_WS_PATH, DEFAULT_DISABLE_HEADERS, PY2_DEPRECATION_MESSAGE
27-
from .constants import PLUGIN_DASHBOARD, PLUGIN_DEVTOOLS_PROTOCOL, DEFAULT_MIN_COMPRESSION_LIMIT
28-
from .constants import PLUGIN_HTTP_PROXY, PLUGIN_INSPECT_TRAFFIC, PLUGIN_PAC_FILE
29-
from .constants import PLUGIN_WEB_SERVER, PLUGIN_PROXY_AUTH, IS_WINDOWS, PLUGIN_WEBSOCKET_TRANSPORT
3023
from .logger import Logger
31-
24+
from .plugins import Plugins
3225
from .version import __version__
26+
from .constants import (
27+
COMMA, IS_WINDOWS, PLUGIN_PAC_FILE, PLUGIN_DASHBOARD, PLUGIN_HTTP_PROXY,
28+
PLUGIN_PROXY_AUTH, PLUGIN_WEB_SERVER, DEFAULT_NUM_WORKERS,
29+
DEFAULT_NUM_ACCEPTORS, PLUGIN_INSPECT_TRAFFIC, DEFAULT_DISABLE_HEADERS,
30+
PY2_DEPRECATION_MESSAGE, DEFAULT_DEVTOOLS_WS_PATH,
31+
PLUGIN_DEVTOOLS_PROTOCOL, PLUGIN_WEBSOCKET_TRANSPORT,
32+
DEFAULT_DATA_DIRECTORY_PATH, DEFAULT_MIN_COMPRESSION_LIMIT,
33+
)
34+
3335

3436
__homepage__ = 'https://github.com/abhinavsingh/proxy.py'
3537

@@ -96,13 +98,17 @@ def initialize(
9698
print(PY2_DEPRECATION_MESSAGE)
9799
sys.exit(1)
98100

101+
# Dirty hack to always discover --basic-auth flag
102+
# defined by proxy auth plugin.
103+
in_args = input_args + ['--plugin', PLUGIN_PROXY_AUTH]
104+
99105
# Discover flags from requested plugin.
100106
# This will also surface external plugin flags
101107
# under --help.
102-
Plugins.discover(input_args)
108+
Plugins.discover(in_args)
103109

104110
# Parse flags
105-
args = flags.parse_args(input_args)
111+
args = flags.parse_args(in_args)
106112

107113
# Print version and exit
108114
if args.version:
@@ -135,9 +141,11 @@ def initialize(
135141
if isinstance(work_klass, str) \
136142
else work_klass
137143

144+
# TODO: Plugin flag initialization logic must be moved within plugins.
145+
#
138146
# Generate auth_code required for basic authentication if enabled
139147
auth_code = None
140-
basic_auth = opts.get('basic_auth', args.basic_auth)
148+
basic_auth = opts.get('basic_auth', getattr(args, 'basic_auth', None))
141149
# Destroy passed credentials via flags or options
142150
args.basic_auth = None
143151
if 'basic_auth' in opts:

proxy/common/logger.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import logging
12+
from typing import Any, Optional
1213

13-
from typing import Optional, Any
14+
from .constants import DEFAULT_LOG_FILE, DEFAULT_LOG_LEVEL, DEFAULT_LOG_FORMAT
1415

15-
from .constants import DEFAULT_LOG_FILE, DEFAULT_LOG_FORMAT, DEFAULT_LOG_LEVEL
1616

1717
SINGLE_CHAR_TO_LEVEL = {
1818
'D': 'DEBUG',

proxy/common/pki.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@
1414
"""
1515
import os
1616
import sys
17-
import uuid
1817
import time
18+
import uuid
1919
import logging
20-
import tempfile
2120
import argparse
21+
import tempfile
2222
import contextlib
2323
import subprocess
24-
25-
from typing import List, Generator, Optional, Tuple
24+
from typing import List, Tuple, Optional, Generator
2625

2726
from .utils import bytes_
28-
from .constants import COMMA
2927
from .version import __version__
28+
from .constants import COMMA
3029

3130

3231
logger = logging.getLogger(__name__)

proxy/common/plugins.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import os
12-
import logging
1312
import inspect
14-
import itertools
13+
import logging
1514
import importlib
15+
import itertools
16+
from typing import Any, Dict, List, Tuple, Union, Optional
1617

17-
from typing import Any, List, Dict, Optional, Tuple, Union
18+
from .utils import text_, bytes_
19+
from .constants import DOT, COMMA, DEFAULT_ABC_PLUGINS
1820

19-
from .utils import bytes_, text_
20-
from .constants import DOT, DEFAULT_ABC_PLUGINS, COMMA
2121

2222
logger = logging.getLogger(__name__)
2323

proxy/common/types.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"""
1111
import queue
1212
import ipaddress
13-
14-
from typing import TYPE_CHECKING, Dict, Any, List, Tuple, Union
13+
from typing import TYPE_CHECKING, Any, Dict, List, Tuple, Union
1514

1615

1716
if TYPE_CHECKING: # pragma: no cover

proxy/common/utils.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
1313
utils
1414
"""
15-
import sys
1615
import ssl
16+
import sys
1717
import socket
1818
import logging
1919
import functools
2020
import ipaddress
2121
import contextlib
22-
2322
from types import TracebackType
24-
from typing import Optional, Dict, Any, List, Tuple, Type, Callable
23+
from typing import Any, Dict, List, Type, Tuple, Callable, Optional
2524

2625
from .constants import (
27-
HTTP_1_1, COLON, WHITESPACE, CRLF,
28-
DEFAULT_TIMEOUT, DEFAULT_THREADLESS, IS_WINDOWS,
26+
CRLF, COLON, HTTP_1_1, IS_WINDOWS, WHITESPACE, DEFAULT_TIMEOUT,
27+
DEFAULT_THREADLESS,
2928
)
3029

30+
3131
if not IS_WINDOWS: # pragma: no cover
3232
import resource
3333

proxy/common/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
from ._version import __version__, VERSION # noqa: WPS436
11+
from ._version import VERSION, __version__ # noqa: WPS436
1212

1313

1414
__all__ = '__version__', 'VERSION'

proxy/core/acceptor/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
1313
pre
1414
"""
15-
from .listener import Listener
16-
from .acceptor import Acceptor
1715
from .pool import AcceptorPool
16+
from .acceptor import Acceptor
17+
from .listener import Listener
18+
1819

1920
__all__ = [
2021
'Listener',

proxy/core/acceptor/acceptor.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,17 @@
1919
import threading
2020
import multiprocessing
2121
import multiprocessing.synchronize
22-
22+
from typing import List, Tuple, Optional
2323
from multiprocessing import connection
2424
from multiprocessing.reduction import recv_handle
2525

26-
from typing import List, Optional, Tuple
27-
26+
from ..work import LocalExecutor, start_threaded_work, delegate_work_to_pool
27+
from ..event import EventQueue
2828
from ...common.flag import flags
2929
from ...common.logger import Logger
3030
from ...common.backports import NonBlockingQueue
3131
from ...common.constants import DEFAULT_LOCAL_EXECUTOR
3232

33-
from ..event import EventQueue
34-
35-
from ..work import LocalExecutor, delegate_work_to_pool, start_threaded_work
3633

3734
logger = logging.getLogger(__name__)
3835

0 commit comments

Comments
 (0)