diff --git a/stubs/user-agents/@tests/stubtest_allowlist.txt b/stubs/user-agents/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..3aa65594b170 --- /dev/null +++ b/stubs/user-agents/@tests/stubtest_allowlist.txt @@ -0,0 +1,3 @@ +# Internal modules +user_agents\.compat +user_agents\.tests diff --git a/stubs/user-agents/METADATA.toml b/stubs/user-agents/METADATA.toml new file mode 100644 index 000000000000..e1a771f4137f --- /dev/null +++ b/stubs/user-agents/METADATA.toml @@ -0,0 +1,2 @@ +version = "2.2.*" +upstream-repository = "https://github.com/selwin/python-user-agents" diff --git a/stubs/user-agents/user_agents/__init__.pyi b/stubs/user-agents/user_agents/__init__.pyi new file mode 100644 index 000000000000..9187af27d451 --- /dev/null +++ b/stubs/user-agents/user_agents/__init__.pyi @@ -0,0 +1,5 @@ +from typing import Final + +from .parsers import parse as parse + +VERSION: Final[tuple[int, int, int]] diff --git a/stubs/user-agents/user_agents/parsers.pyi b/stubs/user-agents/user_agents/parsers.pyi new file mode 100644 index 000000000000..77f78e3b5fc2 --- /dev/null +++ b/stubs/user-agents/user_agents/parsers.pyi @@ -0,0 +1,66 @@ +from typing import Final, NamedTuple, TypeVar + +_T = TypeVar("_T") + +MOBILE_DEVICE_FAMILIES: Final[tuple[str, ...]] +PC_OS_FAMILIES: Final[tuple[str, ...]] +MOBILE_OS_FAMILIES: Final[tuple[str, ...]] +MOBILE_BROWSER_FAMILIES: Final[tuple[str, ...]] +TABLET_DEVICE_FAMILIES: Final[tuple[str, ...]] +TOUCH_CAPABLE_OS_FAMILIES: Final[tuple[str, ...]] +TOUCH_CAPABLE_DEVICE_FAMILIES: Final[tuple[str, ...]] +EMAIL_PROGRAM_FAMILIES: Final[set[str]] + +def verify_attribute(attribute: _T) -> _T | int: ... +def parse_version( + major: str | None = None, minor: str | None = None, patch: str | None = None, patch_minor: str | None = None +) -> tuple[int | str, ...]: ... + +class Browser(NamedTuple): + family: str + version: tuple[int | str, ...] + version_string: str + +def parse_browser( + family: str, major: str | None = None, minor: str | None = None, patch: str | None = None, patch_minor: str | None = None +) -> Browser: ... + +class OperatingSystem(NamedTuple): + family: str + version: tuple[int | str, ...] + version_string: str + +def parse_operating_system( + family: str, major: str | None = None, minor: str | None = None, patch: str | None = None, patch_minor: str | None = None +) -> OperatingSystem: ... + +class Device(NamedTuple): + family: str + brand: str | None + model: str | None + +def parse_device(family: str, brand: str | None, model: str | None) -> Device: ... + +class UserAgent: + ua_string: str + os: OperatingSystem + browser: Browser + device: Device + def __init__(self, user_agent_string: str) -> None: ... + def get_device(self) -> str: ... + def get_os(self) -> str: ... + def get_browser(self) -> str: ... + @property + def is_tablet(self) -> bool: ... + @property + def is_mobile(self) -> bool: ... + @property + def is_touch_capable(self) -> bool: ... + @property + def is_pc(self) -> bool: ... + @property + def is_bot(self) -> bool: ... + @property + def is_email_client(self) -> bool: ... + +def parse(user_agent_string: str) -> UserAgent: ...