diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f6243648..489b01b0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,12 +7,12 @@ repos: args: - --py36-plus -# - repo: https://github.com/timothycrosley/isort.git -# rev: 5.10.0 -# hooks: -# - id: isort -# args: -# - --honor-noqa +- repo: https://github.com/timothycrosley/isort.git + rev: 5.10.0 + hooks: + - id: isort + args: + - --honor-noqa - repo: https://github.com/Lucas-C/pre-commit-hooks.git rev: v1.1.7 @@ -24,8 +24,7 @@ repos: helper/proxy\.pac| Makefile| proxy/common/pki\.py| - README\.md| - .+\.(plist|pbxproj) + README\.md $ - repo: https://github.com/pre-commit/pre-commit-hooks.git @@ -36,7 +35,6 @@ repos: exclude: | (?x) ^ - \.github/workflows/codeql-analysis\.yml| dashboard/src/core/plugins/inspect_traffic\.json $ - id: check-merge-conflict diff --git a/benchmark/_blacksheep.py b/benchmark/_blacksheep.py index cd966b44..99f7e40e 100644 --- a/benchmark/_blacksheep.py +++ b/benchmark/_blacksheep.py @@ -9,7 +9,6 @@ :license: BSD, see LICENSE for more details. """ import uvicorn - from blacksheep.server import Application from blacksheep.server.responses import text diff --git a/benchmark/_proxy.py b/benchmark/_proxy.py index 838918ee..4a5ec0cf 100644 --- a/benchmark/_proxy.py +++ b/benchmark/_proxy.py @@ -10,6 +10,7 @@ """ import time import ipaddress + import proxy diff --git a/benchmark/_starlette.py b/benchmark/_starlette.py index 0e27e023..977b00d8 100644 --- a/benchmark/_starlette.py +++ b/benchmark/_starlette.py @@ -9,10 +9,9 @@ :license: BSD, see LICENSE for more details. """ import uvicorn - -from starlette.applications import Starlette -from starlette.responses import Response from starlette.routing import Route +from starlette.responses import Response +from starlette.applications import Starlette async def homepage(request): # type: ignore[no-untyped-def] diff --git a/benchmark/_tornado.py b/benchmark/_tornado.py index 3af22abb..95e02fe6 100644 --- a/benchmark/_tornado.py +++ b/benchmark/_tornado.py @@ -8,8 +8,8 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -import tornado.ioloop import tornado.web +import tornado.ioloop # pylint: disable=W0223 diff --git a/docs/_ext/spelling_stub_ext.py b/docs/_ext/spelling_stub_ext.py index c8989dc1..502888c4 100644 --- a/docs/_ext/spelling_stub_ext.py +++ b/docs/_ext/spelling_stub_ext.py @@ -2,9 +2,9 @@ from typing import List +from sphinx.util.nodes import nodes from sphinx.application import Sphinx from sphinx.util.docutils import SphinxDirective -from sphinx.util.nodes import nodes class SpellingNoOpDirective(SphinxDirective): diff --git a/docs/conf.py b/docs/conf.py index 350dd216..05d968a8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -4,8 +4,8 @@ """Configuration for the Sphinx documentation generator.""" import sys -from functools import partial from pathlib import Path +from functools import partial from setuptools_scm import get_version diff --git a/examples/web_scraper.py b/examples/web_scraper.py index 0dce2bd3..daf31d61 100644 --- a/examples/web_scraper.py +++ b/examples/web_scraper.py @@ -11,8 +11,8 @@ import time from proxy import Proxy -from proxy.common.types import Readables, Writables, SelectableEvents from proxy.core.work import Work +from proxy.common.types import Readables, Writables, SelectableEvents from proxy.core.connection import TcpClientConnection diff --git a/proxy/__init__.py b/proxy/__init__.py index f08c2afc..08da6e2a 100755 --- a/proxy/__init__.py +++ b/proxy/__init__.py @@ -8,9 +8,10 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -from .proxy import entry_point, main, Proxy, sleep_loop +from .proxy import Proxy, main, sleep_loop, entry_point from .testing import TestCase + __all__ = [ # PyPi package entry_point. See # https://github.com/abhinavsingh/proxy.py#from-command-line-when-installed-using-pip diff --git a/proxy/__main__.py b/proxy/__main__.py index d04d8529..844283ec 100644 --- a/proxy/__main__.py +++ b/proxy/__main__.py @@ -10,5 +10,6 @@ """ from .proxy import entry_point + if __name__ == '__main__': entry_point() diff --git a/proxy/common/_scm_version.pyi b/proxy/common/_scm_version.pyi index 4b964552..504112bd 100644 --- a/proxy/common/_scm_version.pyi +++ b/proxy/common/_scm_version.pyi @@ -2,5 +2,6 @@ # autogenerated on build and absent on mypy checks time from typing import Tuple, Union + version: str version_tuple: Tuple[Union[int, str], ...] diff --git a/proxy/common/_version.py b/proxy/common/_version.py index 21031c64..2d4fce9a 100644 --- a/proxy/common/_version.py +++ b/proxy/common/_version.py @@ -12,9 +12,11 @@ """ from typing import Tuple, Union + try: # pylint: disable=unused-import - from ._scm_version import version as __version__, version_tuple as _ver_tup # noqa: WPS433, WPS436 + from ._scm_version import version as __version__ # noqa: WPS433, WPS436 + from ._scm_version import version_tuple as _ver_tup # noqa: WPS433, WPS436 except ImportError: # pragma: no cover from pkg_resources import get_distribution as _get_dist # noqa: WPS433 __version__ = _get_dist('proxy.py').version # noqa: WPS440 diff --git a/proxy/common/backports.py b/proxy/common/backports.py index 87dbbdf9..770ed9fc 100644 --- a/proxy/common/backports.py +++ b/proxy/common/backports.py @@ -10,9 +10,8 @@ """ import time import threading - -from typing import Any, Deque from queue import Empty +from typing import Any, Deque from collections import deque diff --git a/proxy/common/constants.py b/proxy/common/constants.py index 04645af0..e21586a7 100644 --- a/proxy/common/constants.py +++ b/proxy/common/constants.py @@ -11,16 +11,16 @@ import os import sys import time -import secrets import pathlib +import secrets import platform -import sysconfig import ipaddress - +import sysconfig from typing import Any, List from .version import __version__ + SYS_PLATFORM = platform.system() IS_WINDOWS = SYS_PLATFORM == 'Windows' @@ -150,9 +150,9 @@ DEFAULT_ABC_PLUGINS = [ 'HttpWebServerBasePlugin', 'WebSocketTransportBasePlugin', ] -PLUGIN_PROXY_AUTH = 'proxy.http.proxy.AuthPlugin' PLUGIN_DASHBOARD = 'proxy.dashboard.ProxyDashboard' PLUGIN_HTTP_PROXY = 'proxy.http.proxy.HttpProxyPlugin' +PLUGIN_PROXY_AUTH = 'proxy.http.proxy.auth.AuthPlugin' PLUGIN_WEB_SERVER = 'proxy.http.server.HttpWebServerPlugin' PLUGIN_PAC_FILE = 'proxy.http.server.HttpWebServerPacFilePlugin' PLUGIN_DEVTOOLS_PROTOCOL = 'proxy.http.inspector.devtools.DevtoolsProtocolPlugin' diff --git a/proxy/common/flag.py b/proxy/common/flag.py index 9244ad38..edd07b7c 100644 --- a/proxy/common/flag.py +++ b/proxy/common/flag.py @@ -16,20 +16,22 @@ import argparse import ipaddress import collections import multiprocessing +from typing import Any, List, Optional, cast -from typing import Optional, List, Any, cast - -from .plugins import Plugins from .types import IpAddress from .utils import bytes_, is_py2, is_threadless, set_open_file_limit -from .constants import COMMA, DEFAULT_DATA_DIRECTORY_PATH, DEFAULT_NUM_ACCEPTORS, DEFAULT_NUM_WORKERS -from .constants import DEFAULT_DEVTOOLS_WS_PATH, DEFAULT_DISABLE_HEADERS, PY2_DEPRECATION_MESSAGE -from .constants import PLUGIN_DASHBOARD, PLUGIN_DEVTOOLS_PROTOCOL, DEFAULT_MIN_COMPRESSION_LIMIT -from .constants import PLUGIN_HTTP_PROXY, PLUGIN_INSPECT_TRAFFIC, PLUGIN_PAC_FILE -from .constants import PLUGIN_WEB_SERVER, PLUGIN_PROXY_AUTH, IS_WINDOWS, PLUGIN_WEBSOCKET_TRANSPORT from .logger import Logger - +from .plugins import Plugins from .version import __version__ +from .constants import ( + COMMA, IS_WINDOWS, PLUGIN_PAC_FILE, PLUGIN_DASHBOARD, PLUGIN_HTTP_PROXY, + PLUGIN_PROXY_AUTH, PLUGIN_WEB_SERVER, DEFAULT_NUM_WORKERS, + DEFAULT_NUM_ACCEPTORS, PLUGIN_INSPECT_TRAFFIC, DEFAULT_DISABLE_HEADERS, + PY2_DEPRECATION_MESSAGE, DEFAULT_DEVTOOLS_WS_PATH, + PLUGIN_DEVTOOLS_PROTOCOL, PLUGIN_WEBSOCKET_TRANSPORT, + DEFAULT_DATA_DIRECTORY_PATH, DEFAULT_MIN_COMPRESSION_LIMIT, +) + __homepage__ = 'https://github.com/abhinavsingh/proxy.py' @@ -96,13 +98,17 @@ class FlagParser: print(PY2_DEPRECATION_MESSAGE) sys.exit(1) + # Dirty hack to always discover --basic-auth flag + # defined by proxy auth plugin. + in_args = input_args + ['--plugin', PLUGIN_PROXY_AUTH] + # Discover flags from requested plugin. # This will also surface external plugin flags # under --help. - Plugins.discover(input_args) + Plugins.discover(in_args) # Parse flags - args = flags.parse_args(input_args) + args = flags.parse_args(in_args) # Print version and exit if args.version: @@ -135,9 +141,11 @@ class FlagParser: if isinstance(work_klass, str) \ else work_klass + # TODO: Plugin flag initialization logic must be moved within plugins. + # # Generate auth_code required for basic authentication if enabled auth_code = None - basic_auth = opts.get('basic_auth', args.basic_auth) + basic_auth = opts.get('basic_auth', getattr(args, 'basic_auth', None)) # Destroy passed credentials via flags or options args.basic_auth = None if 'basic_auth' in opts: diff --git a/proxy/common/logger.py b/proxy/common/logger.py index dbd2e8aa..74421d47 100644 --- a/proxy/common/logger.py +++ b/proxy/common/logger.py @@ -9,10 +9,10 @@ :license: BSD, see LICENSE for more details. """ import logging +from typing import Any, Optional -from typing import Optional, Any +from .constants import DEFAULT_LOG_FILE, DEFAULT_LOG_LEVEL, DEFAULT_LOG_FORMAT -from .constants import DEFAULT_LOG_FILE, DEFAULT_LOG_FORMAT, DEFAULT_LOG_LEVEL SINGLE_CHAR_TO_LEVEL = { 'D': 'DEBUG', diff --git a/proxy/common/pki.py b/proxy/common/pki.py index 0ccf6954..f8189c0c 100644 --- a/proxy/common/pki.py +++ b/proxy/common/pki.py @@ -14,19 +14,18 @@ """ import os import sys -import uuid import time +import uuid import logging -import tempfile import argparse +import tempfile import contextlib import subprocess - -from typing import List, Generator, Optional, Tuple +from typing import List, Tuple, Optional, Generator from .utils import bytes_ -from .constants import COMMA from .version import __version__ +from .constants import COMMA logger = logging.getLogger(__name__) diff --git a/proxy/common/plugins.py b/proxy/common/plugins.py index 2349e6ec..c919154c 100644 --- a/proxy/common/plugins.py +++ b/proxy/common/plugins.py @@ -9,15 +9,15 @@ :license: BSD, see LICENSE for more details. """ import os -import logging import inspect -import itertools +import logging import importlib +import itertools +from typing import Any, Dict, List, Tuple, Union, Optional -from typing import Any, List, Dict, Optional, Tuple, Union +from .utils import text_, bytes_ +from .constants import DOT, COMMA, DEFAULT_ABC_PLUGINS -from .utils import bytes_, text_ -from .constants import DOT, DEFAULT_ABC_PLUGINS, COMMA logger = logging.getLogger(__name__) diff --git a/proxy/common/types.py b/proxy/common/types.py index 79bfc62c..bc230c9b 100644 --- a/proxy/common/types.py +++ b/proxy/common/types.py @@ -10,8 +10,7 @@ """ import queue import ipaddress - -from typing import TYPE_CHECKING, Dict, Any, List, Tuple, Union +from typing import TYPE_CHECKING, Any, Dict, List, Tuple, Union if TYPE_CHECKING: # pragma: no cover diff --git a/proxy/common/utils.py b/proxy/common/utils.py index e7373ac2..9dc11ef1 100644 --- a/proxy/common/utils.py +++ b/proxy/common/utils.py @@ -12,22 +12,22 @@ utils """ -import sys import ssl +import sys import socket import logging import functools import ipaddress import contextlib - from types import TracebackType -from typing import Optional, Dict, Any, List, Tuple, Type, Callable +from typing import Any, Dict, List, Type, Tuple, Callable, Optional from .constants import ( - HTTP_1_1, COLON, WHITESPACE, CRLF, - DEFAULT_TIMEOUT, DEFAULT_THREADLESS, IS_WINDOWS, + CRLF, COLON, HTTP_1_1, IS_WINDOWS, WHITESPACE, DEFAULT_TIMEOUT, + DEFAULT_THREADLESS, ) + if not IS_WINDOWS: # pragma: no cover import resource diff --git a/proxy/common/version.py b/proxy/common/version.py index 69403174..530829c5 100644 --- a/proxy/common/version.py +++ b/proxy/common/version.py @@ -8,7 +8,7 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -from ._version import __version__, VERSION # noqa: WPS436 +from ._version import VERSION, __version__ # noqa: WPS436 __all__ = '__version__', 'VERSION' diff --git a/proxy/core/acceptor/__init__.py b/proxy/core/acceptor/__init__.py index a7cd9b1b..e5e3f606 100644 --- a/proxy/core/acceptor/__init__.py +++ b/proxy/core/acceptor/__init__.py @@ -12,9 +12,10 @@ pre """ -from .listener import Listener -from .acceptor import Acceptor from .pool import AcceptorPool +from .acceptor import Acceptor +from .listener import Listener + __all__ = [ 'Listener', diff --git a/proxy/core/acceptor/acceptor.py b/proxy/core/acceptor/acceptor.py index 8fa34afd..9572c1b5 100644 --- a/proxy/core/acceptor/acceptor.py +++ b/proxy/core/acceptor/acceptor.py @@ -19,20 +19,17 @@ import selectors import threading import multiprocessing import multiprocessing.synchronize - +from typing import List, Tuple, Optional from multiprocessing import connection from multiprocessing.reduction import recv_handle -from typing import List, Optional, Tuple - +from ..work import LocalExecutor, start_threaded_work, delegate_work_to_pool +from ..event import EventQueue from ...common.flag import flags from ...common.logger import Logger from ...common.backports import NonBlockingQueue from ...common.constants import DEFAULT_LOCAL_EXECUTOR -from ..event import EventQueue - -from ..work import LocalExecutor, delegate_work_to_pool, start_threaded_work logger = logging.getLogger(__name__) diff --git a/proxy/core/acceptor/listener.py b/proxy/core/acceptor/listener.py index d55962a9..0caef04d 100644 --- a/proxy/core/acceptor/listener.py +++ b/proxy/core/acceptor/listener.py @@ -16,11 +16,12 @@ import os import socket import logging import argparse - -from typing import Optional, Any +from typing import Any, Optional from ...common.flag import flags -from ...common.constants import DEFAULT_BACKLOG, DEFAULT_IPV4_HOSTNAME, DEFAULT_PORT, DEFAULT_PORT_FILE +from ...common.constants import ( + DEFAULT_PORT, DEFAULT_BACKLOG, DEFAULT_PORT_FILE, DEFAULT_IPV4_HOSTNAME, +) flags.add_argument( diff --git a/proxy/core/acceptor/pool.py b/proxy/core/acceptor/pool.py index 0e17cd10..99299cf4 100644 --- a/proxy/core/acceptor/pool.py +++ b/proxy/core/acceptor/pool.py @@ -17,18 +17,16 @@ import logging import argparse import multiprocessing - +from typing import TYPE_CHECKING, Any, List, Optional from multiprocessing import connection from multiprocessing.reduction import send_handle -from typing import TYPE_CHECKING, Any, List, Optional - -from .listener import Listener from .acceptor import Acceptor - +from .listener import Listener from ...common.flag import flags from ...common.constants import DEFAULT_NUM_ACCEPTORS + if TYPE_CHECKING: # pragma: no cover from ..event import EventQueue diff --git a/proxy/core/base/__init__.py b/proxy/core/base/__init__.py index bc86952b..5ce5a827 100644 --- a/proxy/core/base/__init__.py +++ b/proxy/core/base/__init__.py @@ -12,6 +12,7 @@ from .tcp_server import BaseTcpServerHandler from .tcp_tunnel import BaseTcpTunnelHandler from .tcp_upstream import TcpUpstreamConnectionHandler + __all__ = [ 'BaseTcpServerHandler', 'BaseTcpTunnelHandler', diff --git a/proxy/core/base/tcp_server.py b/proxy/core/base/tcp_server.py index 66804505..107e1ac9 100644 --- a/proxy/core/base/tcp_server.py +++ b/proxy/core/base/tcp_server.py @@ -16,18 +16,19 @@ import ssl import socket import logging import selectors - from abc import abstractmethod -from typing import Any, Optional, TypeVar, Union - -from ...common.flag import flags -from ...common.utils import wrap_socket -from ...common.types import Readables, SelectableEvents, Writables -from ...common.constants import DEFAULT_CERT_FILE, DEFAULT_CLIENT_RECVBUF_SIZE -from ...common.constants import DEFAULT_KEY_FILE, DEFAULT_SERVER_RECVBUF_SIZE, DEFAULT_TIMEOUT +from typing import Any, Union, TypeVar, Optional from ...core.work import Work +from ...common.flag import flags +from ...common.types import Readables, Writables, SelectableEvents +from ...common.utils import wrap_socket from ...core.connection import TcpClientConnection +from ...common.constants import ( + DEFAULT_TIMEOUT, DEFAULT_KEY_FILE, DEFAULT_CERT_FILE, + DEFAULT_CLIENT_RECVBUF_SIZE, DEFAULT_SERVER_RECVBUF_SIZE, +) + logger = logging.getLogger(__name__) diff --git a/proxy/core/base/tcp_tunnel.py b/proxy/core/base/tcp_tunnel.py index ea63c279..48444384 100644 --- a/proxy/core/base/tcp_tunnel.py +++ b/proxy/core/base/tcp_tunnel.py @@ -10,16 +10,15 @@ """ import logging import selectors - from abc import abstractmethod from typing import Any, Optional +from .tcp_server import BaseTcpServerHandler +from ..connection import TcpClientConnection, TcpServerConnection from ...http.parser import HttpParser, httpParserTypes -from ...common.types import Readables, SelectableEvents, Writables +from ...common.types import Readables, Writables, SelectableEvents from ...common.utils import text_ -from ..connection import TcpServerConnection, TcpClientConnection -from .tcp_server import BaseTcpServerHandler logger = logging.getLogger(__name__) diff --git a/proxy/core/base/tcp_upstream.py b/proxy/core/base/tcp_upstream.py index 402a22e4..564f9a50 100644 --- a/proxy/core/base/tcp_upstream.py +++ b/proxy/core/base/tcp_upstream.py @@ -10,13 +10,13 @@ """ import ssl import logging - from abc import ABC, abstractmethod -from typing import Optional, Any +from typing import Any, Optional from ...common.types import Readables, Writables, Descriptors from ...core.connection import TcpServerConnection + logger = logging.getLogger(__name__) diff --git a/proxy/core/connection/__init__.py b/proxy/core/connection/__init__.py index 58d100a8..3457f1db 100644 --- a/proxy/core/connection/__init__.py +++ b/proxy/core/connection/__init__.py @@ -13,11 +13,12 @@ reusability Submodules """ -from .connection import TcpConnection, TcpConnectionUninitializedException -from .client import TcpClientConnection -from .server import TcpServerConnection from .pool import UpstreamConnectionPool from .types import tcpConnectionTypes +from .client import TcpClientConnection +from .server import TcpServerConnection +from .connection import TcpConnection, TcpConnectionUninitializedException + __all__ = [ 'TcpConnection', diff --git a/proxy/core/connection/client.py b/proxy/core/connection/client.py index 966221e1..0ba63885 100644 --- a/proxy/core/connection/client.py +++ b/proxy/core/connection/client.py @@ -10,11 +10,10 @@ """ import ssl import socket +from typing import Tuple, Union, Optional -from typing import Union, Tuple, Optional - -from .connection import TcpConnection, TcpConnectionUninitializedException from .types import tcpConnectionTypes +from .connection import TcpConnection, TcpConnectionUninitializedException class TcpClientConnection(TcpConnection): diff --git a/proxy/core/connection/connection.py b/proxy/core/connection/connection.py index 84c6c9de..9aa0d77d 100644 --- a/proxy/core/connection/connection.py +++ b/proxy/core/connection/connection.py @@ -11,13 +11,12 @@ import ssl import socket import logging - from abc import ABC, abstractmethod -from typing import Optional, Union, List - -from ...common.constants import DEFAULT_BUFFER_SIZE, DEFAULT_MAX_SEND_SIZE +from typing import List, Union, Optional from .types import tcpConnectionTypes +from ...common.constants import DEFAULT_BUFFER_SIZE, DEFAULT_MAX_SEND_SIZE + logger = logging.getLogger(__name__) diff --git a/proxy/core/connection/pool.py b/proxy/core/connection/pool.py index 29e00bd6..86c54a32 100644 --- a/proxy/core/connection/pool.py +++ b/proxy/core/connection/pool.py @@ -15,15 +15,13 @@ import socket import logging import selectors - from typing import TYPE_CHECKING, Any, Set, Dict, Tuple -from ...common.flag import flags -from ...common.types import Readables, SelectableEvents, Writables - from ..work import Work - from .server import TcpServerConnection +from ...common.flag import flags +from ...common.types import Readables, Writables, SelectableEvents + logger = logging.getLogger(__name__) diff --git a/proxy/core/connection/server.py b/proxy/core/connection/server.py index 109c238e..48690f96 100644 --- a/proxy/core/connection/server.py +++ b/proxy/core/connection/server.py @@ -10,13 +10,11 @@ """ import ssl import socket +from typing import Tuple, Union, Optional -from typing import Optional, Union, Tuple - -from ...common.utils import new_socket_connection - -from .connection import TcpConnection, TcpConnectionUninitializedException from .types import tcpConnectionTypes +from .connection import TcpConnection, TcpConnectionUninitializedException +from ...common.utils import new_socket_connection class TcpServerConnection(TcpConnection): diff --git a/proxy/core/event/__init__.py b/proxy/core/event/__init__.py index 17e1074e..05736f7b 100644 --- a/proxy/core/event/__init__.py +++ b/proxy/core/event/__init__.py @@ -8,11 +8,12 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -from .queue import EventQueue from .names import EventNames, eventNames +from .queue import EventQueue +from .manager import EventManager from .dispatcher import EventDispatcher from .subscriber import EventSubscriber -from .manager import EventManager + __all__ = [ 'eventNames', diff --git a/proxy/core/event/dispatcher.py b/proxy/core/event/dispatcher.py index 49408fdc..7cc978f1 100644 --- a/proxy/core/event/dispatcher.py +++ b/proxy/core/event/dispatcher.py @@ -11,13 +11,12 @@ import queue import logging import threading - +from typing import Any, Dict, List from multiprocessing import connection -from typing import Dict, Any, List - -from .queue import EventQueue from .names import eventNames +from .queue import EventQueue + logger = logging.getLogger(__name__) diff --git a/proxy/core/event/manager.py b/proxy/core/event/manager.py index 3923c6c1..6a100f90 100644 --- a/proxy/core/event/manager.py +++ b/proxy/core/event/manager.py @@ -15,15 +15,14 @@ import logging import threading import multiprocessing - from typing import Any, Optional from .queue import EventQueue from .dispatcher import EventDispatcher - from ...common.flag import flags from ...common.constants import DEFAULT_ENABLE_EVENTS + logger = logging.getLogger(__name__) diff --git a/proxy/core/event/names.py b/proxy/core/event/names.py index 5040c880..369724aa 100644 --- a/proxy/core/event/names.py +++ b/proxy/core/event/names.py @@ -10,6 +10,7 @@ """ from typing import NamedTuple + # Name of the events that eventing framework supports. # # Ideally this must be configurable via command line or diff --git a/proxy/core/event/queue.py b/proxy/core/event/queue.py index f86ba09b..878fe9bf 100644 --- a/proxy/core/event/queue.py +++ b/proxy/core/event/queue.py @@ -11,14 +11,11 @@ import os import time import threading - +from typing import Any, Dict, Optional from multiprocessing import connection -from typing import Dict, Optional, Any - -from ...common.types import DictQueueType - from .names import eventNames +from ...common.types import DictQueueType class EventQueue: diff --git a/proxy/core/event/subscriber.py b/proxy/core/event/subscriber.py index 14567616..ea478dc4 100644 --- a/proxy/core/event/subscriber.py +++ b/proxy/core/event/subscriber.py @@ -13,13 +13,12 @@ import queue import logging import threading import multiprocessing - +from typing import Any, Dict, Callable, Optional from multiprocessing import connection -from typing import Dict, Optional, Any, Callable - -from .queue import EventQueue from .names import eventNames +from .queue import EventQueue + logger = logging.getLogger(__name__) diff --git a/proxy/core/ssh/__init__.py b/proxy/core/ssh/__init__.py index 2150e155..9d9d605d 100644 --- a/proxy/core/ssh/__init__.py +++ b/proxy/core/ssh/__init__.py @@ -15,6 +15,7 @@ from .handler import SshHttpProtocolHandler from .listener import SshTunnelListener + __all__ = [ 'SshHttpProtocolHandler', 'SshTunnelListener', diff --git a/proxy/core/ssh/handler.py b/proxy/core/ssh/handler.py index 1c021f8c..12557ed9 100644 --- a/proxy/core/ssh/handler.py +++ b/proxy/core/ssh/handler.py @@ -9,9 +9,9 @@ :license: BSD, see LICENSE for more details. """ import argparse - from typing import TYPE_CHECKING, Tuple + if TYPE_CHECKING: # pragma: no cover try: from paramiko.channel import Channel diff --git a/proxy/core/ssh/listener.py b/proxy/core/ssh/listener.py index e1bc565b..1b17120e 100644 --- a/proxy/core/ssh/listener.py +++ b/proxy/core/ssh/listener.py @@ -8,10 +8,10 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -import argparse import logging +import argparse +from typing import TYPE_CHECKING, Any, Set, Tuple, Callable, Optional -from typing import TYPE_CHECKING, Any, Callable, Optional, Set, Tuple try: from paramiko import SSHClient, AutoAddPolicy @@ -23,6 +23,7 @@ except ImportError: # pragma: no cover from ...common.flag import flags + logger = logging.getLogger(__name__) diff --git a/proxy/core/work/__init__.py b/proxy/core/work/__init__.py index 403978ff..a89add78 100644 --- a/proxy/core/work/__init__.py +++ b/proxy/core/work/__init__.py @@ -12,13 +12,14 @@ pre """ -from .work import Work -from .threadless import Threadless -from .remote import RemoteExecutor -from .local import LocalExecutor from .pool import ThreadlessPool +from .work import Work +from .local import LocalExecutor +from .remote import RemoteExecutor from .delegate import delegate_work_to_pool from .threaded import start_threaded_work +from .threadless import Threadless + __all__ = [ 'Work', diff --git a/proxy/core/work/delegate.py b/proxy/core/work/delegate.py index 5a176e89..76207d96 100644 --- a/proxy/core/work/delegate.py +++ b/proxy/core/work/delegate.py @@ -8,9 +8,10 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -from typing import TYPE_CHECKING, Optional, Tuple +from typing import TYPE_CHECKING, Tuple, Optional from multiprocessing.reduction import send_handle + if TYPE_CHECKING: # pragma: no cover import socket import multiprocessing diff --git a/proxy/core/work/local.py b/proxy/core/work/local.py index 95c2c118..e081b2da 100644 --- a/proxy/core/work/local.py +++ b/proxy/core/work/local.py @@ -9,16 +9,16 @@ :license: BSD, see LICENSE for more details. """ import queue -import logging import asyncio +import logging import contextlib - -from typing import Optional -from typing import Any - -from ...common.backports import NonBlockingQueue # noqa: W0611, F401 pylint: disable=unused-import +from typing import Any, Optional from .threadless import Threadless +from ...common.backports import ( # noqa: W0611, F401 pylint: disable=unused-import + NonBlockingQueue, +) + logger = logging.getLogger(__name__) diff --git a/proxy/core/work/pool.py b/proxy/core/work/pool.py index 0a28ff1b..96c43a72 100644 --- a/proxy/core/work/pool.py +++ b/proxy/core/work/pool.py @@ -11,14 +11,13 @@ import logging import argparse import multiprocessing - +from typing import TYPE_CHECKING, Any, List, Optional from multiprocessing import connection -from typing import TYPE_CHECKING, Any, Optional, List from .remote import RemoteExecutor - from ...common.flag import flags -from ...common.constants import DEFAULT_NUM_WORKERS, DEFAULT_THREADLESS +from ...common.constants import DEFAULT_THREADLESS, DEFAULT_NUM_WORKERS + if TYPE_CHECKING: # pragma: no cover from ..event import EventQueue diff --git a/proxy/core/work/remote.py b/proxy/core/work/remote.py index bc16e83e..6dd91ef0 100644 --- a/proxy/core/work/remote.py +++ b/proxy/core/work/remote.py @@ -10,13 +10,13 @@ """ import asyncio import logging - -from typing import Optional, Any +from typing import Any, Optional from multiprocessing import connection from multiprocessing.reduction import recv_handle from .threadless import Threadless + logger = logging.getLogger(__name__) diff --git a/proxy/core/work/threaded.py b/proxy/core/work/threaded.py index 7366f8a2..6f2569a0 100644 --- a/proxy/core/work/threaded.py +++ b/proxy/core/work/threaded.py @@ -11,11 +11,11 @@ import socket import argparse import threading - -from typing import TYPE_CHECKING, Optional, Tuple, TypeVar +from typing import TYPE_CHECKING, Tuple, TypeVar, Optional from ..event import EventQueue, eventNames + if TYPE_CHECKING: # pragma: no cover from .work import Work diff --git a/proxy/core/work/threadless.py b/proxy/core/work/threadless.py index e5c69a39..57eca4dc 100644 --- a/proxy/core/work/threadless.py +++ b/proxy/core/work/threadless.py @@ -11,27 +11,30 @@ import os import ssl import socket -import logging import asyncio +import logging import argparse import selectors import multiprocessing - -from abc import abstractmethod, ABC -from typing import TYPE_CHECKING, Dict, Optional, Tuple, List, Set, Generic, TypeVar, Union - -from ...common.logger import Logger -from ...common.types import Readables, SelectableEvents, Writables -from ...common.constants import DEFAULT_INACTIVE_CONN_CLEANUP_TIMEOUT, DEFAULT_SELECTOR_SELECT_TIMEOUT -from ...common.constants import DEFAULT_WAIT_FOR_TASKS_TIMEOUT +from abc import ABC, abstractmethod +from typing import ( + TYPE_CHECKING, Set, Dict, List, Tuple, Union, Generic, TypeVar, Optional, +) from ..event import eventNames +from ...common.types import Readables, Writables, SelectableEvents +from ...common.logger import Logger +from ...common.constants import ( + DEFAULT_WAIT_FOR_TASKS_TIMEOUT, DEFAULT_SELECTOR_SELECT_TIMEOUT, + DEFAULT_INACTIVE_CONN_CLEANUP_TIMEOUT, +) + if TYPE_CHECKING: # pragma: no cover from typing import Any - from ..event import EventQueue from .work import Work + from ..event import EventQueue T = TypeVar('T') @@ -92,7 +95,9 @@ class Threadless(ABC, Generic[T]): self._total: int = 0 # When put at the top, causes circular import error # since integrated ssh tunnel was introduced. - from ..connection import UpstreamConnectionPool # pylint: disable=C0415 + from ..connection import ( # pylint: disable=C0415 + UpstreamConnectionPool, + ) self._upstream_conn_pool: Optional['UpstreamConnectionPool'] = None self._upstream_conn_filenos: Set[int] = set() if self.flags.enable_conn_pool: diff --git a/proxy/core/work/work.py b/proxy/core/work/work.py index 7747d269..08560103 100644 --- a/proxy/core/work/work.py +++ b/proxy/core/work/work.py @@ -13,13 +13,13 @@ acceptor """ import argparse - -from uuid import uuid4 from abc import ABC, abstractmethod -from typing import Optional, Dict, Any, TypeVar, Generic, TYPE_CHECKING +from uuid import uuid4 +from typing import TYPE_CHECKING, Any, Dict, Generic, TypeVar, Optional + +from ..event import EventQueue, eventNames +from ...common.types import Readables, Writables, SelectableEvents -from ..event import eventNames, EventQueue -from ...common.types import Readables, SelectableEvents, Writables if TYPE_CHECKING: # pragma: no cover from ..connection import UpstreamConnectionPool diff --git a/proxy/dashboard/__init__.py b/proxy/dashboard/__init__.py index 96a79aff..b59e877a 100644 --- a/proxy/dashboard/__init__.py +++ b/proxy/dashboard/__init__.py @@ -10,6 +10,7 @@ """ from .dashboard import ProxyDashboard + __all__ = [ 'ProxyDashboard', ] diff --git a/proxy/dashboard/dashboard.py b/proxy/dashboard/dashboard.py index 6e719d23..411c153b 100644 --- a/proxy/dashboard/dashboard.py +++ b/proxy/dashboard/dashboard.py @@ -12,9 +12,12 @@ import os import logging from typing import List, Tuple -from ..http.responses import permanentRedirectResponse from ..http.parser import HttpParser -from ..http.server import HttpWebServerPlugin, HttpWebServerBasePlugin, httpProtocolTypes +from ..http.server import ( + HttpWebServerPlugin, HttpWebServerBasePlugin, httpProtocolTypes, +) +from ..http.responses import permanentRedirectResponse + logger = logging.getLogger(__name__) diff --git a/proxy/http/__init__.py b/proxy/http/__init__.py index 9c800b5d..37826426 100644 --- a/proxy/http/__init__.py +++ b/proxy/http/__init__.py @@ -8,13 +8,14 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -from .handler import HttpProtocolHandler -from .connection import HttpClientConnection -from .plugin import HttpProtocolHandlerPlugin -from .codes import httpStatusCodes -from .methods import httpMethods -from .headers import httpHeaders from .url import Url +from .codes import httpStatusCodes +from .plugin import HttpProtocolHandlerPlugin +from .handler import HttpProtocolHandler +from .headers import httpHeaders +from .methods import httpMethods +from .connection import HttpClientConnection + __all__ = [ 'HttpProtocolHandler', diff --git a/proxy/http/descriptors.py b/proxy/http/descriptors.py index bae5ea38..102629bd 100644 --- a/proxy/http/descriptors.py +++ b/proxy/http/descriptors.py @@ -9,6 +9,7 @@ :license: BSD, see LICENSE for more details. """ from typing import Any + from ..common.types import Readables, Writables, Descriptors diff --git a/proxy/http/exception/__init__.py b/proxy/http/exception/__init__.py index 513d2bd5..68776e92 100644 --- a/proxy/http/exception/__init__.py +++ b/proxy/http/exception/__init__.py @@ -9,9 +9,10 @@ :license: BSD, see LICENSE for more details. """ from .base import HttpProtocolException -from .http_request_rejected import HttpRequestRejected from .proxy_auth_failed import ProxyAuthenticationFailed from .proxy_conn_failed import ProxyConnectionFailed +from .http_request_rejected import HttpRequestRejected + __all__ = [ 'HttpProtocolException', diff --git a/proxy/http/exception/base.py b/proxy/http/exception/base.py index e01be4ab..bd1233ba 100644 --- a/proxy/http/exception/base.py +++ b/proxy/http/exception/base.py @@ -12,7 +12,8 @@ http """ -from typing import Any, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Optional + if TYPE_CHECKING: # pragma: no cover from ..parser import HttpParser diff --git a/proxy/http/exception/http_request_rejected.py b/proxy/http/exception/http_request_rejected.py index 7c6f8d48..2b2e7a13 100644 --- a/proxy/http/exception/http_request_rejected.py +++ b/proxy/http/exception/http_request_rejected.py @@ -8,12 +8,12 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -from typing import Any, Optional, Dict, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, Optional from .base import HttpProtocolException - from ...common.utils import build_http_response + if TYPE_CHECKING: # pragma: no cover from ..parser import HttpParser diff --git a/proxy/http/exception/proxy_auth_failed.py b/proxy/http/exception/proxy_auth_failed.py index 4fbe62b4..afb2e404 100644 --- a/proxy/http/exception/proxy_auth_failed.py +++ b/proxy/http/exception/proxy_auth_failed.py @@ -16,9 +16,9 @@ from typing import TYPE_CHECKING, Any from .base import HttpProtocolException - from ..responses import PROXY_AUTH_FAILED_RESPONSE_PKT + if TYPE_CHECKING: # pragma: no cover from ..parser import HttpParser diff --git a/proxy/http/exception/proxy_conn_failed.py b/proxy/http/exception/proxy_conn_failed.py index 7aa70923..2001b336 100644 --- a/proxy/http/exception/proxy_conn_failed.py +++ b/proxy/http/exception/proxy_conn_failed.py @@ -15,9 +15,9 @@ from typing import TYPE_CHECKING, Any from .base import HttpProtocolException - from ..responses import BAD_GATEWAY_RESPONSE_PKT + if TYPE_CHECKING: # pragma: no cover from ..parser import HttpParser diff --git a/proxy/http/handler.py b/proxy/http/handler.py index 8b2952f8..04fd507b 100644 --- a/proxy/http/handler.py +++ b/proxy/http/handler.py @@ -15,19 +15,17 @@ import socket import asyncio import logging import selectors +from typing import Any, List, Type, Tuple, Optional -from typing import Tuple, List, Type, Optional, Any - -from ..core.base import BaseTcpServerHandler -from ..common.types import Readables, SelectableEvents, Writables -from ..common.constants import DEFAULT_SELECTOR_SELECT_TIMEOUT - -from .protocols import httpProtocols -from .connection import HttpClientConnection -from .exception import HttpProtocolException +from .parser import HttpParser, httpParserTypes, httpParserStates from .plugin import HttpProtocolHandlerPlugin +from .exception import HttpProtocolException +from .protocols import httpProtocols from .responses import BAD_REQUEST_RESPONSE_PKT -from .parser import HttpParser, httpParserStates, httpParserTypes +from ..core.base import BaseTcpServerHandler +from .connection import HttpClientConnection +from ..common.types import Readables, Writables, SelectableEvents +from ..common.constants import DEFAULT_SELECTOR_SELECT_TIMEOUT logger = logging.getLogger(__name__) diff --git a/proxy/http/inspector/devtools.py b/proxy/http/inspector/devtools.py index 5b16571b..b5058764 100644 --- a/proxy/http/inspector/devtools.py +++ b/proxy/http/inspector/devtools.py @@ -14,18 +14,20 @@ """ import json import logging -from typing import List, Tuple, Any, Dict +from typing import Any, Dict, List, Tuple -from .transformer import CoreEventsToDevtoolsProtocol from ..parser import HttpParser -from ..websocket import WebsocketFrame, websocketOpcodes from ..server import HttpWebServerBasePlugin, httpProtocolTypes - -from ...common.utils import bytes_, text_ +from ..websocket import WebsocketFrame, websocketOpcodes +from .transformer import CoreEventsToDevtoolsProtocol from ...core.event import EventSubscriber from ...common.flag import flags -from ...common.constants import DEFAULT_DEVTOOLS_WS_PATH, DEFAULT_DEVTOOLS_DOC_URL -from ...common.constants import DEFAULT_ENABLE_DEVTOOLS +from ...common.utils import text_, bytes_ +from ...common.constants import ( + DEFAULT_ENABLE_DEVTOOLS, DEFAULT_DEVTOOLS_DOC_URL, + DEFAULT_DEVTOOLS_WS_PATH, +) + logger = logging.getLogger(__name__) diff --git a/proxy/http/inspector/inspect_traffic.py b/proxy/http/inspector/inspect_traffic.py index 60225f5c..8b5b01da 100644 --- a/proxy/http/inspector/inspect_traffic.py +++ b/proxy/http/inspector/inspect_traffic.py @@ -9,12 +9,12 @@ :license: BSD, see LICENSE for more details. """ import json -from typing import TYPE_CHECKING, List, Dict, Any - -from ...common.utils import bytes_ -from ...core.event import EventSubscriber +from typing import TYPE_CHECKING, Any, Dict, List from ..websocket import WebsocketFrame, WebSocketTransportBasePlugin +from ...core.event import EventSubscriber +from ...common.utils import bytes_ + if TYPE_CHECKING: # pragma: no cover from ..connection import HttpClientConnection diff --git a/proxy/http/inspector/transformer.py b/proxy/http/inspector/transformer.py index ea9276dd..d04909e1 100644 --- a/proxy/http/inspector/transformer.py +++ b/proxy/http/inspector/transformer.py @@ -12,12 +12,14 @@ import json import time from typing import TYPE_CHECKING, Any, Dict -from ...common.constants import PROXY_PY_START_TIME, DEFAULT_DEVTOOLS_DOC_URL -from ...common.constants import DEFAULT_DEVTOOLS_FRAME_ID, DEFAULT_DEVTOOLS_LOADER_ID -from ...common.utils import bytes_ -from ...core.event import eventNames - from ..websocket import WebsocketFrame +from ...core.event import eventNames +from ...common.utils import bytes_ +from ...common.constants import ( + PROXY_PY_START_TIME, DEFAULT_DEVTOOLS_DOC_URL, DEFAULT_DEVTOOLS_FRAME_ID, + DEFAULT_DEVTOOLS_LOADER_ID, +) + if TYPE_CHECKING: # pragma: no cover from ..connection import HttpClientConnection diff --git a/proxy/http/parser/__init__.py b/proxy/http/parser/__init__.py index be633d48..d1976665 100644 --- a/proxy/http/parser/__init__.py +++ b/proxy/http/parser/__init__.py @@ -13,10 +13,11 @@ http Submodules """ -from .parser import HttpParser from .chunk import ChunkParser, chunkParserStates -from .types import httpParserStates, httpParserTypes -from .protocol import ProxyProtocol, PROXY_PROTOCOL_V2_SIGNATURE +from .types import httpParserTypes, httpParserStates +from .parser import HttpParser +from .protocol import PROXY_PROTOCOL_V2_SIGNATURE, ProxyProtocol + __all__ = [ 'HttpParser', diff --git a/proxy/http/parser/chunk.py b/proxy/http/parser/chunk.py index 2d976c44..69111792 100644 --- a/proxy/http/parser/chunk.py +++ b/proxy/http/parser/chunk.py @@ -8,7 +8,7 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -from typing import NamedTuple, Tuple, List, Optional +from typing import List, Tuple, Optional, NamedTuple from ...common.utils import bytes_, find_http_line from ...common.constants import CRLF, DEFAULT_BUFFER_SIZE diff --git a/proxy/http/parser/parser.py b/proxy/http/parser/parser.py index 6adbd558..6573caba 100644 --- a/proxy/http/parser/parser.py +++ b/proxy/http/parser/parser.py @@ -12,22 +12,22 @@ http """ -from typing import TypeVar, Optional, Dict, Type, Tuple, List - -from ...common.constants import DEFAULT_DISABLE_HEADERS, COLON, DEFAULT_ENABLE_PROXY_PROTOCOL, HTTP_1_0 -from ...common.constants import HTTP_1_1, SLASH, CRLF -from ...common.constants import WHITESPACE, DEFAULT_HTTP_PORT -from ...common.utils import build_http_request, build_http_response, text_ -from ...common.flag import flags +from typing import Dict, List, Type, Tuple, TypeVar, Optional from ..url import Url -from ..methods import httpMethods -from ..protocols import httpProtocols -from ..exception import HttpProtocolException - -from .protocol import ProxyProtocol from .chunk import ChunkParser, chunkParserStates from .types import httpParserTypes, httpParserStates +from ..methods import httpMethods +from .protocol import ProxyProtocol +from ..exception import HttpProtocolException +from ..protocols import httpProtocols +from ...common.flag import flags +from ...common.utils import text_, build_http_request, build_http_response +from ...common.constants import ( + CRLF, COLON, SLASH, HTTP_1_0, HTTP_1_1, WHITESPACE, DEFAULT_HTTP_PORT, + DEFAULT_DISABLE_HEADERS, DEFAULT_ENABLE_PROXY_PROTOCOL, +) + flags.add_argument( '--enable-proxy-protocol', diff --git a/proxy/http/parser/protocol.py b/proxy/http/parser/protocol.py index c44192f0..2fc19df4 100644 --- a/proxy/http/parser/protocol.py +++ b/proxy/http/parser/protocol.py @@ -8,12 +8,12 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -from typing import Optional, Tuple +from typing import Tuple, Optional from ..exception import HttpProtocolException - from ...common.constants import WHITESPACE + PROXY_PROTOCOL_V2_SIGNATURE = b'\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A' diff --git a/proxy/http/parser/tls/__init__.py b/proxy/http/parser/tls/__init__.py index d32e35bc..1ad8fb2c 100644 --- a/proxy/http/parser/tls/__init__.py +++ b/proxy/http/parser/tls/__init__.py @@ -11,6 +11,7 @@ from .tls import TlsParser from .types import tlsContentType, tlsHandshakeType + __all__ = [ 'TlsParser', 'tlsContentType', diff --git a/proxy/http/parser/tls/certificate.py b/proxy/http/parser/tls/certificate.py index 1004210a..f71e495c 100644 --- a/proxy/http/parser/tls/certificate.py +++ b/proxy/http/parser/tls/certificate.py @@ -8,7 +8,7 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -from typing import Optional, Tuple +from typing import Tuple, Optional class TlsCertificate: diff --git a/proxy/http/parser/tls/finished.py b/proxy/http/parser/tls/finished.py index 4cc72733..df9db062 100644 --- a/proxy/http/parser/tls/finished.py +++ b/proxy/http/parser/tls/finished.py @@ -8,7 +8,7 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -from typing import Optional, Tuple +from typing import Tuple, Optional class TlsFinished: diff --git a/proxy/http/parser/tls/handshake.py b/proxy/http/parser/tls/handshake.py index d859ceb5..7a03e247 100644 --- a/proxy/http/parser/tls/handshake.py +++ b/proxy/http/parser/tls/handshake.py @@ -10,14 +10,18 @@ """ import struct import logging +from typing import Tuple, Optional -from typing import Optional, Tuple - +from .hello import ( + TlsClientHello, TlsServerHello, TlsHelloRequest, TlsServerHelloDone, +) from .types import tlsHandshakeType -from .hello import TlsHelloRequest, TlsClientHello, TlsServerHello, TlsServerHelloDone -from .certificate import TlsCertificate, TlsCertificateRequest, TlsCertificateVerify -from .key_exchange import TlsClientKeyExchange, TlsServerKeyExchange from .finished import TlsFinished +from .certificate import ( + TlsCertificate, TlsCertificateVerify, TlsCertificateRequest, +) +from .key_exchange import TlsClientKeyExchange, TlsServerKeyExchange + logger = logging.getLogger(__name__) diff --git a/proxy/http/parser/tls/hello.py b/proxy/http/parser/tls/hello.py index 80287109..f60c724b 100644 --- a/proxy/http/parser/tls/hello.py +++ b/proxy/http/parser/tls/hello.py @@ -11,11 +11,11 @@ import os import struct import logging - -from typing import Optional, Tuple +from typing import Tuple, Optional from .pretty import pretty_hexlify + logger = logging.getLogger(__name__) diff --git a/proxy/http/parser/tls/key_exchange.py b/proxy/http/parser/tls/key_exchange.py index ce56562b..cb0059ed 100644 --- a/proxy/http/parser/tls/key_exchange.py +++ b/proxy/http/parser/tls/key_exchange.py @@ -8,7 +8,7 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -from typing import Optional, Tuple +from typing import Tuple, Optional class TlsServerKeyExchange: diff --git a/proxy/http/parser/tls/tls.py b/proxy/http/parser/tls/tls.py index 634c5b93..9e5aa89e 100644 --- a/proxy/http/parser/tls/tls.py +++ b/proxy/http/parser/tls/tls.py @@ -10,12 +10,12 @@ """ import struct import logging - -from typing import Optional, Tuple +from typing import Tuple, Optional from .types import tlsContentType -from .certificate import TlsCertificate from .handshake import TlsHandshake +from .certificate import TlsCertificate + logger = logging.getLogger(__name__) diff --git a/proxy/http/parser/tls/types.py b/proxy/http/parser/tls/types.py index 9dd05df3..640cffe2 100644 --- a/proxy/http/parser/tls/types.py +++ b/proxy/http/parser/tls/types.py @@ -10,6 +10,7 @@ """ from typing import NamedTuple + TlsContentType = NamedTuple( 'TlsContentType', [ ('CHANGE_CIPHER_SPEC', int), diff --git a/proxy/http/plugin.py b/proxy/http/plugin.py index 3b587a17..9eaa0977 100644 --- a/proxy/http/plugin.py +++ b/proxy/http/plugin.py @@ -10,16 +10,15 @@ """ import socket import argparse - from abc import ABC, abstractmethod -from typing import List, Union, Optional, TYPE_CHECKING - -from ..core.event import EventQueue +from typing import TYPE_CHECKING, List, Union, Optional +from .mixins import TlsInterceptionPropertyMixin from .parser import HttpParser from .connection import HttpClientConnection +from ..core.event import EventQueue from .descriptors import DescriptorsHandlerMixin -from .mixins import TlsInterceptionPropertyMixin + if TYPE_CHECKING: # pragma: no cover from ..core.connection import UpstreamConnectionPool diff --git a/proxy/http/proxy/__init__.py b/proxy/http/proxy/__init__.py index 4e18002c..a794ba07 100644 --- a/proxy/http/proxy/__init__.py +++ b/proxy/http/proxy/__init__.py @@ -10,10 +10,9 @@ """ from .plugin import HttpProxyBasePlugin from .server import HttpProxyPlugin -from .auth import AuthPlugin + __all__ = [ 'HttpProxyBasePlugin', 'HttpProxyPlugin', - 'AuthPlugin', ] diff --git a/proxy/http/proxy/auth.py b/proxy/http/proxy/auth.py index a309d194..f2632d79 100644 --- a/proxy/http/proxy/auth.py +++ b/proxy/http/proxy/auth.py @@ -15,14 +15,12 @@ """ from typing import Optional -from ..exception import ProxyAuthenticationFailed - -from ...common.flag import flags -from ...common.constants import DEFAULT_BASIC_AUTH - from ...http import httpHeaders -from ...http.parser import HttpParser +from ..exception import ProxyAuthenticationFailed from ...http.proxy import HttpProxyBasePlugin +from ...common.flag import flags +from ...http.parser import HttpParser +from ...common.constants import DEFAULT_BASIC_AUTH flags.add_argument( diff --git a/proxy/http/proxy/plugin.py b/proxy/http/proxy/plugin.py index 9f6f1145..ed951e31 100644 --- a/proxy/http/proxy/plugin.py +++ b/proxy/http/proxy/plugin.py @@ -9,17 +9,15 @@ :license: BSD, see LICENSE for more details. """ import argparse - from abc import ABC -from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, Tuple, Optional from ..mixins import TlsInterceptionPropertyMixin - from ..parser import HttpParser -from ..descriptors import DescriptorsHandlerMixin from ..connection import HttpClientConnection - from ...core.event import EventQueue +from ..descriptors import DescriptorsHandlerMixin + if TYPE_CHECKING: # pragma: no cover from ...core.connection import UpstreamConnectionPool diff --git a/proxy/http/proxy/server.py b/proxy/http/proxy/server.py index 3008898c..10932fde 100644 --- a/proxy/http/proxy/server.py +++ b/proxy/http/proxy/server.py @@ -21,33 +21,32 @@ import socket import logging import threading import subprocess - -from typing import Optional, List, Union, Dict, cast, Any +from typing import Any, Dict, List, Union, Optional, cast from .plugin import HttpProxyBasePlugin - +from ..parser import HttpParser, httpParserTypes, httpParserStates +from ..plugin import HttpProtocolHandlerPlugin from ..headers import httpHeaders from ..methods import httpMethods -from ..protocols import httpProtocols -from ..plugin import HttpProtocolHandlerPlugin from ..exception import HttpProtocolException, ProxyConnectionFailed -from ..parser import HttpParser, httpParserStates, httpParserTypes +from ..protocols import httpProtocols from ..responses import PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT - -from ...common.types import Readables, Writables, Descriptors -from ...common.constants import DEFAULT_CA_CERT_DIR, DEFAULT_CA_CERT_FILE, DEFAULT_CA_FILE -from ...common.constants import DEFAULT_CA_KEY_FILE, DEFAULT_CA_SIGNING_KEY_FILE -from ...common.constants import COMMA, DEFAULT_HTTPS_PROXY_ACCESS_LOG_FORMAT -from ...common.constants import PROXY_AGENT_HEADER_VALUE, DEFAULT_DISABLE_HEADERS -from ...common.constants import DEFAULT_HTTP_PROXY_ACCESS_LOG_FORMAT -from ...common.constants import DEFAULT_DISABLE_HTTP_PROXY, PLUGIN_PROXY_AUTH -from ...common.utils import text_ -from ...common.pki import gen_public_key, gen_csr, sign_csr - +from ...common.pki import gen_csr, sign_csr, gen_public_key from ...core.event import eventNames -from ...core.connection import TcpServerConnection -from ...core.connection import TcpConnectionUninitializedException from ...common.flag import flags +from ...common.types import Readables, Writables, Descriptors +from ...common.utils import text_ +from ...core.connection import ( + TcpServerConnection, TcpConnectionUninitializedException, +) +from ...common.constants import ( + COMMA, DEFAULT_CA_FILE, PLUGIN_PROXY_AUTH, DEFAULT_CA_CERT_DIR, + DEFAULT_CA_KEY_FILE, DEFAULT_CA_CERT_FILE, DEFAULT_DISABLE_HEADERS, + PROXY_AGENT_HEADER_VALUE, DEFAULT_DISABLE_HTTP_PROXY, + DEFAULT_CA_SIGNING_KEY_FILE, DEFAULT_HTTP_PROXY_ACCESS_LOG_FORMAT, + DEFAULT_HTTPS_PROXY_ACCESS_LOG_FORMAT, +) + logger = logging.getLogger(__name__) diff --git a/proxy/http/responses.py b/proxy/http/responses.py index 3eaca1e6..c1e8a173 100644 --- a/proxy/http/responses.py +++ b/proxy/http/responses.py @@ -11,11 +11,10 @@ import gzip from typing import Any, Dict, Optional +from .codes import httpStatusCodes from ..common.flag import flags from ..common.utils import build_http_response -from ..common.constants import PROXY_AGENT_HEADER_VALUE, PROXY_AGENT_HEADER_KEY - -from .codes import httpStatusCodes +from ..common.constants import PROXY_AGENT_HEADER_KEY, PROXY_AGENT_HEADER_VALUE PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT = memoryview( diff --git a/proxy/http/server/__init__.py b/proxy/http/server/__init__.py index 059c2cc1..dfbaa02c 100644 --- a/proxy/http/server/__init__.py +++ b/proxy/http/server/__init__.py @@ -9,9 +9,10 @@ :license: BSD, see LICENSE for more details. """ from .web import HttpWebServerPlugin -from .pac_plugin import HttpWebServerPacFilePlugin from .plugin import HttpWebServerBasePlugin from .protocols import httpProtocolTypes +from .pac_plugin import HttpWebServerPacFilePlugin + __all__ = [ 'HttpWebServerPlugin', diff --git a/proxy/http/server/pac_plugin.py b/proxy/http/server/pac_plugin.py index 8cc0a4d0..a52f213d 100644 --- a/proxy/http/server/pac_plugin.py +++ b/proxy/http/server/pac_plugin.py @@ -12,16 +12,14 @@ pac """ -from typing import List, Tuple, Optional, Any +from typing import Any, List, Tuple, Optional from .plugin import HttpWebServerBasePlugin -from .protocols import httpProtocolTypes - from ..parser import HttpParser +from .protocols import httpProtocolTypes from ..responses import okResponse - -from ...common.utils import bytes_, text_ from ...common.flag import flags +from ...common.utils import text_, bytes_ from ...common.constants import DEFAULT_PAC_FILE, DEFAULT_PAC_FILE_URL_PATH diff --git a/proxy/http/server/plugin.py b/proxy/http/server/plugin.py index 069b0dff..62ebd3e7 100644 --- a/proxy/http/server/plugin.py +++ b/proxy/http/server/plugin.py @@ -9,16 +9,15 @@ :license: BSD, see LICENSE for more details. """ import argparse - from abc import ABC, abstractmethod -from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, List, Tuple, Optional -from ..websocket import WebsocketFrame from ..parser import HttpParser -from ..descriptors import DescriptorsHandlerMixin +from ..websocket import WebsocketFrame from ..connection import HttpClientConnection - from ...core.event import EventQueue +from ..descriptors import DescriptorsHandlerMixin + if TYPE_CHECKING: # pragma: no cover from ...core.connection import UpstreamConnectionPool diff --git a/proxy/http/server/protocols.py b/proxy/http/server/protocols.py index a561cb93..84b5d8ac 100644 --- a/proxy/http/server/protocols.py +++ b/proxy/http/server/protocols.py @@ -15,6 +15,7 @@ """ from typing import NamedTuple + HttpProtocolTypes = NamedTuple( 'HttpProtocolTypes', [ ('HTTP', int), diff --git a/proxy/http/server/web.py b/proxy/http/server/web.py index 50352171..efc734cd 100644 --- a/proxy/http/server/web.py +++ b/proxy/http/server/web.py @@ -13,25 +13,25 @@ import time import socket import logging import mimetypes - -from typing import List, Optional, Dict, Tuple, Union, Any, Pattern - -from ...common.constants import DEFAULT_STATIC_SERVER_DIR -from ...common.constants import DEFAULT_ENABLE_STATIC_SERVER, DEFAULT_ENABLE_WEB_SERVER -from ...common.constants import DEFAULT_MIN_COMPRESSION_LIMIT, DEFAULT_WEB_ACCESS_LOG_FORMAT -from ...common.utils import bytes_, text_, build_websocket_handshake_response -from ...common.types import Readables, Writables, Descriptors -from ...common.flag import flags - -from ..exception import HttpProtocolException -from ..plugin import HttpProtocolHandlerPlugin -from ..websocket import WebsocketFrame, websocketOpcodes -from ..parser import HttpParser, httpParserTypes -from ..protocols import httpProtocols -from ..responses import NOT_FOUND_RESPONSE_PKT, okResponse +from typing import Any, Dict, List, Tuple, Union, Pattern, Optional from .plugin import HttpWebServerBasePlugin +from ..parser import HttpParser, httpParserTypes +from ..plugin import HttpProtocolHandlerPlugin from .protocols import httpProtocolTypes +from ..exception import HttpProtocolException +from ..protocols import httpProtocols +from ..responses import NOT_FOUND_RESPONSE_PKT, okResponse +from ..websocket import WebsocketFrame, websocketOpcodes +from ...common.flag import flags +from ...common.types import Readables, Writables, Descriptors +from ...common.utils import text_, bytes_, build_websocket_handshake_response +from ...common.constants import ( + DEFAULT_ENABLE_WEB_SERVER, DEFAULT_STATIC_SERVER_DIR, + DEFAULT_ENABLE_STATIC_SERVER, DEFAULT_MIN_COMPRESSION_LIMIT, + DEFAULT_WEB_ACCESS_LOG_FORMAT, +) + logger = logging.getLogger(__name__) diff --git a/proxy/http/url.py b/proxy/http/url.py index 9cbdb4ae..c799efaa 100644 --- a/proxy/http/url.py +++ b/proxy/http/url.py @@ -13,12 +13,11 @@ http url """ -from typing import List, Optional, Tuple - -from ..common.constants import COLON, DEFAULT_ALLOWED_URL_SCHEMES, SLASH, AT -from ..common.utils import text_ +from typing import List, Tuple, Optional from .exception import HttpProtocolException +from ..common.utils import text_ +from ..common.constants import AT, COLON, SLASH, DEFAULT_ALLOWED_URL_SCHEMES class Url: diff --git a/proxy/http/websocket/__init__.py b/proxy/http/websocket/__init__.py index 50173873..a787535c 100644 --- a/proxy/http/websocket/__init__.py +++ b/proxy/http/websocket/__init__.py @@ -19,6 +19,7 @@ from .frame import WebsocketFrame, websocketOpcodes from .client import WebsocketClient from .plugin import WebSocketTransportBasePlugin + __all__ = [ 'websocketOpcodes', 'WebsocketFrame', diff --git a/proxy/http/websocket/client.py b/proxy/http/websocket/client.py index 498df469..f398b5d8 100644 --- a/proxy/http/websocket/client.py +++ b/proxy/http/websocket/client.py @@ -13,16 +13,17 @@ import base64 import socket import secrets import selectors - -from typing import Optional, Union, Callable +from typing import Union, Callable, Optional from .frame import WebsocketFrame - -from ..parser import httpParserTypes, HttpParser - -from ...common.constants import DEFAULT_BUFFER_SIZE, DEFAULT_SELECTOR_SELECT_TIMEOUT -from ...common.utils import new_socket_connection, build_websocket_handshake_request, text_ -from ...core.connection import tcpConnectionTypes, TcpConnection +from ..parser import HttpParser, httpParserTypes +from ...common.utils import ( + text_, new_socket_connection, build_websocket_handshake_request, +) +from ...core.connection import TcpConnection, tcpConnectionTypes +from ...common.constants import ( + DEFAULT_BUFFER_SIZE, DEFAULT_SELECTOR_SELECT_TIMEOUT, +) class WebsocketClient(TcpConnection): diff --git a/proxy/http/websocket/frame.py b/proxy/http/websocket/frame.py index e1749059..7cccbcb0 100644 --- a/proxy/http/websocket/frame.py +++ b/proxy/http/websocket/frame.py @@ -19,10 +19,9 @@ import io import base64 import struct import hashlib -import secrets import logging - -from typing import TypeVar, Type, Optional, NamedTuple +import secrets +from typing import Type, TypeVar, Optional, NamedTuple WebsocketOpcodes = NamedTuple( diff --git a/proxy/http/websocket/plugin.py b/proxy/http/websocket/plugin.py index f7f27485..be544773 100644 --- a/proxy/http/websocket/plugin.py +++ b/proxy/http/websocket/plugin.py @@ -8,15 +8,15 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -import argparse import json +import argparse from abc import ABC, abstractmethod -from typing import TYPE_CHECKING, List, Dict, Any - -from ...common.utils import bytes_ -from ...core.event import EventQueue +from typing import TYPE_CHECKING, Any, Dict, List from . import WebsocketFrame +from ...core.event import EventQueue +from ...common.utils import bytes_ + if TYPE_CHECKING: # pragma: no cover from ..connection import HttpClientConnection diff --git a/proxy/http/websocket/transport.py b/proxy/http/websocket/transport.py index b18a8064..463195ef 100644 --- a/proxy/http/websocket/transport.py +++ b/proxy/http/websocket/transport.py @@ -10,15 +10,14 @@ """ import json import logging -from typing import List, Tuple, Any, Dict - -from ...common.utils import bytes_ - -from ..server import httpProtocolTypes, HttpWebServerBasePlugin -from ..parser import HttpParser +from typing import Any, Dict, List, Tuple from .frame import WebsocketFrame from .plugin import WebSocketTransportBasePlugin +from ..parser import HttpParser +from ..server import HttpWebServerBasePlugin, httpProtocolTypes +from ...common.utils import bytes_ + logger = logging.getLogger(__name__) diff --git a/proxy/plugin/__init__.py b/proxy/plugin/__init__.py index 578bc3bc..e76a2534 100644 --- a/proxy/plugin/__init__.py +++ b/proxy/plugin/__init__.py @@ -13,21 +13,22 @@ Cloudflare """ from .cache import CacheResponsesPlugin, BaseCacheResponsesPlugin -from .filter_by_upstream import FilterByUpstreamHostPlugin -from .man_in_the_middle import ManInTheMiddlePlugin -from .mock_rest_api import ProposedRestApiPlugin -from .modify_post_data import ModifyPostDataPlugin -from .redirect_to_custom_server import RedirectToCustomServerPlugin from .shortlink import ShortLinkPlugin -from .web_server_route import WebServerPlugin -from .reverse_proxy import ReverseProxyPlugin from .proxy_pool import ProxyPoolPlugin +from .program_name import ProgramNamePlugin +from .mock_rest_api import ProposedRestApiPlugin +from .reverse_proxy import ReverseProxyPlugin +from .cloudflare_dns import CloudflareDnsResolverPlugin +from .modify_post_data import ModifyPostDataPlugin +from .web_server_route import WebServerPlugin +from .man_in_the_middle import ManInTheMiddlePlugin +from .filter_by_upstream import FilterByUpstreamHostPlugin +from .custom_dns_resolver import CustomDnsResolverPlugin from .filter_by_client_ip import FilterByClientIpPlugin from .filter_by_url_regex import FilterByURLRegexPlugin from .modify_chunk_response import ModifyChunkResponsePlugin -from .custom_dns_resolver import CustomDnsResolverPlugin -from .cloudflare_dns import CloudflareDnsResolverPlugin -from .program_name import ProgramNamePlugin +from .redirect_to_custom_server import RedirectToCustomServerPlugin + __all__ = [ 'CacheResponsesPlugin', diff --git a/proxy/plugin/cache/__init__.py b/proxy/plugin/cache/__init__.py index f3bfb84b..ce6cfe42 100644 --- a/proxy/plugin/cache/__init__.py +++ b/proxy/plugin/cache/__init__.py @@ -11,6 +11,7 @@ from .base import BaseCacheResponsesPlugin from .cache_responses import CacheResponsesPlugin + __all__ = [ 'BaseCacheResponsesPlugin', 'CacheResponsesPlugin', diff --git a/proxy/plugin/cache/base.py b/proxy/plugin/cache/base.py index 4451adf1..278f4eed 100644 --- a/proxy/plugin/cache/base.py +++ b/proxy/plugin/cache/base.py @@ -9,11 +9,12 @@ :license: BSD, see LICENSE for more details. """ import logging -from typing import Optional, Any +from typing import Any, Optional -from ...http.parser import HttpParser -from ...http.proxy import HttpProxyBasePlugin from .store.base import CacheStore +from ...http.proxy import HttpProxyBasePlugin +from ...http.parser import HttpParser + logger = logging.getLogger(__name__) diff --git a/proxy/plugin/cache/cache_responses.py b/proxy/plugin/cache/cache_responses.py index 200a60cb..e9ccd126 100644 --- a/proxy/plugin/cache/cache_responses.py +++ b/proxy/plugin/cache/cache_responses.py @@ -11,8 +11,8 @@ import multiprocessing from typing import Any -from .store.disk import OnDiskCacheStore from .base import BaseCacheResponsesPlugin +from .store.disk import OnDiskCacheStore class CacheResponsesPlugin(BaseCacheResponsesPlugin): diff --git a/proxy/plugin/cache/store/disk.py b/proxy/plugin/cache/store/disk.py index d4e6b9dc..8ea54b8c 100644 --- a/proxy/plugin/cache/store/disk.py +++ b/proxy/plugin/cache/store/disk.py @@ -8,16 +8,16 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -import logging import os +import logging import tempfile -from typing import Optional, BinaryIO - -from ....common.flag import flags -from ....common.utils import text_ -from ....http.parser import HttpParser +from typing import BinaryIO, Optional from .base import CacheStore +from ....common.flag import flags +from ....http.parser import HttpParser +from ....common.utils import text_ + logger = logging.getLogger(__name__) diff --git a/proxy/plugin/cloudflare_dns.py b/proxy/plugin/cloudflare_dns.py index 781cb8d4..9c459b56 100644 --- a/proxy/plugin/cloudflare_dns.py +++ b/proxy/plugin/cloudflare_dns.py @@ -16,15 +16,17 @@ """ import logging + try: import httpx except ImportError: # pragma: no cover pass -from typing import Optional, Tuple +from typing import Tuple, Optional -from ..common.flag import flags from ..http.proxy import HttpProxyBasePlugin +from ..common.flag import flags + logger = logging.getLogger(__name__) diff --git a/proxy/plugin/custom_dns_resolver.py b/proxy/plugin/custom_dns_resolver.py index f40a93e8..5ee7aded 100644 --- a/proxy/plugin/custom_dns_resolver.py +++ b/proxy/plugin/custom_dns_resolver.py @@ -13,8 +13,7 @@ dns """ import socket - -from typing import Optional, Tuple +from typing import Tuple, Optional from ..http.proxy import HttpProxyBasePlugin diff --git a/proxy/plugin/filter_by_client_ip.py b/proxy/plugin/filter_by_client_ip.py index fba98101..2f199042 100644 --- a/proxy/plugin/filter_by_client_ip.py +++ b/proxy/plugin/filter_by_client_ip.py @@ -14,11 +14,10 @@ """ from typing import Optional -from ..common.flag import flags - from ..http import httpStatusCodes -from ..http.parser import HttpParser from ..http.proxy import HttpProxyBasePlugin +from ..common.flag import flags +from ..http.parser import HttpParser from ..http.exception import HttpRequestRejected diff --git a/proxy/plugin/filter_by_upstream.py b/proxy/plugin/filter_by_upstream.py index a257fdf2..39f70859 100644 --- a/proxy/plugin/filter_by_upstream.py +++ b/proxy/plugin/filter_by_upstream.py @@ -10,12 +10,11 @@ """ from typing import Optional -from ..common.utils import text_ -from ..common.flag import flags - from ..http import httpStatusCodes -from ..http.parser import HttpParser from ..http.proxy import HttpProxyBasePlugin +from ..common.flag import flags +from ..http.parser import HttpParser +from ..common.utils import text_ from ..http.exception import HttpRequestRejected diff --git a/proxy/plugin/filter_by_url_regex.py b/proxy/plugin/filter_by_url_regex.py index 3d12ad34..587c6f63 100644 --- a/proxy/plugin/filter_by_url_regex.py +++ b/proxy/plugin/filter_by_url_regex.py @@ -12,20 +12,18 @@ url """ +import re import json import logging - -from typing import Optional, List, Dict, Any - -from ..common.flag import flags -from ..common.utils import text_ +from typing import Any, Dict, List, Optional from ..http import httpStatusCodes -from ..http.parser import HttpParser from ..http.proxy import HttpProxyBasePlugin +from ..common.flag import flags +from ..http.parser import HttpParser +from ..common.utils import text_ from ..http.exception import HttpRequestRejected -import re logger = logging.getLogger(__name__) diff --git a/proxy/plugin/man_in_the_middle.py b/proxy/plugin/man_in_the_middle.py index d571f25a..1ceb3a21 100644 --- a/proxy/plugin/man_in_the_middle.py +++ b/proxy/plugin/man_in_the_middle.py @@ -10,8 +10,8 @@ """ from typing import Optional -from ..http.responses import okResponse from ..http.proxy import HttpProxyBasePlugin +from ..http.responses import okResponse class ManInTheMiddlePlugin(HttpProxyBasePlugin): diff --git a/proxy/plugin/mock_rest_api.py b/proxy/plugin/mock_rest_api.py index 56cac4cb..2588ce05 100644 --- a/proxy/plugin/mock_rest_api.py +++ b/proxy/plugin/mock_rest_api.py @@ -15,11 +15,10 @@ import json from typing import Optional -from ..common.utils import bytes_, text_ - -from ..http.responses import okResponse, NOT_FOUND_RESPONSE_PKT -from ..http.parser import HttpParser from ..http.proxy import HttpProxyBasePlugin +from ..http.parser import HttpParser +from ..common.utils import text_, bytes_ +from ..http.responses import NOT_FOUND_RESPONSE_PKT, okResponse class ProposedRestApiPlugin(HttpProxyBasePlugin): diff --git a/proxy/plugin/modify_chunk_response.py b/proxy/plugin/modify_chunk_response.py index a0838da5..16171e1f 100644 --- a/proxy/plugin/modify_chunk_response.py +++ b/proxy/plugin/modify_chunk_response.py @@ -10,8 +10,8 @@ """ from typing import Any, Optional -from ..http.parser import HttpParser, httpParserTypes from ..http.proxy import HttpProxyBasePlugin +from ..http.parser import HttpParser, httpParserTypes class ModifyChunkResponsePlugin(HttpProxyBasePlugin): diff --git a/proxy/plugin/modify_post_data.py b/proxy/plugin/modify_post_data.py index 21be9d35..d4b5ba61 100644 --- a/proxy/plugin/modify_post_data.py +++ b/proxy/plugin/modify_post_data.py @@ -10,11 +10,10 @@ """ from typing import Optional -from ..common.utils import bytes_ - from ..http import httpMethods -from ..http.parser import HttpParser from ..http.proxy import HttpProxyBasePlugin +from ..http.parser import HttpParser +from ..common.utils import bytes_ class ModifyPostDataPlugin(HttpProxyBasePlugin): diff --git a/proxy/plugin/program_name.py b/proxy/plugin/program_name.py index b8e205b4..0aaadcb8 100644 --- a/proxy/plugin/program_name.py +++ b/proxy/plugin/program_name.py @@ -10,15 +10,13 @@ """ import os import subprocess - from typing import Any, Dict, Optional +from ..http.proxy import HttpProxyBasePlugin +from ..http.parser import HttpParser from ..common.utils import text_ from ..common.constants import IS_WINDOWS -from ..http.parser import HttpParser -from ..http.proxy import HttpProxyBasePlugin - class ProgramNamePlugin(HttpProxyBasePlugin): """Tries to identify the application connecting to the diff --git a/proxy/plugin/proxy_pool.py b/proxy/plugin/proxy_pool.py index 41ffe5b7..6e040347 100644 --- a/proxy/plugin/proxy_pool.py +++ b/proxy/plugin/proxy_pool.py @@ -12,19 +12,19 @@ import base64 import random import logging import ipaddress +from typing import Any, Dict, List, Optional -from typing import Dict, List, Optional, Any - -from ..common.flag import flags -from ..common.utils import text_, bytes_ -from ..common.constants import COLON, LOCAL_INTERFACE_HOSTNAMES, ANY_INTERFACE_HOSTNAMES - -from ..http import Url, httpMethods, httpHeaders -from ..http.parser import HttpParser -from ..http.exception import HttpProtocolException -from ..http.proxy import HttpProxyBasePlugin - +from ..http import Url, httpHeaders, httpMethods from ..core.base import TcpUpstreamConnectionHandler +from ..http.proxy import HttpProxyBasePlugin +from ..common.flag import flags +from ..http.parser import HttpParser +from ..common.utils import text_, bytes_ +from ..http.exception import HttpProtocolException +from ..common.constants import ( + COLON, ANY_INTERFACE_HOSTNAMES, LOCAL_INTERFACE_HOSTNAMES, +) + logger = logging.getLogger(__name__) diff --git a/proxy/plugin/redirect_to_custom_server.py b/proxy/plugin/redirect_to_custom_server.py index 82f4b0bf..d1c893bd 100644 --- a/proxy/plugin/redirect_to_custom_server.py +++ b/proxy/plugin/redirect_to_custom_server.py @@ -8,8 +8,8 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -from urllib import parse as urlparse from typing import Optional +from urllib import parse as urlparse from ..http.proxy import HttpProxyBasePlugin from ..http.parser import HttpParser diff --git a/proxy/plugin/reverse_proxy.py b/proxy/plugin/reverse_proxy.py index 26ebbb6a..e21442e7 100644 --- a/proxy/plugin/reverse_proxy.py +++ b/proxy/plugin/reverse_proxy.py @@ -10,18 +10,16 @@ """ import random import logging - -from typing import List, Tuple, Any, Dict, Optional - -from ..common.utils import text_ -from ..common.constants import DEFAULT_HTTPS_PORT, DEFAULT_HTTP_PORT +from typing import Any, Dict, List, Tuple, Optional from ..http import Url -from ..http.exception import HttpProtocolException +from ..core.base import TcpUpstreamConnectionHandler from ..http.parser import HttpParser from ..http.server import HttpWebServerBasePlugin, httpProtocolTypes +from ..common.utils import text_ +from ..http.exception import HttpProtocolException +from ..common.constants import DEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT -from ..core.base import TcpUpstreamConnectionHandler logger = logging.getLogger(__name__) diff --git a/proxy/plugin/shortlink.py b/proxy/plugin/shortlink.py index 11b7a7d8..0f5840ba 100644 --- a/proxy/plugin/shortlink.py +++ b/proxy/plugin/shortlink.py @@ -14,11 +14,10 @@ """ from typing import Optional -from ..common.constants import DOT, SLASH - -from ..http.responses import NOT_FOUND_RESPONSE_PKT, seeOthersResponse -from ..http.parser import HttpParser from ..http.proxy import HttpProxyBasePlugin +from ..http.parser import HttpParser +from ..http.responses import NOT_FOUND_RESPONSE_PKT, seeOthersResponse +from ..common.constants import DOT, SLASH class ShortLinkPlugin(HttpProxyBasePlugin): diff --git a/proxy/plugin/web_server_route.py b/proxy/plugin/web_server_route.py index d4ad4eff..205a8f9b 100644 --- a/proxy/plugin/web_server_route.py +++ b/proxy/plugin/web_server_route.py @@ -11,9 +11,10 @@ import logging from typing import List, Tuple -from ..http.responses import okResponse from ..http.parser import HttpParser from ..http.server import HttpWebServerBasePlugin, httpProtocolTypes +from ..http.responses import okResponse + logger = logging.getLogger(__name__) diff --git a/proxy/proxy.py b/proxy/proxy.py index e2e2af15..8f04b2af 100644 --- a/proxy/proxy.py +++ b/proxy/proxy.py @@ -13,22 +13,20 @@ import sys import time import signal import logging +from typing import Any, List, Optional -from typing import List, Optional, Any - -from proxy.core.ssh.listener import SshTunnelListener - +from .core.ssh import SshTunnelListener, SshHttpProtocolHandler from .core.work import ThreadlessPool from .core.event import EventManager -from .core.ssh import SshHttpProtocolHandler -from .core.acceptor import AcceptorPool, Listener - -from .common.utils import bytes_ from .common.flag import FlagParser, flags -from .common.constants import DEFAULT_ENABLE_SSH_TUNNEL, DEFAULT_LOG_FILE -from .common.constants import DEFAULT_OPEN_FILE_LIMIT, DEFAULT_PLUGINS, DEFAULT_VERSION -from .common.constants import DEFAULT_ENABLE_DASHBOARD, DEFAULT_WORK_KLASS, DEFAULT_PID_FILE -from .common.constants import DEFAULT_LOG_FORMAT, DEFAULT_LOG_LEVEL, IS_WINDOWS +from .common.utils import bytes_ +from .core.acceptor import Listener, AcceptorPool +from .common.constants import ( + IS_WINDOWS, DEFAULT_PLUGINS, DEFAULT_VERSION, DEFAULT_LOG_FILE, + DEFAULT_PID_FILE, DEFAULT_LOG_LEVEL, DEFAULT_LOG_FORMAT, + DEFAULT_WORK_KLASS, DEFAULT_OPEN_FILE_LIMIT, DEFAULT_ENABLE_DASHBOARD, + DEFAULT_ENABLE_SSH_TUNNEL, +) logger = logging.getLogger(__name__) diff --git a/proxy/testing/__init__.py b/proxy/testing/__init__.py index e841545b..f0b7ffe5 100644 --- a/proxy/testing/__init__.py +++ b/proxy/testing/__init__.py @@ -10,6 +10,7 @@ """ from .test_case import TestCase + __all__ = [ 'TestCase', ] diff --git a/proxy/testing/test_case.py b/proxy/testing/test_case.py index f6d75ce0..18c75216 100644 --- a/proxy/testing/test_case.py +++ b/proxy/testing/test_case.py @@ -8,15 +8,16 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -import contextlib import time +import contextlib +from typing import Any, List, Optional, Generator + import unittest -from typing import Optional, List, Generator, Any from ..proxy import Proxy -from ..common.constants import DEFAULT_TIMEOUT -from ..common.utils import new_socket_connection from ..plugin import CacheResponsesPlugin +from ..common.utils import new_socket_connection +from ..common.constants import DEFAULT_TIMEOUT class TestCase(unittest.TestCase): diff --git a/tests/http/exceptions/test_http_proxy_auth_failed.py b/tests/http/exceptions/test_http_proxy_auth_failed.py index 5d74aecb..9dfbe214 100644 --- a/tests/http/exceptions/test_http_proxy_auth_failed.py +++ b/tests/http/exceptions/test_http_proxy_auth_failed.py @@ -14,7 +14,7 @@ import pytest from pytest_mock import MockerFixture -from proxy.http import HttpProtocolHandler, httpHeaders, HttpClientConnection +from proxy.http import HttpProtocolHandler, HttpClientConnection, httpHeaders from proxy.common.flag import FlagParser from proxy.common.utils import build_http_request from proxy.http.responses import PROXY_AUTH_FAILED_RESPONSE_PKT diff --git a/tests/http/parser/test_http_parser.py b/tests/http/parser/test_http_parser.py index 562574d4..68510415 100644 --- a/tests/http/parser/test_http_parser.py +++ b/tests/http/parser/test_http_parser.py @@ -16,8 +16,8 @@ from proxy.common.utils import ( bytes_, find_http_line, build_http_header, build_http_request, ) from proxy.http.exception import HttpProtocolException -from proxy.http.responses import okResponse from proxy.http.protocols import httpProtocols +from proxy.http.responses import okResponse from proxy.common.constants import CRLF, HTTP_1_0 diff --git a/tests/http/proxy/test_http_proxy_tls_interception.py b/tests/http/proxy/test_http_proxy_tls_interception.py index b13c748d..e7e166f3 100644 --- a/tests/http/proxy/test_http_proxy_tls_interception.py +++ b/tests/http/proxy/test_http_proxy_tls_interception.py @@ -19,7 +19,7 @@ from unittest import mock from pytest_mock import MockerFixture -from proxy.http import HttpProtocolHandler, httpMethods, HttpClientConnection +from proxy.http import HttpProtocolHandler, HttpClientConnection, httpMethods from proxy.http.proxy import HttpProxyPlugin from proxy.common.flag import FlagParser from proxy.common.utils import bytes_, build_http_request diff --git a/tests/http/test_protocol_handler.py b/tests/http/test_protocol_handler.py index 707725ab..a2425fd7 100644 --- a/tests/http/test_protocol_handler.py +++ b/tests/http/test_protocol_handler.py @@ -17,7 +17,7 @@ from unittest import mock from pytest_mock import MockerFixture -from proxy.http import HttpProtocolHandler, httpHeaders, HttpClientConnection +from proxy.http import HttpProtocolHandler, HttpClientConnection, httpHeaders from proxy.http.proxy import HttpProxyPlugin from proxy.common.flag import FlagParser from proxy.http.parser import HttpParser, httpParserTypes, httpParserStates @@ -25,8 +25,8 @@ from proxy.common.utils import bytes_ from proxy.common.plugins import Plugins from proxy.common.version import __version__ from proxy.http.responses import ( - BAD_GATEWAY_RESPONSE_PKT, PROXY_AUTH_FAILED_RESPONSE_PKT, - PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT, BAD_REQUEST_RESPONSE_PKT, + BAD_GATEWAY_RESPONSE_PKT, BAD_REQUEST_RESPONSE_PKT, + PROXY_AUTH_FAILED_RESPONSE_PKT, PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT, ) from proxy.common.constants import ( CRLF, PLUGIN_HTTP_PROXY, PLUGIN_PROXY_AUTH, PLUGIN_WEB_SERVER, diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index e8fd9b7c..93a88b73 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -11,13 +11,14 @@ Test the simplest proxy use scenario for smoke. """ import time -import pytest import tempfile import subprocess - +from typing import Any, List, Generator from pathlib import Path -from typing import Any, Generator, List -from subprocess import Popen, check_output as _check_output +from subprocess import Popen +from subprocess import check_output as _check_output + +import pytest from proxy.common.constants import IS_WINDOWS diff --git a/tests/plugin/test_http_proxy_plugins.py b/tests/plugin/test_http_proxy_plugins.py index 742b7fd7..5b9e30d1 100644 --- a/tests/plugin/test_http_proxy_plugins.py +++ b/tests/plugin/test_http_proxy_plugins.py @@ -20,7 +20,9 @@ from unittest import mock from pytest_mock import MockerFixture -from proxy.http import HttpProtocolHandler, httpStatusCodes, HttpClientConnection +from proxy.http import ( + HttpProtocolHandler, HttpClientConnection, httpStatusCodes, +) from proxy.plugin import ProposedRestApiPlugin, RedirectToCustomServerPlugin from proxy.http.proxy import HttpProxyPlugin from proxy.common.flag import FlagParser diff --git a/tests/plugin/test_http_proxy_plugins_with_tls_interception.py b/tests/plugin/test_http_proxy_plugins_with_tls_interception.py index a985f0c2..77345a41 100644 --- a/tests/plugin/test_http_proxy_plugins_with_tls_interception.py +++ b/tests/plugin/test_http_proxy_plugins_with_tls_interception.py @@ -18,7 +18,7 @@ import pytest from pytest_mock import MockerFixture -from proxy.http import HttpProtocolHandler, httpMethods, HttpClientConnection +from proxy.http import HttpProtocolHandler, HttpClientConnection, httpMethods from proxy.http.proxy import HttpProxyPlugin from proxy.common.flag import FlagParser from proxy.http.parser import HttpParser, httpParserTypes diff --git a/tests/test_main.py b/tests/test_main.py index 070b134b..f3b7a85b 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -17,20 +17,21 @@ from unittest import mock from proxy.proxy import main, entry_point from proxy.common.utils import bytes_ from proxy.common.constants import ( # noqa: WPS450 - DEFAULT_CA_CERT_DIR, DEFAULT_ENABLE_SSH_TUNNEL, DEFAULT_PORT, DEFAULT_PLUGINS, DEFAULT_TIMEOUT, DEFAULT_KEY_FILE, + DEFAULT_PORT, DEFAULT_PLUGINS, DEFAULT_TIMEOUT, DEFAULT_KEY_FILE, DEFAULT_LOG_FILE, DEFAULT_PAC_FILE, DEFAULT_PID_FILE, PLUGIN_DASHBOARD, DEFAULT_CERT_FILE, DEFAULT_LOG_LEVEL, DEFAULT_PORT_FILE, PLUGIN_HTTP_PROXY, PLUGIN_PROXY_AUTH, PLUGIN_WEB_SERVER, DEFAULT_BASIC_AUTH, DEFAULT_LOG_FORMAT, DEFAULT_THREADLESS, DEFAULT_WORK_KLASS, - DEFAULT_CA_KEY_FILE, DEFAULT_NUM_WORKERS, DEFAULT_CA_CERT_FILE, - DEFAULT_ENABLE_EVENTS, DEFAULT_IPV6_HOSTNAME, DEFAULT_NUM_ACCEPTORS, - DEFAULT_LOCAL_EXECUTOR, PLUGIN_INSPECT_TRAFFIC, DEFAULT_ENABLE_DEVTOOLS, - DEFAULT_OPEN_FILE_LIMIT, DEFAULT_DEVTOOLS_WS_PATH, + DEFAULT_CA_CERT_DIR, DEFAULT_CA_KEY_FILE, DEFAULT_NUM_WORKERS, + DEFAULT_CA_CERT_FILE, DEFAULT_ENABLE_EVENTS, DEFAULT_IPV6_HOSTNAME, + DEFAULT_NUM_ACCEPTORS, DEFAULT_LOCAL_EXECUTOR, PLUGIN_INSPECT_TRAFFIC, + DEFAULT_ENABLE_DEVTOOLS, DEFAULT_OPEN_FILE_LIMIT, DEFAULT_DEVTOOLS_WS_PATH, DEFAULT_ENABLE_DASHBOARD, PLUGIN_DEVTOOLS_PROTOCOL, - DEFAULT_ENABLE_WEB_SERVER, DEFAULT_DISABLE_HTTP_PROXY, - PLUGIN_WEBSOCKET_TRANSPORT, DEFAULT_CA_SIGNING_KEY_FILE, - DEFAULT_CLIENT_RECVBUF_SIZE, DEFAULT_SERVER_RECVBUF_SIZE, - DEFAULT_ENABLE_STATIC_SERVER, _env_threadless_compliant, + DEFAULT_ENABLE_SSH_TUNNEL, DEFAULT_ENABLE_WEB_SERVER, + DEFAULT_DISABLE_HTTP_PROXY, PLUGIN_WEBSOCKET_TRANSPORT, + DEFAULT_CA_SIGNING_KEY_FILE, DEFAULT_CLIENT_RECVBUF_SIZE, + DEFAULT_SERVER_RECVBUF_SIZE, DEFAULT_ENABLE_STATIC_SERVER, + _env_threadless_compliant, )