Skip to content

Commit e00e0cf

Browse files
author
Derrick Petzold
committed
The SCH- check was erroneously setting Galaxy S phones to tablets.
Added support for PlayStation, PlayStation Vita, and SAMSUNG-GT-S8530.
1 parent 3dede6f commit e00e0cf

2 files changed

Lines changed: 50 additions & 10 deletions

File tree

‎user_agents/parsers.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,26 @@
1818
'iPod',
1919
'Generic Smartphone',
2020
'Generic Feature Phone',
21+
'PlayStation Vita',
2122
)
2223

2324
MOBILE_OS_FAMILIES = (
2425
'Windows Phone',
25-
'Windows Phone OS', # Earlier versions of ua-parser returns Windows Phone OS
26+
'Windows Phone OS', # Earlier versions of ua-parser returns Windows Phone OS
2627
'Symbian OS',
28+
'Bada',
2729
)
2830

2931
TABLET_DEVICE_FAMILIES = (
3032
'iPad',
3133
'BlackBerry Playbook',
32-
'Blackberry Playbook', # Earlier versions of ua-parser returns "Blackberry" instead of "BlackBerry"
34+
'Blackberry Playbook', # Earlier versions of ua-parser returns "Blackberry" instead of "BlackBerry"
3335
'Kindle',
3436
'Kindle Fire',
37+
'Kindle Fire HD',
38+
'Galaxy Tab',
39+
'Xoom',
40+
'Dell Streak',
3541
)
3642

3743
TOUCH_CAPABLE_OS_FAMILIES = (
@@ -121,18 +127,16 @@ def _is_android_tablet(self):
121127
if ('Mobile Safari' not in self.ua_string and
122128
self.browser.family != "Firefox Mobile"):
123129
return True
124-
if 'SCH-' in self.ua_string:
125-
return True
126130
return False
127131

128132
def _is_blackberry_touch_capable_device(self):
129133
# A helper to determine whether a BB phone has touch capabilities
130134
# Blackberry Bold Touch series begins with 99XX
131135
if 'Blackberry 99' in self.device.family:
132136
return True
133-
if 'Blackberry 95' in self.device.family: # BB Storm devices
137+
if 'Blackberry 95' in self.device.family: # BB Storm devices
134138
return True
135-
if 'Blackberry 95' in self.device.family: # BB Torch devices
139+
if 'Blackberry 95' in self.device.family: # BB Torch devices
136140
return True
137141
return False
138142

‎user_agents/tests.py‎

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# flake8: noqa
2+
13
import unittest
24

35
from ua_parser import user_agent_parser
@@ -25,6 +27,11 @@
2527
google_bot_ua_string = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
2628
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'
2729
android_firefox_aurora_ua_string = 'Mozilla/5.0 (Android; Mobile; rv:27.0) Gecko/27.0 Firefox/27.0'
30+
samsung_galaxy_s_ua_string = 'Mozilla/5.0 (Linux; Android 4.4.2; en-us; SAMSUNG SCH-I545 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Mobile Safari/537.36'
31+
playstation_vita_ua_string = 'Mozilla/5.0 (PlayStation Vita 3.12) AppleWebKit/536.26 (KHTML, like Gecko) Silk/3.2'
32+
playstation_ua_string = 'Mozilla/5.0 (PLAYSTATION 3 4.60) AppleWebKit/531.22.8 (KHTML, like Gecko)'
33+
samsung_gt_ua_string = 'Mozilla/5.0 (SAMSUNG; SAMSUNG-GT-S8530/S8530DDLC2; U; Bada/2.0; en-us) AppleWebKit/534.20 (KHTML, like Gecko) Dolfin/3.0 Mobile WVGA SMM-MMS/1.2.0 OPN-B'
34+
2835

2936
iphone_ua = parse(iphone_ua_string)
3037
ipad_ua = parse(ipad_ua_string)
@@ -47,6 +54,10 @@
4754
google_bot_ua = parse(google_bot_ua_string)
4855
nokia_n97_ua = parse(nokia_n97_ua_string)
4956
android_firefox_aurora_ua = parse(android_firefox_aurora_ua_string)
57+
samsung_galaxy_s_ua = parse(samsung_galaxy_s_ua_string)
58+
playstation_vita_ua = parse(playstation_vita_ua_string)
59+
playstation_ua = parse(playstation_ua_string)
60+
samsung_gt_ua = parse(samsung_gt_ua_string)
5061

5162

5263
class UserAgentsTest(unittest.TestCase):
@@ -61,7 +72,7 @@ def test_user_agent_object_assignments(self):
6172
iphone_ua.browser.version,
6273
(int(ua_dict['user_agent']['major']), int(ua_dict['user_agent']['minor']))
6374
)
64-
75+
6576
# Ensure os attributes are assigned correctly
6677
self.assertEqual(iphone_ua.os.family, ua_dict['os']['family'])
6778
self.assertEqual(
@@ -93,6 +104,11 @@ def test_is_tablet_property(self):
93104
self.assertTrue(kindle_fire_ua.is_tablet)
94105
self.assertTrue(nexus_7_ua.is_tablet)
95106
self.assertFalse(android_firefox_aurora_ua.is_tablet)
107+
self.assertFalse(samsung_galaxy_s_ua.is_tablet)
108+
self.assertFalse(playstation_vita_ua.is_tablet)
109+
self.assertFalse(playstation_ua.is_tablet)
110+
self.assertFalse(samsung_gt_ua.is_tablet)
111+
96112

97113
def test_is_mobile_property(self):
98114
self.assertTrue(iphone_ua.is_mobile)
@@ -114,6 +130,11 @@ def test_is_mobile_property(self):
114130
self.assertFalse(ubuntu_firefox_ua.is_mobile)
115131
self.assertFalse(google_bot_ua.is_mobile)
116132
self.assertTrue(android_firefox_aurora_ua.is_mobile)
133+
self.assertTrue(samsung_galaxy_s_ua.is_mobile)
134+
self.assertTrue(playstation_vita_ua.is_mobile)
135+
self.assertFalse(playstation_ua.is_mobile)
136+
self.assertTrue(samsung_gt_ua.is_mobile)
137+
117138

118139
def test_is_touch_property(self):
119140
self.assertTrue(iphone_ua.is_touch_capable)
@@ -135,6 +156,11 @@ def test_is_touch_property(self):
135156
self.assertFalse(google_bot_ua.is_touch_capable)
136157
self.assertFalse(nokia_n97_ua.is_touch_capable)
137158
self.assertTrue(android_firefox_aurora_ua.is_touch_capable)
159+
self.assertTrue(samsung_galaxy_s_ua.is_touch_capable)
160+
self.assertFalse(playstation_vita_ua.is_touch_capable)
161+
self.assertFalse(playstation_ua.is_touch_capable)
162+
self.assertFalse(samsung_gt_ua.is_touch_capable)
163+
138164

139165
def test_is_pc(self):
140166
self.assertFalse(iphone_ua.is_pc)
@@ -145,7 +171,7 @@ def test_is_pc(self):
145171
self.assertFalse(nexus_7_ua.is_pc)
146172
self.assertFalse(windows_phone_ua.is_pc)
147173
self.assertFalse(blackberry_bold_touch_ua.is_pc)
148-
self.assertFalse(blackberry_torch_ua.is_pc)
174+
self.assertFalse(blackberry_torch_ua.is_pc)
149175
self.assertFalse(blackberry_bold_ua.is_pc)
150176
self.assertFalse(j2me_opera_ua.is_pc)
151177
self.assertFalse(google_bot_ua.is_pc)
@@ -156,6 +182,11 @@ def test_is_pc(self):
156182
self.assertTrue(ie_touch_ua.is_pc)
157183
self.assertTrue(ie_ua.is_pc)
158184
self.assertFalse(android_firefox_aurora_ua.is_pc)
185+
self.assertFalse(samsung_galaxy_s_ua.is_pc)
186+
self.assertFalse(playstation_vita_ua.is_pc)
187+
self.assertFalse(playstation_ua.is_pc)
188+
self.assertFalse(samsung_gt_ua.is_pc)
189+
159190

160191
def test_is_bot(self):
161192
self.assertTrue(google_bot_ua.is_bot)
@@ -167,16 +198,21 @@ def test_is_bot(self):
167198
self.assertFalse(nexus_7_ua.is_bot)
168199
self.assertFalse(windows_phone_ua.is_bot)
169200
self.assertFalse(blackberry_bold_touch_ua.is_bot)
170-
self.assertFalse(blackberry_torch_ua.is_bot)
201+
self.assertFalse(blackberry_torch_ua.is_bot)
171202
self.assertFalse(blackberry_bold_ua.is_bot)
172-
self.assertFalse(j2me_opera_ua.is_bot)
203+
self.assertFalse(j2me_opera_ua.is_bot)
173204
self.assertFalse(mac_safari_ua.is_bot)
174205
self.assertFalse(windows_ie_ua.is_bot)
175206
self.assertFalse(ubuntu_firefox_ua.is_bot)
176207
self.assertFalse(ie_touch_ua.is_bot)
177208
self.assertFalse(ie_ua.is_bot)
178209
self.assertFalse(nokia_n97_ua.is_bot)
179210
self.assertFalse(android_firefox_aurora_ua.is_bot)
211+
self.assertFalse(samsung_galaxy_s_ua.is_bot)
212+
self.assertFalse(playstation_vita_ua.is_bot)
213+
self.assertFalse(playstation_ua.is_bot)
214+
self.assertFalse(samsung_gt_ua.is_bot)
215+
180216

181217
def test_strings(self):
182218
self.assertEqual(str(iphone_ua), "iPhone / iOS 5.1 / Mobile Safari 5.1")

0 commit comments

Comments
 (0)