<commit_before># -*- coding: utf-8 -*-
from django.views.generic import View
from django.views.decorators.csrf import csrf_exempt, csrf_protect
from django.core.urlresolvers import resolve, reverse


class UrlResolverView(View):

    @csrf_exempt
    def dispatch(self, request, *args, **kwargs):
        """
        This view reads url name, args, kwargs from GET parameters, reverses the url and resolves view function
        Returns the result of resolved view function, called with provided args and kwargs

        Using the resolver for a csrf_exempt view would still raise CSRF verification error on UrlResolverView,
        thus the resolver must be csrf_exempt. CSRF verification is done on resolved view, if it isn't csrf_exempt
        """

        url_name = request.GET.get('djng_url_name')
        url_args = request.GET.getlist('djng_url_args', None)
        url_kwargs = {}

        for param in request.GET:
            if param.startswith('djng_url_kwarg_'):
                url_kwargs[param[15:]] = request.GET[param]  # [15:] to remove 'djng_url_kwarg' prefix

        view, args, kwargs = resolve(reverse(url_name, args=url_args, kwargs=url_kwargs))

        # Return csrf_protected view if it isn't csrf_exempt
        if hasattr(view, 'csrf_exempt'):
            if view.csrf_exempt:
                return view(request, *args, **kwargs)
        return csrf_protect(view)(request, *args, **kwargs)<commit_msg>resolver changes, add middleware processing<commit_after># -*- coding: utf-8 -*-
from django.conf import settings
from django.utils.decorators import decorator_from_middleware
from django.utils.module_loading import import_string
from django.views.generic import View
from django.views.decorators.csrf import csrf_exempt
from django.core.urlresolvers import resolve, reverse


class UrlResolverView(View):

    @csrf_exempt
    def dispatch(self, request, *args, **kwargs):
        """
        This view reads url name, args, kwargs from GET parameters, reverses the url and resolves view function
        Returns the result of resolved view function, called with provided args and kwargs

        Using the resolver for a csrf_exempt view would still raise CSRF verification error on UrlResolverView,
        thus the resolver must be csrf_exempt. CSRF/Session/Auth and other middleware checks are done when calling
        the actual view.
        """

        url_name = request.GET.get('djng_url_name')
        url_args = request.GET.getlist('djng_url_args', None)
        url_kwargs = {}

        for param in request.GET:
            if param.startswith('djng_url_kwarg_'):
                url_kwargs[param[15:]] = request.GET[param]  # [15:] to remove 'djng_url_kwarg' prefix

        view, args, kwargs = resolve(reverse(url_name, args=url_args, kwargs=url_kwargs))

        # Run through all the middlewares when calling actual view
        for middleware_path in settings.MIDDLEWARE_CLASSES:
            view = decorator_from_middleware(import_string(middleware_path))(view)
        return view(request, *args, **kwargs)
{'fraction_non_alphanumeric': 0.08129285014691479, 'fraction_numerical': 0.00326477309826967, 'mean_word_length': 3.2853146853146855, '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': '6859594', 'n_tokens_mistral': 902, 'n_tokens_neox': 882, 'n_words': 278}