cligram.proxy_manager
Proxy management and testing for Telegram connections.
- class cligram.proxy_manager.Proxy(url, type, host, port, secret=None, username=None, password=None)[source]
Bases:
objectProxy connection configuration.
Supports both MTProto and SOCKS5 protocols with their respective authentication methods. For MTProto, requires secret key; for SOCKS5, supports optional username/password authentication.
- class cligram.proxy_manager.ProxyManager[source]
Bases:
objectManages proxy connections and testing.
Provides functionality to add, test, and select working proxies for Telegram connections.
- classmethod from_config(config, exclude_direct=False)[source]
Create ProxyManager instance from application config.
- Parameters:
- Return type:
- Returns:
ProxyManager instance
- async test_proxies(filter=None, exclusion=[], shutdown_event=None, timeout=30.0, oneshot=False)[source]
Test configured proxies.
The best proxy will be set as current_proxy.
- Parameters:
filter (
Optional[ProxyType]) – Optional proxy type to filter for testingexclusion (
List[Proxy]) – List of proxies to exclude from testingshutdown_event (
Optional[Event]) – Optional asyncio event to signal shutdowntimeout (
float) – Timeout for proxy test in secondsoneshot (
bool) – If True, stop testing after first successful proxy
- Return type:
- Returns:
List of ProxyTestResult objects with test outcomes
- class cligram.proxy_manager.ProxyTestResult(proxy, success, latency=None, error=None)[source]
Bases:
objectResult of a proxy test, including latency and status.
- class cligram.proxy_manager.ProxyType(*values)[source]
Bases:
EnumType of proxy connection supported by the application.
- DIRECT = 'direct'
Direct connection without proxy.
- MTPROTO = 'mtproto'
MTProto proxy protocol used by Telegram.
- SOCKS5 = 'socks5'
SOCKS5 proxy protocol with optional authentication.