コード例 #1
0
    def Parse(self, user_agent_string):
        family, v1, v2, v3 = None, None, None, None
        match = self.user_agent_re.search(user_agent_string)
        if match:
            if self.family_replacement:
                if re.search(r'\$1', self.family_replacement):
                    family = re.sub(r'\$1', match.group(1), self.family_replacement)
                else:
                    family = self.family_replacement
            else:
                family = match.group(1)

            if self.v1_replacement:
                v1 = self.v1_replacement
            elif match.lastindex and match.lastindex >= 2:
                v1 = match.group(2)

            if self.v2_replacement:
                v2 = self.v2_replacement
            elif match.lastindex and match.lastindex >= 3:
                v2 = match.group(3)

            if match.lastindex and match.lastindex >= 4:
                v3 = match.group(4)

        return family, v1, v2, v3
コード例 #2
0
    def Parse(self, user_agent_string):
        device = None
        match = self.user_agent_re.search(user_agent_string)
        if match:
            if self.device_replacement:
                if re.search(r'\$1', self.device_replacement):
                    device = re.sub(r'\$1', match.group(1), self.device_replacement)
                else:
                    device = self.device_replacement
            else:
                device = match.group(1)

        return device