Beispiel #1
0
    def _match(self):
        # Fetch client IP address.
        client_ip = self._request.META.get('REMOTE_ADDR')
        if 'HTTP_X_FORWARDED_FOR' in self._request.META:
            # HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.
            # Take just the first valid one (proxies like squid may introduce
            # invalid values like 'unknown' under certain configurations, so
            # a validations is always required).
            for ip in self._request.META['HTTP_X_FORWARDED_FOR'].split(','):
                ip = ip.strip()
                try:
                    validate_ipv46_address(ip)
                    client_ip = ip
                    break
                except ValidationError:
                    pass

        # Fetch HTTP headers.
        # See: https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.META
        http_headers = {}
        for name, value in self._request.META.iteritems():
            if name in (
                    'CONTENT_LENGTH',
                    'CONTENT_TYPE',
            ):
                http_headers[self._normalized_header_name(name)] = value
            elif name.startswith('HTTP_'):
                http_headers[self._normalized_header_name(name[5:])] = value

        # Match.
        return mobile_detector.match(http_headers)
    def _match(self):
        # Fetch client IP address.
        client_ip = self._request.META.get('REMOTE_ADDR')
        if 'HTTP_X_FORWARDED_FOR' in self._request.META:
            # HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.
            # Take just the first valid one (proxies like squid may introduce
            # invalid values like 'unknown' under certain configurations, so
            # a validations is always required).
            for ip in self._request.META['HTTP_X_FORWARDED_FOR'].split(','):
                ip = ip.strip()
                try:
                    validate_ipv46_address(ip)
                    client_ip = ip
                    break
                except ValidationError:
                    pass

        # Fetch HTTP headers.
        # See: https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.META
        http_headers = {}
        for name, value in self._request.META.iteritems():
            if name in ('CONTENT_LENGTH', 'CONTENT_TYPE',):
                http_headers[self._normalized_header_name(name)] = value
            elif name.startswith('HTTP_'):
                http_headers[self._normalized_header_name(name[5:])] = value

        # Match.
        return mobile_detector.match(http_headers)
Beispiel #3
0
def match(args, help):
    if len(args) == 1:
        from fiftyone_degrees import mobile_detector
        device = mobile_detector.match(args[0])
        for name, value in device.properties.iteritems():
            sys.stdout.write('%s: %s\n' % (name, unicode(value),))
    else:
        sys.stderr.write(help)
        sys.exit(1)
def match(args, help):
    if len(args) == 1:
        from fiftyone_degrees import mobile_detector
        device = mobile_detector.match(args[0])
        for name, value in device.properties.iteritems():
            sys.stdout.write('%s: %s\n' % (name, unicode(value),))
    else:
        sys.stderr.write(help)
        sys.exit(1)