handle webkit; make robot a dict (since robots may run on specific systems or emulate specific browsers, they should be returned separately)

This commit is contained in:
rolux 2012-03-27 12:20:22 +02:00
parent 4bb4e31b48
commit 6ed4a2d867

View file

@ -43,6 +43,7 @@ UA_ALIASES = {
'Chrome': '(CrMo)', 'Chrome': '(CrMo)',
'Firefox': '(Fennec|Firebird|Iceweasel|Minefield|Namoroka|Phoenix|SeaMonkey|Shiretoko)' 'Firefox': '(Fennec|Firebird|Iceweasel|Minefield|Namoroka|Phoenix|SeaMonkey|Shiretoko)'
}, },
'robot': {},
'system': { 'system': {
'BSD': '(FreeBSD|NetBSD|OpenBSD)', 'BSD': '(FreeBSD|NetBSD|OpenBSD)',
'Linux': '(CrOS|MeeGo|webOS)', 'Linux': '(CrOS|MeeGo|webOS)',
@ -54,6 +55,7 @@ UA_NAMES = {
'chromeframe': 'Chrome Frame', 'chromeframe': 'Chrome Frame',
'MSIE': 'Internet Explorer' 'MSIE': 'Internet Explorer'
}, },
'robot': {},
'system': { 'system': {
'CPU OS': 'iOS', 'CPU OS': 'iOS',
'iPhone OS': 'iOS', 'iPhone OS': 'iOS',
@ -62,22 +64,25 @@ UA_NAMES = {
} }
UA_REGEXPS = { UA_REGEXPS = {
'browser': [ 'browser': [
'(BingPreview)\/(\d+)',
'(Camino)\/(\d+)', '(Camino)\/(\d+)',
'(chromeframe)\/(\d+)', '(chromeframe)\/(\d+)',
'(Google Web Preview).+Chrome\/(\d+)',
'(Chrome)\/(\d+)', '(Chrome)\/(\d+)',
'(Epiphany)\/(\d+)', '(Epiphany)\/(\d+)',
'(Firefox)\/(\d+)', '(Firefox)\/(\d+)',
'(Galeon)\/(\d+)', '(Galeon)\/(\d+)',
'(Googlebot)\/(\d+)',
'(Konqueror)\/(\d+)', '(Konqueror)\/(\d+)',
'(MSIE) (\d+)', '(MSIE) (\d+)',
'(Netscape)\d?\/(\d+)', '(Netscape)\d?\/(\d+)',
'(NokiaBrowser)\/(\d+)', '(NokiaBrowser)\/(\d+)',
'(Opera) (\d+)', '(Opera) (\d+)',
'(Opera)\/.+Version\/(\d+)', '(Opera)\/.+Version\/(\d+)',
'Version\/(\d+).+(Safari)' 'Version\/(\d+).+(Safari)',
'(WebKit)\/(\d+)'
],
'robot': [
'(BingPreview)\/(\d+)',
'(Google Web Preview).+Chrome\/(\d+)',
'(Googlebot)\/(\d+)'
], ],
'system': [ 'system': [
'(Android) (\d+)', '(Android) (\d+)',
@ -105,9 +110,9 @@ UA_REGEXPS = {
'(Windows).+(WinNT4.0)' # Firefox '(Windows).+(WinNT4.0)' # Firefox
] ]
} }
UA_ROBOTS = ['BingPreview', 'Google Web Preview', 'Googlebot']
UA_VERSIONS = { UA_VERSIONS = {
'browser': {}, 'browser': {},
'robot': {},
'system': { 'system': {
'10.0': '10.0 (Cheetah)', '10.0': '10.0 (Cheetah)',
'10.1': '10.1 (Puma)', '10.1': '10.1 (Puma)',
@ -285,7 +290,6 @@ def parse_useragent(useragent):
'string': string 'string': string
} }
break; break;
data['robot'] = data['browser']['name'] in UA_ROBOTS
return data return data
def removeSpecialCharacters(text): def removeSpecialCharacters(text):