Skip to content

Commit a508c62

Browse files
committed
feat(proxy-checker): make probe URL configurable and relax TLS typing
- add optional `test_url` parameter to `ProxyChecker.check_proxy` so callers can override probe URL (falls back to google) - remove module-level `PROBE_URL` constant - relax `tls` annotation to accept Literal values or plain `str` - use `test_url or "https://www.google.com"` when calling `send_query` - reformat docstring indentation for `check_proxy`
1 parent 9fb23e1 commit a508c62

1 file changed

Lines changed: 42 additions & 43 deletions

File tree

‎proxy_checker/ProxyChecker.py‎

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
)
1717
REMOTE_ADDR_REGEX = re.compile(r"REMOTE_ADDR = (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})")
1818

19-
PROBE_URL = "https://www.google.com"
20-
2119

2220
class ProxyChecker:
2321
def __init__(self, timeout: int = 30000, verbose: bool = False):
@@ -56,54 +54,55 @@ def check_proxy(
5654
check_all_protocols: bool = False,
5755
protocol: Optional[Union[str, list]] = None,
5856
retries: int = 1,
59-
tls: Literal["1.3", "1.2", "1.1", "1.0"] = "1.3",
57+
tls: Union[Literal["1.3", "1.2", "1.1", "1.0"], str] = "1.3",
6058
user: Optional[str] = None,
6159
password: Optional[str] = None,
6260
timeout: Optional[int] = None,
61+
test_url: Optional[str] = None,
6362
) -> ProxyChekerResult:
6463
"""Check a proxy for working protocols, anonymity, latency and country.
6564
66-
Parameters
67-
----------
68-
proxy : str
69-
Proxy address in the form 'host:port'. For protocol testing the method
70-
will prefix this value with protocol scheme (e.g. 'http://host:port').
71-
check_country : bool, default=True
72-
If True, query the IP geolocation service to get country and country code.
73-
check_address : bool, default=False
74-
If True, attempt to parse REMOTE_ADDR from the judge response.
75-
check_all_protocols : bool, default=False
76-
If True, test all protocols listed; otherwise stop after the first success.
77-
protocol : Optional[Union[str, list]], default=None
78-
A single protocol name (e.g. 'http') or a list of protocols to test.
79-
When None all supported protocols ('http','https','socks4','socks5') are used.
80-
retries : int, default=1
81-
How many times to retry protocol checks.
82-
tls : float, default=1.3
83-
Maximum TLS version to allow when using an HTTPS proxy (1.3,1.2,1.1,1.0).
84-
user, password : Optional[str]
85-
Optional proxy authentication credentials.
86-
timeout : Optional[int], default=None
87-
Per-request timeout in milliseconds (ms). If None the instance
88-
default `self.timeout` is used.
89-
90-
Returns
91-
-------
92-
ProxyChekerResult
93-
Dataclass with fields: protocols (List[str]), anonymity (Literal), latency (ms int),
94-
country, country_code, proxy (remote address when check_address=True), and error flag.
95-
96-
Notes
97-
-----
98-
- The timeout parameter is in milliseconds to match the underlying pycurl usage.
99-
- The method will return a `ProxyChekerResult` with `error=True` when no protocol
100-
succeeds.
65+
Parameters
66+
----------
67+
proxy : str
68+
Proxy address in the form 'host:port'. For protocol testing the method
69+
will prefix this value with protocol scheme (e.g. 'http://host:port').
70+
check_country : bool, default=True
71+
If True, query the IP geolocation service to get country and country code.
72+
check_address : bool, default=False
73+
If True, attempt to parse REMOTE_ADDR from the judge response.
74+
check_all_protocols : bool, default=False
75+
If True, test all protocols listed; otherwise stop after the first success.
76+
protocol : Optional[Union[str, list]], default=None
77+
A single protocol name (e.g. 'http') or a list of protocols to test.
78+
When None all supported protocols ('http','https','socks4','socks5') are used.
79+
retries : int, default=1
80+
How many times to retry protocol checks.
81+
tls : float, default=1.3
82+
Maximum TLS version to allow when using an HTTPS proxy (1.3,1.2,1.1,1.0).
83+
user, password : Optional[str]
84+
Optional proxy authentication credentials.
85+
timeout : Optional[int], default=None
86+
Per-request timeout in milliseconds (ms). If None the instance
87+
default `self.timeout` is used.
88+
89+
Returns
90+
-------
91+
ProxyChekerResult
92+
Dataclass with fields: protocols (List[str]), anonymity (Literal), latency (ms int),
93+
country, country_code, proxy (remote address when check_address=True), and error flag.
94+
95+
Notes
96+
-----
97+
- The timeout parameter is in milliseconds to match the underlying pycurl usage.
98+
- The method will return a `ProxyChekerResult` with `error=True` when no protocol
99+
succeeds.
101100
102101
Example
103-
-------
104-
>>> checker = ProxyChecker()
105-
>>> result = checker.check_proxy('1.2.3.4:8080', timeout=10000)
106-
>>> print(result.to_json())
102+
-------
103+
>>> checker = ProxyChecker()
104+
>>> result = checker.check_proxy('1.2.3.4:8080', timeout=10000)
105+
>>> print(result.to_json())
107106
"""
108107
all_protocols = ["http", "https", "socks4", "socks5"]
109108

@@ -124,7 +123,7 @@ def check_proxy(
124123
# Query a fixed probe URL using the protocol-prefixed proxy URL
125124
proxy_url = f"{proto}://{proxy}"
126125
result = send_query(
127-
url=PROBE_URL,
126+
url=test_url or "https://www.google.com",
128127
proxy=proxy_url,
129128
user=user,
130129
password=password,

0 commit comments

Comments
 (0)