<commit_before>from functools import wraps
from django.core.urlresolvers import reverse
from django.views.generic import View
from django.http import HttpResponseBadRequest
from django.conf.urls.defaults import url
from django.contrib.auth.decorators import login_required

from serializers import serialize, SerializableResult


def extjshacks(f):
    @wraps(f)
    def wrapper(self, request, *args, **kwargs):
        self.use_extjshacks = bool(request.META.get('HTTP_X_DEVILRY_USE_EXTJS', False))
        return f(self, request, *args, **kwargs)
    return wrapper

class RestfulView(View):
    """
    :class:`RestfulView` and the :func:`restful_api`-decorator is use in
    conjunction to create a RESTful web service with a CRUD+S interface.
    """

    @classmethod
    def create_rest_url(cls):
        """
        Create a ``django.conf.urls.defaults.url``-object for this view::

            r'^{urlprefix}/(?P<id>[a-zA-Z0-9]+)?$

        Where ``urlprefix`` is ``cls._meta.urlprefix`` documented in
        :func:`restful_api`.

        The name of the url is the ``cls._meta.urlname``, documented in
        :func:`restful_api`.

        The view is wrapped by :func:`django.contrib.auth.decorators.login_required`.
        """
        return url(r'^{urlprefix}/(?P<id>[a-zA-Z0-9]+)?$'.format(urlprefix=cls._meta.urlprefix),
            login_required(cls.as_view()),
            name=cls._meta.urlname)

    @classmethod
    def get_rest_url(cls, *args, **kwargs):<commit_msg>restful: forbidden_if_no_authenticated instead of login_required<commit_after>from functools import wraps
from django.core.urlresolvers import reverse
from django.views.generic import View
from django.http import HttpResponseBadRequest, HttpResponseForbidden
from django.conf.urls.defaults import url
from django.contrib.auth.decorators import login_required

from serializers import serialize, SerializableResult


def extjshacks(f):
    @wraps(f)
    def wrapper(self, request, *args, **kwargs):
        self.use_extjshacks = bool(request.META.get('HTTP_X_DEVILRY_USE_EXTJS', False))
        return f(self, request, *args, **kwargs)
    return wrapper

def forbidden_if_no_authenticated(f):
    @wraps(f)
    def wrapper(request, *args, **kwargs):
        if request.user.is_authenticated():
            return f(request, *args, **kwargs)
        else:
            return HttpResponseForbidden()
    return wrapper

class RestfulView(View):
    """
    :class:`RestfulView` and the :func:`restful_api`-decorator is use in
    conjunction to create a RESTful web service with a CRUD+S interface.
    """

    @classmethod
    def create_rest_url(cls):
        """
        Create a ``django.conf.urls.defaults.url``-object for this view::

            r'^{urlprefix}/(?P<id>[a-zA-Z0-9]+)?$

        Where ``urlprefix`` is ``cls._meta.urlprefix`` documented in
        :func:`restful_api`.

        The name of the url is the ``cls._meta.urlname``, documented in
        :func:`restful_api`.

        The view is wrapped by :func:`django.contrib.auth.decorators.login_required`.
        """
        return url(r'^{urlprefix}/(?P<id>[a-zA-Z0-9]+)?$'.format(urlprefix=cls._meta.urlprefix),
            forbidden_if_no_authenticated(cls.as_view()),
            name=cls._meta.urlname)

    @classmethod
    def get_rest_url(cls, *args, **kwargs):
{'fraction_non_alphanumeric': 0.12334933973589436, 'fraction_numerical': 0.0024009603841536613, 'mean_word_length': 3.414569536423841, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2944796', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1038, 'n_words': 242}