Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 155c23d

Browse filesBrowse files
authored
method __str__ from UserAgent now using methods (selwin#94)
Is better to calculate and provide a method to calculate the string values for `device`, `os` and `browser` instead of doing it directly on `__str__` method. This way the users may use those methods to get each data directly. Instead of having to make a `user_agent.__str__().split('/')` to get each value
1 parent 89ce57f commit 155c23d
Copy full SHA for 155c23d

File tree

Expand file treeCollapse file tree

1 file changed

+15
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-4
lines changed

‎user_agents/parsers.py

Copy file name to clipboardExpand all lines: user_agents/parsers.py
+15-4Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ def __init__(self, user_agent_string):
140140
self.device = parse_device(**ua_dict['device'])
141141

142142
def __str__(self):
143-
device = self.is_pc and "PC" or self.device.family
144-
os = ("%s %s" % (self.os.family, self.os.version_string)).strip()
145-
browser = ("%s %s" % (self.browser.family, self.browser.version_string)).strip()
146-
return " / ".join([device, os, browser])
143+
return "{device} / {os} / {browser}".format(
144+
device=self.get_device(),
145+
os=self.get_os(),
146+
browser=self.get_browser()
147+
)
147148

148149
def __unicode__(self):
149150
return unicode(str(self))
@@ -167,6 +168,15 @@ def _is_blackberry_touch_capable_device(self):
167168
return True
168169
return False
169170

171+
def get_device(self):
172+
return self.is_pc and "PC" or self.device.family
173+
174+
def get_os(self):
175+
return ("%s %s" % (self.os.family, self.os.version_string)).strip()
176+
177+
def get_browser(self):
178+
return ("%s %s" % (self.browser.family, self.browser.version_string)).strip()
179+
170180
@property
171181
def is_tablet(self):
172182
if self.device.family in TABLET_DEVICE_FAMILIES:
@@ -255,5 +265,6 @@ def is_email_client(self):
255265
return True
256266
return False
257267

268+
258269
def parse(user_agent_string):
259270
return UserAgent(user_agent_string)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.