當前位置: 首頁>>代碼示例>>Python>>正文


Python user_agent_parser.Parse方法代碼示例

本文整理匯總了Python中ua_parser.user_agent_parser.Parse方法的典型用法代碼示例。如果您正苦於以下問題:Python user_agent_parser.Parse方法的具體用法?Python user_agent_parser.Parse怎麽用?Python user_agent_parser.Parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ua_parser.user_agent_parser的用法示例。


在下文中一共展示了user_agent_parser.Parse方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_user_agent_object_assignments

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def test_user_agent_object_assignments(self):
        ua_dict = user_agent_parser.Parse(devices['iphone']['ua_string'])
        iphone_ua = devices['iphone']['user_agent']

        # Ensure browser attributes are assigned correctly
        self.assertEqual(iphone_ua.browser.family,
                         ua_dict['user_agent']['family'])
        self.assertEqual(
            iphone_ua.browser.version,
            (int(ua_dict['user_agent']['major']),
             int(ua_dict['user_agent']['minor']))
        )

        # Ensure os attributes are assigned correctly
        self.assertEqual(iphone_ua.os.family, ua_dict['os']['family'])
        self.assertEqual(
            iphone_ua.os.version,
            (int(ua_dict['os']['major']), int(ua_dict['os']['minor']))
        )

        # Ensure device attributes are assigned correctly
        self.assertEqual(iphone_ua.device.family,
                         ua_dict['device']['family']) 
開發者ID:yandenghong,項目名稱:KortURL,代碼行數:25,代碼來源:tests.py

示例2: parse_sort_key

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def parse_sort_key(sort_key):
        # type: (str) -> Dict[str, Any]
        """Parse the sort key from the database"""
        topic = None
        sortkey_timestamp = None
        message_id = None
        if sort_key.startswith("01:"):
            api_ver, channel_id, topic = sort_key.split(":")
        elif sort_key.startswith("02:"):
            api_ver, raw_sortkey, channel_id = sort_key.split(":")
            sortkey_timestamp = int(raw_sortkey)
        else:
            channel_id, message_id = sort_key.split(":")
            api_ver = "00"
        return dict(api_ver=api_ver, channel_id=channel_id,
                    topic=topic, message_id=message_id,
                    sortkey_timestamp=sortkey_timestamp) 
開發者ID:mozilla-services,項目名稱:autopush,代碼行數:19,代碼來源:utils.py

示例3: external_task_browser_check

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def external_task_browser_check(request):
    if request.method == "GET":
        valid_browser = False
        if 'HTTP_USER_AGENT' in request.META:
            ua = user_agent_parser.Parse(request.META['HTTP_USER_AGENT'])
            if ua['user_agent']['family'].lower() in ('firefox', 'chrome'):
                device = ua['device']
                if 'is_mobile' not in device or not device['is_mobile']:
                    valid_browser = True
        if not valid_browser:
            return html_error_response(
                request, '''
                This task requires Google Chrome. <br/><br/>
                <a class="btn" href="http://www.google.com/chrome/"
                target="_blank">Get Google Chrome</a>
            ''')
    return None 
開發者ID:seanbell,項目名稱:opensurfaces,代碼行數:19,代碼來源:external.py

示例4: clean_addresses

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def clean_addresses(emails):
    """Takes a string of emails and returns a list of tuples of name/address
    pairs that are symanticly valid"""

    # Parse our string of emails, discarding invalid/illegal addresses
    valid_emails_list = address.parse_list(emails)

    # If no valid email addresses are found, return an empty list
    if not valid_emails_list:
        return []

    # If we have valid emails, use flanker's unicode address list creator to
    # give us something to pass to Python's email library's getaddresses
    valid_emails = valid_emails_list.to_unicode()

    # Return a list, in ('Name', 'email@dj.local')] form, the resulting emails
    email_list = getaddresses([valid_emails])

    # Lowercase all the email addresses in the list
    lowered_list = [(name, email.lower()) for name, email in email_list]
    return lowered_list 
開發者ID:ofa,項目名稱:connect,代碼行數:23,代碼來源:utils.py

示例5: __init__

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def __init__(self, user_agent_string):
        ua_dict = user_agent_parser.Parse(user_agent_string)
        self.ua_string = user_agent_string
        self.os = parse_operating_system(**ua_dict['os'])
        self.browser = parse_browser(**ua_dict['user_agent'])
        self.device = parse_device(**ua_dict['device']) 
開發者ID:yandenghong,項目名稱:KortURL,代碼行數:8,代碼來源:parsers.py

示例6: __init__

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def __init__(self, user_agent_string=""):
        user_agent_parsed = user_agent_parser.Parse(
            user_agent_string if user_agent_string else ""
        )
        self.user_agent = user_agent_parsed.get("user_agent", dict())
        self.user_agent_os = user_agent_parsed.get("os", dict())
        self.user_agent_device = user_agent_parsed.get("device", dict())
        self.user_agent_string = user_agent_parsed.get("string", "") 
開發者ID:jotes,項目名稱:django-cookies-samesite,代碼行數:10,代碼來源:user_agent_checker.py

示例7: user_agent_parsed

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def user_agent_parsed(self):
        return user_agent_parser.Parse(self.user_agent) 
開發者ID:seanbell,項目名稱:opensurfaces,代碼行數:4,代碼來源:models.py

示例8: __init__

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def __init__(self, ua):
        self._agent = user_agent_parser.Parse(ua)

        os_family = self._agent['os']['family']
        browser_family = self._agent['user_agent']['family']

        family = None

        if os_family == 'Android':
            if 'Firefox' in browser_family:
                family = 'and_ff'
            elif 'Chrome' in browser_family:
                family = 'and_chr'
            elif 'Android' in browser_family:
                family = 'android'
        else:
            if 'Edge' in browser_family:
                family = 'edge'
            elif 'Firefox' in browser_family:
                family = 'firefox'
            elif 'Chrome' in browser_family:
                family = 'chrome'
            elif 'IE' in browser_family:
                family = 'ie'
            elif 'Opera' in browser_family:
                family = 'opera'
            elif 'Safari' in browser_family:
                family = 'safari'

        self._family = family 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:32,代碼來源:caniuse.py

示例9: testParseAll

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def testParseAll(self):
        user_agent_string = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; fr; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5,gzip(gfe),gzip(gfe)'
        expected = {
            'device': {
                'family': 'Other',
                'brand': None,
                'model': None
            },
            'os': {
                'family': 'Mac OS X',
                'major': '10',
                'minor': '4',
                'patch': None,
                'patch_minor': None
            },
            'user_agent': {
                'family': 'Firefox',
                'major': '3',
                'minor': '5',
                'patch': '5'
            },
            'string': user_agent_string
        }

        result = user_agent_parser.Parse(user_agent_string)
        self.assertEqual(
            result, expected,
            "UA: {0}\n expected<{1}> != actual<{2}>".format(user_agent_string, expected, result))
    # Make a YAML file for manual comparsion with pgts_browser_list-orig.yaml 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:31,代碼來源:user_agent_parser_test.py

示例10: runUserAgentTestsFromYAML

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def runUserAgentTestsFromYAML(self, file_name):
        yamlFile = open(os.path.join(TEST_RESOURCES_DIR, file_name))
        yamlContents = yaml.load(yamlFile)
        yamlFile.close()

        for test_case in yamlContents['test_cases']:
            # Inputs to Parse()
            user_agent_string = test_case['user_agent_string']
            kwds = {}
            if 'js_ua' in test_case:
                kwds = eval(test_case['js_ua'])

            # The expected results
            expected = {'family': test_case['family'],
                        'major': test_case['major'],
                        'minor': test_case['minor'],
                        'patch': test_case['patch']}

            result = {}
            result = user_agent_parser.ParseUserAgent(user_agent_string, **kwds)
            self.assertEqual(
                result, expected,
                "UA: {0}\n expected<{1}, {2}, {3}, {4}> != actual<{5}, {6}, {7}, {8}>".format(
                    user_agent_string,
                    expected['family'], expected['major'], expected['minor'], expected['patch'],
                    result['family'], result['major'], result['minor'], result['patch'])) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:28,代碼來源:user_agent_parser_test.py

示例11: runOSTestsFromYAML

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def runOSTestsFromYAML(self, file_name):
        yamlFile = open(os.path.join(TEST_RESOURCES_DIR, file_name))
        yamlContents = yaml.load(yamlFile)
        yamlFile.close()

        for test_case in yamlContents['test_cases']:
            # Inputs to Parse()
            user_agent_string = test_case['user_agent_string']
            kwds = {}
            if 'js_ua' in test_case:
                kwds = eval(test_case['js_ua'])

            # The expected results
            expected = {
                'family': test_case['family'],
                'major': test_case['major'],
                'minor': test_case['minor'],
                'patch': test_case['patch'],
                'patch_minor': test_case['patch_minor']
            }

            result = user_agent_parser.ParseOS(user_agent_string, **kwds)
            self.assertEqual(
                result, expected,
                "UA: {0}\n expected<{1} {2} {3} {4} {5}> != actual<{6} {7} {8} {9} {10}>".format(
                    user_agent_string,
                    expected['family'],
                    expected['major'],
                    expected['minor'],
                    expected['patch'],
                    expected['patch_minor'],
                    result['family'],
                    result['major'],
                    result['minor'],
                    result['patch'],
                    result['patch_minor'])) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:38,代碼來源:user_agent_parser_test.py

示例12: runDeviceTestsFromYAML

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def runDeviceTestsFromYAML(self, file_name):
        yamlFile = open(os.path.join(TEST_RESOURCES_DIR, file_name))
        yamlContents = yaml.load(yamlFile)
        yamlFile.close()

        for test_case in yamlContents['test_cases']:
            # Inputs to Parse()
            user_agent_string = test_case['user_agent_string']
            kwds = {}
            if 'js_ua' in test_case:
                kwds = eval(test_case['js_ua'])

            # The expected results
            expected = {
                'family': test_case['family'],
                'brand': test_case['brand'],
                'model': test_case['model']
            }

            result = user_agent_parser.ParseDevice(user_agent_string, **kwds)
            self.assertEqual(
                result, expected,
                "UA: {0}\n expected<{1} {2} {3}> != actual<{4} {5} {6}>".format(
                    user_agent_string,
                    expected['family'],
                    expected['brand'],
                    expected['model'],
                    result['family'],
                    result['brand'],
                    result['model'])) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:32,代碼來源:user_agent_parser_test.py

示例13: process_useragent

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def process_useragent(useragent):
    """Convert a useragent into something useful"""
    parsed_agent = user_agent_parser.Parse(useragent)

    browser = prettify_agent_version(parsed_agent['user_agent'])
    operating_system = prettify_agent_version(parsed_agent['os'])
    device = parsed_agent['device']['family']
    return (operating_system, browser, device) 
開發者ID:ofa,項目名稱:connect,代碼行數:10,代碼來源:utils.py

示例14: parse_user_agent

# 需要導入模塊: from ua_parser import user_agent_parser [as 別名]
# 或者: from ua_parser.user_agent_parser import Parse [as 別名]
def parse_user_agent(agent_string):
    # type: (str) -> Tuple[Dict[str, str], Dict[str, Any]]
    """Extracts user-agent data from a UA string

    Parses the user-agent into two forms. A limited one suitable for Datadog
    logging with limited tags, and a full string suitable for complete logging.

    :returns: A tuple of dicts, the first being the Datadog limited and the
              second being the complete info.

    """
    parsed = user_agent_parser.Parse(agent_string)
    dd_info = {}
    raw_info = {}

    # Parse out the OS family
    ua_os = parsed["os"]
    ua_os_family = raw_info["ua_os_family"] = ua_os["family"]
    if ua_os_family.startswith("Windows"):
        # Windows has a bunch of additional version bits in the family string
        dd_info["ua_os_family"] = "Windows"
    elif ua_os_family in VALID_UA_OS:
        dd_info["ua_os_family"] = ua_os_family
    elif "Linux" in agent_string:
        # Incredibly annoying, but the user agent parser returns things like
        # 'Mandriva' and 'Unbuntu' sometimes instead of just saying Linux
        dd_info["ua_os_family"] = "Linux"
    else:
        dd_info["ua_os_family"] = "Other"

    # Parse out the full version for raw info, too many combos for DataDog
    bits = ["major", "minor", "patch", "patch_minor"]
    os_bits = [ua_os[x] for x in bits]
    raw_info["ua_os_ver"] = ".".join(filter(None, os_bits))

    # Parse out the browser family
    ua_browser = parsed["user_agent"]
    ua_browser_family = raw_info["ua_browser_family"] = ua_browser["family"]
    if ua_browser_family in VALID_UA_BROWSER:
        dd_info["ua_browser_family"] = ua_browser_family
    else:
        dd_info["ua_browser_family"] = "Other"

    # Parse out the full browser version
    bits = ["major", "minor", "patch"]
    browser_bits = [ua_browser[x] for x in bits]
    raw_info["ua_browser_ver"] = ".".join(filter(None, browser_bits))

    return dd_info, raw_info 
開發者ID:mozilla-services,項目名稱:autopush,代碼行數:51,代碼來源:utils.py


注:本文中的ua_parser.user_agent_parser.Parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。