<commit_before>import operator

from django.db import models
from django.http import Http404
from rest_framework.generics import get_object_or_404

from threepio import api_logger as logger


class MultipleFieldLookup(object):
    lookup_fields = None

    def get_object(self):
        queryset = self.filter_queryset(self.get_queryset())
        #: field to perform lookup with
        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field

        #: kwarg value to lookup
        filter_value = self.kwargs[lookup_url_kwarg]

        #: determine the value of the field
        if filter_value.isdecimal():
            VALID_FIELDS = (models.AutoField,
                            models.IntegerField,
                            models.BigIntegerField)
        else:
            VALID_FIELDS = (models.UUIDField,
                            models.CharField,
                            models.TextField)

        filter_fields = []
        for field_name in self.lookup_fields:
            try:
                field = queryset.model._meta.get_field(field_name)
            except models.FieldDoesNotExist:
                raise Exception(
                    "The lookup field `%s` does not exist for the model %s."
                    % (field_name, queryset.model.__name__))
            if isinstance(field, VALID_FIELDS):
                filter_fields.append(field_name)

        query_list = [models.Q(**{field: filter_value}) for field in filter_fields]
        try:
            filter_chain = reduce(operator.or_, query_list)
        except TypeError:
            raise Http404

        obj = get_object_or_404(queryset, filter_chain)
        self.check_object_permissions(self.request, obj)
        return obj<commit_msg>PEP8 Compliance.<commit_after>import operator

from django.db import models
from django.db.models import Q
from django.http import Http404
from rest_framework.generics import get_object_or_404

from threepio import api_logger as logger


class MultipleFieldLookup(object):
    lookup_fields = None

    def get_object(self):
        queryset = self.filter_queryset(self.get_queryset())
        #: field to perform lookup with
        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field

        #: kwarg value to lookup
        filter_value = self.kwargs[lookup_url_kwarg]

        #: determine the value of the field
        if filter_value.isdecimal():
            VALID_FIELDS = (models.AutoField,
                            models.IntegerField,
                            models.BigIntegerField)
        else:
            VALID_FIELDS = (models.UUIDField,
                            models.CharField,
                            models.TextField)

        filter_fields = []
        for field_name in self.lookup_fields:
            try:
                field = queryset.model._meta.get_field(field_name)
            except models.FieldDoesNotExist:
                raise Exception(
                    "The lookup field `%s` does not exist for the model %s."
                    % (field_name, queryset.model.__name__))
            if isinstance(field, VALID_FIELDS):
                filter_fields.append(field_name)

        query_list = [Q(**{field: filter_value}) for field in filter_fields]
        try:
            filter_chain = reduce(operator.or_, query_list)
        except TypeError:
            raise Http404

        obj = get_object_or_404(queryset, filter_chain)
        self.check_object_permissions(self.request, obj)
        return obj
{'fraction_non_alphanumeric': 0.06717904924565898, 'fraction_numerical': 0.007116424708226587, 'mean_word_length': 1.9880952380952381, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4515784', 'n_tokens_mistral': 977, 'n_tokens_neox': 923, 'n_words': 226}