Files
proxy-scraper-checker/proxy_scraper_checker/sort.py
T

22 lines
543 B
Python
Raw Normal View History

2023-01-02 00:09:55 +03:00
from __future__ import annotations
from typing import Tuple
2024-01-21 17:45:01 +00:00
from aiohttp_socks import ProxyType
2023-01-02 00:09:55 +03:00
from .proxy import Proxy
2024-01-21 17:45:01 +00:00
PROTOCOL_ORDER = (ProxyType.HTTP, ProxyType.SOCKS4, ProxyType.SOCKS5)
2023-01-02 00:09:55 +03:00
2024-01-21 17:45:01 +00:00
def protocol_sort_key(proxy: Proxy, /) -> Tuple[int, ProxyType]:
return (PROTOCOL_ORDER.index(proxy.protocol), proxy.protocol)
2023-01-02 00:09:55 +03:00
2024-01-21 17:45:01 +00:00
def natural_sort_key(proxy: Proxy, /) -> Tuple[int, ...]:
return (proxy.protocol.value, *map(int, proxy.host.split(".")), proxy.port)
def timeout_sort_key(proxy: Proxy, /) -> float:
return proxy.timeout