diff --git a/pyproject.toml b/pyproject.toml index 06631f6..772c721 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,5 +63,5 @@ Documentation = "https://python-proxy-headers.readthedocs.io/en/latest/" ProxyMesh = "https://proxymesh.com" [tool.ruff.lint] -# Pre-0.16 default set; widen in follow-up PRs (PLC0415, T201). -select = ["E4", "E7", "E9", "F"] +# Pre-0.16 default set, plus no new inline imports and lazy log args. +select = ["E4", "E7", "E9", "F", "PLC0415", "G004"] diff --git a/python_proxy_headers/autoscraper_proxy.py b/python_proxy_headers/autoscraper_proxy.py index 3a54668..f8af6b4 100644 --- a/python_proxy_headers/autoscraper_proxy.py +++ b/python_proxy_headers/autoscraper_proxy.py @@ -169,9 +169,9 @@ def _get_soup_with_proxy(self, url=None, html=None, request_args=None): Returns: BeautifulSoup object """ - from html import unescape - from bs4 import BeautifulSoup - from autoscraper.utils import normalize + from html import unescape # noqa: PLC0415 + from bs4 import BeautifulSoup # noqa: PLC0415 + from autoscraper.utils import normalize # noqa: PLC0415 if html: html = normalize(unescape(html)) @@ -209,7 +209,7 @@ def build( Returns: List of similar results """ - from autoscraper.utils import normalize, unique_hashable, unique_stack_list + from autoscraper.utils import normalize, unique_hashable, unique_stack_list # noqa: PLC0415 if not wanted_list and not (wanted_dict and any(wanted_dict.values())): raise ValueError("No targets were supplied") diff --git a/python_proxy_headers/httpx_proxy.py b/python_proxy_headers/httpx_proxy.py index bb26310..2b35005 100644 --- a/python_proxy_headers/httpx_proxy.py +++ b/python_proxy_headers/httpx_proxy.py @@ -85,7 +85,7 @@ def handle_request(self, request): # Create the HTTP/1.1 or HTTP/2 connection if http2_negotiated or (self._http2 and not self._http1): - from httpcore._sync.http2 import HTTP2Connection + from httpcore._sync.http2 import HTTP2Connection # noqa: PLC0415 self._connection = HTTP2Connection( origin=self._remote_origin, @@ -175,7 +175,7 @@ async def handle_async_request(self, request): # Create the HTTP/1.1 or HTTP/2 connection if http2_negotiated or (self._http2 and not self._http1): - from httpcore._async.http2 import AsyncHTTP2Connection + from httpcore._async.http2 import AsyncHTTP2Connection # noqa: PLC0415 self._connection = AsyncHTTP2Connection( origin=self._remote_origin, diff --git a/test_header_security.py b/test_header_security.py index a9a93ba..23ff38d 100644 --- a/test_header_security.py +++ b/test_header_security.py @@ -44,7 +44,7 @@ def test_rejects_nul(self) -> None: validate_headers({"X-ProxyMesh-Country": "US\x00evil"}) def test_proxy_from_url_rejects_crlf(self) -> None: - from python_proxy_headers.urllib3_proxy_manager import proxy_from_url + from python_proxy_headers.urllib3_proxy_manager import proxy_from_url # noqa: PLC0415 with self.assertRaises(ValueError): proxy_from_url( @@ -55,15 +55,15 @@ def test_proxy_from_url_rejects_crlf(self) -> None: ) def test_requests_adapter_rejects_crlf(self) -> None: - from python_proxy_headers.requests_adapter import ProxySession + from python_proxy_headers.requests_adapter import ProxySession # noqa: PLC0415 with self.assertRaises(ValueError): ProxySession(proxy_headers={"X-ProxyMesh-Country": "US\r\nX-Injected: pwned"}) def test_pycurl_rejects_crlf(self) -> None: try: - import pycurl - from python_proxy_headers.pycurl_proxy import set_proxy_headers + import pycurl # noqa: PLC0415 + from python_proxy_headers.pycurl_proxy import set_proxy_headers # noqa: PLC0415 except ImportError: self.skipTest("pycurl is not installed") curl = pycurl.Curl() @@ -99,7 +99,7 @@ def test_rejects_non_http_url_schemes(self) -> None: def test_pycurl_request_rejects_file_scheme(self) -> None: try: - from python_proxy_headers.pycurl_proxy import get, request + from python_proxy_headers.pycurl_proxy import get, request # noqa: PLC0415 except ImportError: self.skipTest("pycurl is not installed") with self.assertRaises(ValueError): @@ -111,7 +111,7 @@ def test_pycurl_request_rejects_file_scheme(self) -> None: def test_pycurl_request_rejects_origin_header_and_method_crlf(self) -> None: try: - from python_proxy_headers.pycurl_proxy import request + from python_proxy_headers.pycurl_proxy import request # noqa: PLC0415 except ImportError: self.skipTest("pycurl is not installed") with self.assertRaises(ValueError): @@ -320,8 +320,8 @@ def _run_proxy(self) -> None: class ConnectMergeIntegrationTests(unittest.TestCase): def test_urllib3_does_not_copy_hostile_connect_headers(self) -> None: - import urllib3 - from python_proxy_headers.requests_adapter import ProxySession + import urllib3 # noqa: PLC0415 + from python_proxy_headers.requests_adapter import ProxySession # noqa: PLC0415 urllib3.disable_warnings() helper = _LocalHttpsProxy( @@ -355,7 +355,7 @@ def test_urllib3_does_not_copy_hostile_connect_headers(self) -> None: helper.close() def test_urllib3_does_not_send_injected_connect_header(self) -> None: - from python_proxy_headers.urllib3_proxy_manager import proxy_from_url + from python_proxy_headers.urllib3_proxy_manager import proxy_from_url # noqa: PLC0415 helper = _LocalHttpsProxy(b"") helper.start() diff --git a/test_proxy_headers.py b/test_proxy_headers.py index 8e9fc4b..7fb9e56 100755 --- a/test_proxy_headers.py +++ b/test_proxy_headers.py @@ -174,7 +174,7 @@ class Urllib3Test(ModuleTest): def test(self, config: TestConfig) -> TestResult: try: - from python_proxy_headers.urllib3_proxy_manager import proxy_from_url + from python_proxy_headers.urllib3_proxy_manager import proxy_from_url # noqa: PLC0415 # Create proxy manager (ProxyHeaderManager) with optional proxy headers manager = proxy_from_url( @@ -229,7 +229,7 @@ class RequestsTest(ModuleTest): def test(self, config: TestConfig) -> TestResult: try: - from python_proxy_headers.requests_adapter import ProxySession + from python_proxy_headers.requests_adapter import ProxySession # noqa: PLC0415 # Create session with optional proxy headers to send with ProxySession(proxy_headers=config.proxy_headers_to_send or None) as session: @@ -284,9 +284,9 @@ class AiohttpTest(ModuleTest): def test(self, config: TestConfig) -> TestResult: try: - import asyncio - from python_proxy_headers.aiohttp_proxy import ProxyClientSession - from multidict import CIMultiDict + import asyncio # noqa: PLC0415 + from python_proxy_headers.aiohttp_proxy import ProxyClientSession # noqa: PLC0415 + from multidict import CIMultiDict # noqa: PLC0415 async def _test_async(): # ProxyClientSession automatically includes ProxyTCPConnector @@ -351,8 +351,8 @@ class HttpxTest(ModuleTest): def test(self, config: TestConfig) -> TestResult: try: - from python_proxy_headers.httpx_proxy import HTTPProxyTransport - import httpx + from python_proxy_headers.httpx_proxy import HTTPProxyTransport # noqa: PLC0415 + import httpx # noqa: PLC0415 # Build proxy with optional headers proxy_headers_to_send = config.proxy_headers_to_send @@ -411,7 +411,7 @@ class PycurlTest(ModuleTest): def test(self, config: TestConfig) -> TestResult: try: - from python_proxy_headers.pycurl_proxy import get + from python_proxy_headers.pycurl_proxy import get # noqa: PLC0415 # Make request using high-level API response = get( @@ -465,7 +465,7 @@ class CloudscraperTest(ModuleTest): def test(self, config: TestConfig) -> TestResult: try: - from python_proxy_headers.cloudscraper_proxy import create_scraper + from python_proxy_headers.cloudscraper_proxy import create_scraper # noqa: PLC0415 # Create scraper with optional proxy headers to send scraper = create_scraper(proxy_headers=config.proxy_headers_to_send or None) @@ -520,7 +520,7 @@ class AutoscraperTest(ModuleTest): def test(self, config: TestConfig) -> TestResult: try: - from python_proxy_headers.autoscraper_proxy import ProxyAutoScraper + from python_proxy_headers.autoscraper_proxy import ProxyAutoScraper # noqa: PLC0415 # Create scraper with optional proxy headers to send scraper = ProxyAutoScraper(proxy_headers=config.proxy_headers_to_send or None)