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
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit ca1d840

Browse filesBrowse files
committed
Added "is_spider" property, Symbian devices are now recognized as mobile devices too.
1 parent 4901041 commit ca1d840
Copy full SHA for ca1d840

File tree

Expand file treeCollapse file tree

2 files changed

+43
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+43
-1
lines changed

‎user_agents/parsers.py

Copy file name to clipboardExpand all lines: user_agents/parsers.py
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
'Generic Feature Phone',
1111
)
1212

13+
MOBILE_OS_FAMILIES = (
14+
'Windows Phone OS',
15+
'Symbian OS',
16+
)
17+
1318
TABLET_DEVICE_FAMILIES = (
1419
'iPad',
1520
'Blackberry Playbook',
@@ -129,7 +134,7 @@ def is_mobile(self):
129134
return True
130135
if self.os.family == 'BlackBerry OS' and self.device.family != 'Blackberry Playbook':
131136
return True
132-
if self.os.family == 'Windows Phone OS':
137+
if self.os.family in MOBILE_OS_FAMILIES:
133138
return True
134139
# TODO: remove after https://github.com/tobie/ua-parser/issues/126 is closed
135140
if 'J2ME' in self.ua_string or 'MIDP' in self.ua_string:
@@ -138,6 +143,7 @@ def is_mobile(self):
138143

139144
@property
140145
def is_touch_capable(self):
146+
# TODO: detect touch capable Nokia devices
141147
if self.os.family in TOUCH_CAPABLE_OS_FAMILIES:
142148
return True
143149
if self.device.family in TOUCH_CAPABLE_DEVICE_FAMILIES:
@@ -160,6 +166,10 @@ def is_pc(self):
160166
return True
161167
return False
162168

169+
@property
170+
def is_spider(self):
171+
return True if self.device.family == 'Spider' else False
172+
163173

164174
def parse(user_agent_string):
165175
return UserAgent(user_agent_string)

‎user_agents/tests.py

Copy file name to clipboardExpand all lines: user_agents/tests.py
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
mac_safari_ua_string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2'
2323
windows_ie_ua_string = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
2424
ubuntu_firefox_ua_string = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:15.0) Gecko/20100101 Firefox/15.0.1'
25+
google_bot_ua_string = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
26+
nokia_n97_ua_string = 'Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/12.0.024; Profile/MIDP-2.1 Configuration/CLDC-1.1; en-us) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.12344'
2527

2628
iphone_ua = parse(iphone_ua_string)
2729
ipad_ua = parse(ipad_ua_string)
@@ -41,6 +43,8 @@
4143
mac_safari_ua = parse(mac_safari_ua_string)
4244
windows_ie_ua = parse(windows_ie_ua_string)
4345
ubuntu_firefox_ua = parse(ubuntu_firefox_ua_string)
46+
google_bot_ua = parse(google_bot_ua_string)
47+
nokia_n97_ua = parse(nokia_n97_ua_string)
4448

4549

4650
class UserAgentsTest(unittest.TestCase):
@@ -79,6 +83,8 @@ def test_is_tablet_property(self):
7983
self.assertFalse(windows_ie_ua.is_tablet)
8084
self.assertFalse(ubuntu_firefox_ua.is_tablet)
8185
self.assertFalse(j2me_opera_ua.is_tablet)
86+
self.assertFalse(google_bot_ua.is_tablet)
87+
self.assertFalse(nokia_n97_ua.is_tablet)
8288
self.assertTrue(windows_rt_ua.is_tablet)
8389
self.assertTrue(ipad_ua.is_tablet)
8490
self.assertTrue(playbook_ua.is_tablet)
@@ -92,6 +98,7 @@ def test_is_mobile_property(self):
9298
self.assertTrue(blackberry_bold_ua.is_mobile)
9399
self.assertTrue(windows_phone_ua.is_mobile)
94100
self.assertTrue(j2me_opera_ua.is_mobile)
101+
self.assertTrue(nokia_n97_ua.is_mobile)
95102
self.assertFalse(windows_rt_ua.is_mobile)
96103
self.assertFalse(ipad_ua.is_mobile)
97104
self.assertFalse(playbook_ua.is_mobile)
@@ -102,6 +109,7 @@ def test_is_mobile_property(self):
102109
self.assertFalse(mac_safari_ua.is_mobile)
103110
self.assertFalse(windows_ie_ua.is_mobile)
104111
self.assertFalse(ubuntu_firefox_ua.is_mobile)
112+
self.assertFalse(google_bot_ua.is_mobile)
105113

106114
def test_is_touch_property(self):
107115
self.assertTrue(iphone_ua.is_touch_capable)
@@ -120,6 +128,8 @@ def test_is_touch_property(self):
120128
self.assertFalse(mac_safari_ua.is_touch_capable)
121129
self.assertFalse(windows_ie_ua.is_touch_capable)
122130
self.assertFalse(ubuntu_firefox_ua.is_touch_capable)
131+
self.assertFalse(google_bot_ua.is_touch_capable)
132+
self.assertFalse(nokia_n97_ua.is_touch_capable)
123133

124134
def test_is_pc(self):
125135
self.assertFalse(iphone_ua.is_pc)
@@ -133,8 +143,30 @@ def test_is_pc(self):
133143
self.assertFalse(blackberry_torch_ua.is_pc)
134144
self.assertFalse(blackberry_bold_ua.is_pc)
135145
self.assertFalse(j2me_opera_ua.is_pc)
146+
self.assertFalse(google_bot_ua.is_pc)
147+
self.assertFalse(nokia_n97_ua.is_pc)
136148
self.assertTrue(mac_safari_ua.is_pc)
137149
self.assertTrue(windows_ie_ua.is_pc)
138150
self.assertTrue(ubuntu_firefox_ua.is_pc)
139151
self.assertTrue(ie_touch_ua.is_pc)
140152
self.assertTrue(ie_ua.is_pc)
153+
154+
def test_is_spider(self):
155+
self.assertTrue(google_bot_ua.is_spider)
156+
self.assertFalse(iphone_ua.is_spider)
157+
self.assertFalse(galaxy_s3_ua.is_spider)
158+
self.assertFalse(ipad_ua.is_spider)
159+
self.assertFalse(playbook_ua.is_spider)
160+
self.assertFalse(kindle_fire_ua.is_spider)
161+
self.assertFalse(nexus_7_ua.is_spider)
162+
self.assertFalse(windows_phone_ua.is_spider)
163+
self.assertFalse(blackberry_bold_touch_ua.is_spider)
164+
self.assertFalse(blackberry_torch_ua.is_spider)
165+
self.assertFalse(blackberry_bold_ua.is_spider)
166+
self.assertFalse(j2me_opera_ua.is_spider)
167+
self.assertFalse(mac_safari_ua.is_spider)
168+
self.assertFalse(windows_ie_ua.is_spider)
169+
self.assertFalse(ubuntu_firefox_ua.is_spider)
170+
self.assertFalse(ie_touch_ua.is_spider)
171+
self.assertFalse(ie_ua.is_spider)
172+
self.assertFalse(nokia_n97_ua.is_spider)

0 commit comments

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