Package madrona :: Package common :: Package uaparser :: Module regexes
[hide private]

Source Code for Module madrona.common.uaparser.regexes

  1  #!/usr/bin/python2.4 
  2  # 
  3  # Copyright 2009 Google Inc. 
  4  # 
  5  # Licensed under the Apache License, Version 2.0 (the "License"); 
  6  # you may not use this file except in compliance with the License. 
  7  # You may obtain a copy of the License at 
  8  # 
  9  #     http://www.apache.org/licenses/LICENSE-2.0 
 10  # 
 11  # Unless required by applicable law or agreed to in writing, software 
 12  # distributed under the License is distributed on an "AS IS" BASIS, 
 13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 14  # See the License for the specific language governing permissions and 
 15  # limitations under the License. 
 16   
 17  """Regexes.""" 
 18   
 19  import parser 
 20   
 21   
 22  browser_slash_v123_names = ( 
 23      'Jasmine|ANTGalio|Midori|Fresco|Lobo|Maxthon|Lynx|OmniWeb|Dillo|Camino|' 
 24      'Demeter|Fluid|Fennec|Shiira|Sunrise|Chrome|Flock|Netscape|Lunascape|' 
 25      'Epiphany|WebPilot|Vodafone|NetFront|Konqueror|SeaMonkey|Kazehakase|' 
 26      'Vienna|Iceape|Iceweasel|IceWeasel|Iron|K-Meleon|Sleipnir|Galeon|' 
 27      'GranParadiso|Opera Mini|iCab|NetNewsWire|Iron|Iris') 
 28   
 29  browser_slash_v12_names = ( 
 30      'Bolt|Jasmine|Maxthon|Lynx|Arora|IBrowse|Dillo|Camino|Shiira|Fennec|' 
 31      'Phoenix|Chrome|Flock|Netscape|Lunascape|Epiphany|WebPilot|' 
 32      'Opera Mini|Opera|Vodafone|' 
 33      'NetFront|Konqueror|SeaMonkey|Kazehakase|Vienna|Iceape|Iceweasel|IceWeasel|' 
 34      'Iron|K-Meleon|Sleipnir|Galeon|GranParadiso|' 
 35      'iCab|NetNewsWire|Iron|Space Bison|Stainless|Orca') 
 36   
 37  _P = parser.UserAgentParser 
 38  USER_AGENT_PARSERS = ( 
 39    #### SPECIAL CASES TOP #### 
 40    # must go before Opera 
 41    _P(r'^(Opera)/(\d+)\.(\d+) \(Nintendo Wii', family_replacement='Wii'), 
 42    # must go before Browser/v1.v2 - eg: Minefield/3.1a1pre 
 43    _P(r'(Namoroka|Shiretoko|Minefield)/(\d+)\.(\d+)\.(\d+(?:pre)?)', 
 44       'Firefox ($1)'), 
 45    _P(r'(Namoroka|Shiretoko|Minefield)/(\d+)\.(\d+)([ab]\d+[a-z]*)?', 
 46       'Firefox ($1)'), 
 47    _P(r'(SeaMonkey|Fennec|Camino)/(\d+)\.(\d+)([ab]?\d+[a-z]*)'), 
 48    # e.g.: Flock/2.0b2 
 49    _P(r'(Flock)/(\d+)\.(\d+)(b\d+?)'), 
 50   
 51    # e.g.: Fennec/0.9pre 
 52    _P(r'(Fennec)/(\d+)\.(\d+)(pre)'), 
 53    _P(r'(Navigator)/(\d+)\.(\d+)\.(\d+)', 'Netscape'), 
 54    _P(r'(Navigator)/(\d+)\.(\d+)([ab]\d+)', 'Netscape'), 
 55    _P(r'(Netscape6)/(\d+)\.(\d+)\.(\d+)', 'Netscape'), 
 56    _P(r'(MyIBrow)/(\d+)\.(\d+)', 'My Internet Browser'), 
 57    _P(r'(Firefox).*Tablet browser (\d+)\.(\d+)\.(\d+)', 'MicroB'), 
 58    # Opera will stop at 9.80 and hide the real version in the Version string. 
 59    # see: http://dev.opera.com/articles/view/opera-ua-string-changes/ 
 60    _P(r'(Opera)/9.80.*Version\/(\d+)\.(\d+)(?:\.(\d+))?'), 
 61   
 62    _P(r'(Firefox)/(\d+)\.(\d+)\.(\d+(?:pre)?) \(Swiftfox\)', 'Swiftfox'), 
 63    _P(r'(Firefox)/(\d+)\.(\d+)([ab]\d+[a-z]*)? \(Swiftfox\)', 'Swiftfox'), 
 64   
 65    # catches lower case konqueror 
 66    _P(r'(konqueror)/(\d+)\.(\d+)\.(\d+)', 'Konqueror'), 
 67   
 68    #### END SPECIAL CASES TOP #### 
 69   
 70    #### MAIN CASES - this catches > 50% of all browsers #### 
 71    # Browser/v1.v2.v3 
 72    _P(r'(%s)/(\d+)\.(\d+)\.(\d+)' % browser_slash_v123_names), 
 73    # Browser/v1.v2 
 74    _P(r'(%s)/(\d+)\.(\d+)' % browser_slash_v12_names), 
 75    # Browser v1.v2.v3 (space instead of slash) 
 76    _P(r'(iRider|Crazy Browser|SkipStone|iCab|Lunascape|Sleipnir|Maemo Browser) (\d+)\.(\d+)\.(\d+)'), 
 77    # Browser v1.v2 (space instead of slash) 
 78    _P(r'(iCab|Lunascape|Opera|Android) (\d+)\.(\d+)'), 
 79    _P(r'(IEMobile) (\d+)\.(\d+)', 'IE Mobile'), 
 80    # DO THIS AFTER THE EDGE CASES ABOVE! 
 81    _P(r'(Firefox)/(\d+)\.(\d+)\.(\d+)'), 
 82    _P(r'(Firefox)/(\d+)\.(\d+)(pre|[ab]\d+[a-z]*)?'), 
 83    #### END MAIN CASES #### 
 84   
 85    #### SPECIAL CASES #### 
 86    #_P(r''), 
 87    _P(r'(Obigo|OBIGO)[^\d]*(\d+)(?:.(\d+))?', 'Obigo'), 
 88    _P(r'(MAXTHON|Maxthon) (\d+)\.(\d+)', family_replacement='Maxthon'), 
 89    _P(r'(Maxthon|MyIE2|Uzbl|Shiira)', v1_replacement='0'), 
 90    _P(r'(PLAYSTATION) (\d+)', family_replacement='PlayStation'), 
 91    _P(r'(PlayStation Portable)[^\d]+(\d+).(\d+)'), 
 92    _P(r'(BrowseX) \((\d+)\.(\d+)\.(\d+)'), 
 93    _P(r'(Opera)/(\d+)\.(\d+).*Opera Mobi', 'Opera Mobile'), 
 94    _P(r'(POLARIS)/(\d+)\.(\d+)', family_replacement='Polaris'), 
 95    _P(r'(BonEcho)/(\d+)\.(\d+)\.(\d+)', 'Bon Echo'), 
 96    _P(r'(iPhone) OS (\d+)_(\d+)(?:_(\d+))?'), 
 97    _P(r'(Avant)', v1_replacement='1'), 
 98    _P(r'(Nokia)[EN]?(\d+)'), 
 99    _P(r'(Black[bB]erry)(\d+)', family_replacement='Blackberry'), 
100    _P(r'(OmniWeb)/v(\d+)\.(\d+)'), 
101    _P(r'(Blazer)/(\d+)\.(\d+)', 'Palm Blazer'), 
102    _P(r'(Pre)/(\d+)\.(\d+)', 'Palm Pre'), 
103    _P(r'(Links) \((\d+)\.(\d+)'), 
104    _P(r'(QtWeb) Internet Browser/(\d+)\.(\d+)'), 
105    _P(r'(Version)/(\d+)\.(\d+)(?:\.(\d+))?.*Safari/', 
106       family_replacement='Safari'), 
107    _P(r'(OLPC)/Update(\d+)\.(\d+)'), 
108    _P(r'(OLPC)/Update()\.(\d+)', v1_replacement='0'), 
109    _P(r'(SamsungSGHi560)', family_replacement='Samsung SGHi560'), 
110    _P(r'^(SonyEricssonK800i)', family_replacement='Sony Ericsson K800i'), 
111    _P(r'(Teleca Q7)'), 
112    _P(r'(MSIE) (\d+)\.(\d+)', family_replacement='IE'), 
113  ) 
114