<commit_before>from __future__ import absolute_import

from rest_framework.generics import GenericAPIView
from rest_framework.views import APIView

from ._django import apply_http_methods, create_handler


def api_view(injector):
    """Create DRF class-based API view from injector class."""

    handler = create_handler(APIView)
    apply_http_methods(handler, injector)
    apply_api_view_methods(handler, injector)
    return injector.let(as_view=handler.as_view)


def generic_api_view(injector):
    """Create DRF generic class-based API view from injector class."""

    handler = create_handler(GenericAPIView)
    apply_http_methods(handler, injector)
    apply_api_view_methods(handler, injector)
    apply_generic_api_view_methods(handler, injector)
    return injector.let(as_view=handler.as_view)


def apply_api_view_methods(handler, injector):

    if "renderer_classes" in injector:
        handler.renderer_classes = injector.renderer_classes
    if "parser_classes" in injector:
        handler.parser_classes = injector.parser_classes
    if "permission_classes" in injector:
        handler.permission_classes = injector.permission_classes


def apply_generic_api_view_methods(handler, injector):

    handler.queryset = injector.queryset
    handler.serializer_class = injector.serializer_cls
    if "lookup_field" in injector:
        handler.lookup_field = injector.lookup_field
    if "lookup_url_kwarg" in injector:
        handler.lookup_url_kwarg = injector.lookup_url_kwarg
    if "filter_backends" in injector:
        handler.filter_backends = injector.filter_backends
    if "filter_cls" in injector:
        handler.filter_class = injector.filter_cls
    if "pagination_cls" in injector:
        handler.pagination_class = injector.pagination_cls


# TODO:
#
# APIView.authentication_classes
# APIView.throttle_classes
# APIView.content_negotiation_class<commit_msg>Make queryset and serializer_cls optional attributes to the generic DRF view.<commit_after>from __future__ import absolute_import

from rest_framework.generics import GenericAPIView
from rest_framework.views import APIView

from ._django import apply_http_methods, create_handler


def api_view(injector):
    """Create DRF class-based API view from injector class."""

    handler = create_handler(APIView)
    apply_http_methods(handler, injector)
    apply_api_view_methods(handler, injector)
    return injector.let(as_view=handler.as_view)


def generic_api_view(injector):
    """Create DRF generic class-based API view from injector class."""

    handler = create_handler(GenericAPIView)
    apply_http_methods(handler, injector)
    apply_api_view_methods(handler, injector)
    apply_generic_api_view_methods(handler, injector)
    return injector.let(as_view=handler.as_view)


def apply_api_view_methods(handler, injector):

    if "renderer_classes" in injector:
        handler.renderer_classes = injector.renderer_classes
    if "parser_classes" in injector:
        handler.parser_classes = injector.parser_classes
    if "permission_classes" in injector:
        handler.permission_classes = injector.permission_classes


def apply_generic_api_view_methods(handler, injector):

    if "queryset" in injector:
        handler.queryset = injector.queryset
    if "serializer_cls" in injector:
        handler.serializer_class = injector.serializer_cls
    if "lookup_field" in injector:
        handler.lookup_field = injector.lookup_field
    if "lookup_url_kwarg" in injector:
        handler.lookup_url_kwarg = injector.lookup_url_kwarg
    if "filter_backends" in injector:
        handler.filter_backends = injector.filter_backends
    if "filter_cls" in injector:
        handler.filter_class = injector.filter_cls
    if "pagination_cls" in injector:
        handler.pagination_class = injector.pagination_cls


# TODO:
#
# APIView.authentication_classes
# APIView.throttle_classes
# APIView.content_negotiation_class
{'fraction_non_alphanumeric': 0.06830878618588115, 'fraction_numerical': 0.0, 'mean_word_length': 4.627142857142857, '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': '2964100', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1173, 'n_words': 253}