Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method __str__() from UserAgent now using methods custom get_device, get_os and get_browser #94

Merged
merged 1 commit into from Aug 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions user_agents/parsers.py
Expand Up @@ -136,10 +136,11 @@ def __init__(self, user_agent_string):
self.device = parse_device(**ua_dict['device'])

def __str__(self):
device = self.is_pc and "PC" or self.device.family
os = ("%s %s" % (self.os.family, self.os.version_string)).strip()
browser = ("%s %s" % (self.browser.family, self.browser.version_string)).strip()
return " / ".join([device, os, browser])
return "{device} / {os} / {browser}".format(
device=self.get_device(),
os=self.get_os(),
browser=self.get_browser()
)

def __unicode__(self):
return unicode(str(self))
Expand All @@ -163,6 +164,15 @@ def _is_blackberry_touch_capable_device(self):
return True
return False

def get_device(self):
return self.is_pc and "PC" or self.device.family

def get_os(self):
return ("%s %s" % (self.os.family, self.os.version_string)).strip()

def get_browser(self):
return ("%s %s" % (self.browser.family, self.browser.version_string)).strip()

@property
def is_tablet(self):
if self.device.family in TABLET_DEVICE_FAMILIES:
Expand Down Expand Up @@ -251,5 +261,6 @@ def is_email_client(self):
return True
return False


def parse(user_agent_string):
return UserAgent(user_agent_string)