diff --git a/src/ua_generator/__init__.py b/src/ua_generator/__init__.py index 877c639..dd5cc7f 100644 --- a/src/ua_generator/__init__.py +++ b/src/ua_generator/__init__.py @@ -5,13 +5,11 @@ """ import typing -from . import user_agent, options as _options, data as _data +from . import user_agent, options as _options -def generate( - device: typing.Union[tuple[_data._DEVICES_TYPE], _data._DEVICES_TYPE, None] = None, - platform: typing.Union[tuple[_data._PLATFORMS_TYPE], _data._PLATFORMS_TYPE, None] = None, - browser: typing.Union[tuple[_data._BROWSERS_TYPE], _data._BROWSERS_TYPE, None] = None, - options: typing.Union[_options.Options, None] = None -): +def generate(device: typing.Union[tuple, str, None] = None, + platform: typing.Union[tuple, str, None] = None, + browser: typing.Union[tuple, str, None] = None, + options: typing.Union[_options.Options, None] = None) -> user_agent.UserAgent: return user_agent.UserAgent(device, platform, browser, options) diff --git a/src/ua_generator/data/__init__.py b/src/ua_generator/data/__init__.py index da655bb..afca546 100644 --- a/src/ua_generator/data/__init__.py +++ b/src/ua_generator/data/__init__.py @@ -3,17 +3,12 @@ Copyright: 2022-2024 Ekin Karadeniz (github.com/iamdual) License: Apache License 2.0 """ -from typing import Literal DEVICES = ('desktop', 'mobile') -_DEVICES_TYPE = Literal['desktop', 'mobile', None] PLATFORMS = ('windows', 'macos', 'ios', 'linux', 'android') -_PLATFORMS_TYPE = Literal['windows', 'macos', 'ios', 'linux', 'android', None] PLATFORMS_DESKTOP = ('windows', 'macos', 'linux') # Platforms on desktop devices PLATFORMS_MOBILE = ('ios', 'android') # Platforms on mobile devices BROWSERS = ('chrome', 'edge', 'firefox', 'safari') -_BROWSERS_TYPE = Literal['chrome', 'edge', 'firefox', 'safari', None] BROWSERS_SUPPORT_CH = ('chrome', 'edge') # Browsers that support Client Hints -_BROWSERS_SUPPORT_CH_TYPE = Literal['chrome', 'edge', None] diff --git a/src/ua_generator/user_agent.py b/src/ua_generator/user_agent.py index ec3049d..3a68cd8 100644 --- a/src/ua_generator/user_agent.py +++ b/src/ua_generator/user_agent.py @@ -7,26 +7,14 @@ from . import utils, exceptions from .client_hints import ClientHints -from .data import ( - DEVICES, _DEVICES_TYPE, - BROWSERS, _BROWSERS_TYPE, - PLATFORMS, _PLATFORMS_TYPE, - PLATFORMS_DESKTOP, - PLATFORMS_MOBILE, -) +from .data import DEVICES, BROWSERS, PLATFORMS, PLATFORMS_DESKTOP, PLATFORMS_MOBILE from .data.generator import Generator from .headers import Headers from .options import Options class UserAgent: - def __init__( - self, - device: _DEVICES_TYPE = None, - platform: _PLATFORMS_TYPE = None, - browser: _BROWSERS_TYPE = None, - options: typing.Union[Options, None] = None, - ): + def __init__(self, device=None, platform=None, browser=None, options=None): self.device: typing.Union[str, None] = utils.choice(device) if device else None self.platform: typing.Union[str, None] = utils.choice(platform) if platform else None self.browser: typing.Union[str, None] = utils.choice(browser) if browser else None @@ -100,6 +88,3 @@ def __complete(self): def __str__(self): return self.text - - def __repr__(self) -> str: - return f"UserAgent(\"{self.text}\", device={self.device}, platform={self.platform}, browser={self.browser})" \ No newline at end of file