Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
8 changes: 4 additions & 4 deletions python_proxy_headers/autoscraper_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions python_proxy_headers/httpx_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions test_header_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
20 changes: 10 additions & 10 deletions test_proxy_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down