Skip to content

Commit

Permalink
make internal methods private
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdual committed Mar 9, 2024
1 parent e3134c0 commit 966e1b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/ua_generator/data/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def __init__(self, device, platform, browser):
self.platform = platform
self.browser = browser

self.platform_version = self.generate_platform_version()
self.browser_version = self.generate_browser_version()
self.user_agent = self.generate_user_agent()
self.platform_version = self.__platform_version()
self.browser_version = self.__browser_version()
self.user_agent = self.__user_agent()

def generate_platform_version(self):
def __platform_version(self):
if self.platform == 'windows':
return windows.get_version()
elif self.platform == 'macos':
Expand All @@ -30,7 +30,7 @@ def generate_platform_version(self):
elif self.platform == 'android':
return android.get_version()

def generate_browser_version(self):
def __browser_version(self):
if self.browser == 'chrome':
return chrome.get_version()
elif self.browser == 'safari':
Expand All @@ -40,7 +40,7 @@ def generate_browser_version(self):
elif self.browser == 'edge':
return edge.get_version()

def generate_user_agent(self):
def __user_agent(self):
if self.platform == 'windows':
if self.browser == 'chrome':
template = utils.choice((
Expand Down
34 changes: 17 additions & 17 deletions src/ua_generator/useragent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def generate(self, device=None, platform=None, browser=None):
self.device = device
self.platform = platform
self.browser = browser
self.complete()
self.__complete()
return self

def find_device(self):
def __find_device(self):
if self.device is not None:
if not utils.contains_multiple(self.device, devices):
raise exceptions.InvalidArgumentError('No device type found: {}'.format(self.device))
Expand All @@ -42,7 +42,7 @@ def find_device(self):

return self.device

def find_platform(self):
def __find_platform(self):
if self.platform is not None:
if not utils.contains_multiple(self.platform, platforms):
raise exceptions.InvalidArgumentError('No platform found: {}'.format(self.platform))
Expand All @@ -59,7 +59,7 @@ def find_platform(self):

return self.platform

def find_browser(self):
def __find_browser(self):
if self.browser is not None:
if not utils.contains_multiple(self.browser, browsers):
raise exceptions.InvalidArgumentError('No browser found: {}'.format(self.browser))
Expand All @@ -75,10 +75,10 @@ def find_browser(self):

return self.browser

def complete(self):
self.device = self.find_device()
self.platform = self.find_platform()
self.browser = self.find_browser()
def __complete(self):
self.device = self.__find_device()
self.platform = self.__find_platform()
self.browser = self.__find_browser()

ua = generator.Generator(device=self.device, platform=self.platform, browser=self.browser)
self.platform_version = ua.platform_version
Expand All @@ -94,16 +94,16 @@ def __str__(self):
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Full-Version-List
class ClientHints:
def __init__(self, _gen: generator.Generator):
self.mobile = serialization.ch_bool(self.ch_mobile(_gen.platform))
self.platform = serialization.ch_string(self.ch_platform(_gen.platform))
self.platform_version = serialization.ch_string(self.ch_platform_version(_gen.platform_version))
self.brands = serialization.ch_brand_list(self.ch_brands(_gen))
self.brands_full_version_list = serialization.ch_brand_list(self.ch_brands(_gen, full_version_list=True))
self.mobile = serialization.ch_bool(self.__mobile(_gen.platform))
self.platform = serialization.ch_string(self.__platform(_gen.platform))
self.platform_version = serialization.ch_string(self.__platform_version(_gen.platform_version))
self.brands = serialization.ch_brand_list(self.__brands(_gen))
self.brands_full_version_list = serialization.ch_brand_list(self.__brands(_gen, full_version_list=True))

def ch_mobile(self, platform: str):
def __mobile(self, platform: str):
return utils.contains(platforms_mobile, platform)

def ch_platform(self, platform: str):
def __platform(self, platform: str):
if platform == 'ios':
platform = 'iOS'
elif platform == 'macos':
Expand All @@ -112,10 +112,10 @@ def ch_platform(self, platform: str):
platform = platform.title()
return platform

def ch_platform_version(self, platform_version):
def __platform_version(self, platform_version):
return formats.version(platform_version)

def ch_brands(self, _gen: generator.Generator, full_version_list: bool = False):
def __brands(self, _gen: generator.Generator, full_version_list: bool = False):
brand_list = [{'brand': 'Not A(Brand', 'version': '99'}]

if full_version_list:
Expand Down

0 comments on commit 966e1b5

Please sign in to comment.