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

27 lines
642 B
Python
Raw Normal View History

2024-01-21 17:45:01 +00:00
from __future__ import annotations
2024-02-01 07:24:26 +00:00
import os
from pathlib import Path
from typing import Union
2024-01-21 17:45:01 +00:00
from urllib.parse import urlparse
2024-02-01 07:24:26 +00:00
import aiofiles.os
2024-01-21 17:45:01 +00:00
import charset_normalizer
2024-02-01 07:24:26 +00:00
IS_DOCKER = os.getenv("IS_DOCKER") == "1"
2024-01-21 17:45:01 +00:00
def is_url(value: str, /) -> bool:
parsed_url = urlparse(value)
return bool(parsed_url.scheme and parsed_url.netloc)
def bytes_decode(value: bytes, /) -> str:
return str(charset_normalizer.from_bytes(value)[0])
2024-02-01 07:24:26 +00:00
2024-02-01 14:52:29 +03:00
async def check_access(path: Union[Path, str], /, *, mode: int) -> None:
if not await aiofiles.os.access(path, mode):
msg = f"{path} is not accessible"
2024-02-01 07:24:26 +00:00
raise ValueError(msg)