def test_operaParser(self): """ It should be possible to invoke the Opera parser via L{UserAgent.parse} with an appropriate string. """ agent = UserAgent.fromHeaderValue('Opera/9.20 (Windows NT 6.0; U; en)') self.assertEqual(agent.browser, browsers.OPERA)
def test_msieParser(self): """ It should be possible to invoke the MSIE parser via L{UserAgent.parse} with an appropriate string. """ agent = UserAgent.fromHeaderValue( 'Mozilla/4.0 (compatible; MSIE 4.5; Windows 98; Win 9x 4.8410008)') self.assertEqual(agent.browser, browsers.INTERNET_EXPLORER)
def test_webkitParser(self): """ It should be possible to invoke the WebKit parser via L{UserAgent.parse} with an appropriate string. """ agent = UserAgent.fromHeaderValue( 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/420+ ' '(KHTML, like Gecko, Safari/420) OmniWeb/v607.17') self.assertEqual(agent.browser, browsers.WEBKIT)
def test_geckoParser(self): """ It should be possible to invoke the Gecko parser via L{UserAgent.parse} with an appropriate string. """ agent = UserAgent.fromHeaderValue( 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ja-JP; rv:1.4) ' 'Gecko/20030624 Netscape/7.1 (ax)') self.assertEqual(agent.browser, browsers.GECKO)
def isMobileClient(request): agentString = request.getHeader("user-agent") if agentString is None: return False agent = UserAgent.fromHeaderValue(agentString) if agent is None: return False requiredVersion = mobileClients.get(agent.browser, None) if requiredVersion is not None: return agent.version >= requiredVersion return False