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

19 lines
450 B
Python

from __future__ import annotations
from functools import cache
from pathlib import Path
from urllib.parse import urlparse
import charset_normalizer
is_docker = cache(Path("/.dockerenv").exists)
def is_http_url(value: str, /) -> bool:
parsed_url = urlparse(value)
return bool(parsed_url.scheme in {"http", "https"} and parsed_url.netloc)
def bytes_decode(value: bytes, /) -> str:
return str(charset_normalizer.from_bytes(value)[0])