Skip to content

Commit

Permalink
Merge pull request #16 from iamdual/revert-15-master
Browse files Browse the repository at this point in the history
Revert "Typing literals + UserAgent __repr__"
  • Loading branch information
iamdual authored Oct 20, 2024
2 parents d8d05da + 8a56494 commit 54d78dc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
12 changes: 5 additions & 7 deletions src/ua_generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 0 additions & 5 deletions src/ua_generator/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
19 changes: 2 additions & 17 deletions src/ua_generator/user_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})"

0 comments on commit 54d78dc

Please sign in to comment.