<commit_before>import inspect
from functools import wraps
from django.http import *
import re
import sys

import warnings
from .helper import ApplicationHelper
from django.utils.translation import ugettext as _
from django.conf.urls import url, include
from django import VERSION
if VERSION[:2]<(1,9):
    from django.conf.urls import patterns

from .exceptions import InvalidActionError
from .exceptions import InvalidControllerError

def get_controller_name(controller_class, with_prefix = True):
    controller_name = getattr(controller_class, 'controller_name', None)
    if controller_name is None:
        name_ = [controller_class.__name__[0]]
        prev = ''
        for l in re.sub(r"Controller$",'',controller_class.__name__[1:]):
            if l.isupper() and prev.islower():
                name_.append('_'+l)
            else:
                name_.append(l)
            prev = l
        controller_name = ''.join(name_).lower()

    controller_prefix = getattr(controller_class, 'controller_prefix', None)
    if with_prefix and controller_prefix not in (None, ''):
        controller_name = controller_class.controller_prefix + controller_name
    return controller_name

def autoview_function(site, request, controller_name, controller_class, action_name = 'index', *args, **kwargs):
    error_msg = None
    try:
        # if controller_name in self.controllers:
        # controller_class = self.controllers[controller_name]
        if action_name in get_actions(controller_class):
            helper = ApplicationHelper#self.helpers.get(controller_name, ApplicationHelper)
            kwargs_all = kwargs.copy()
            if hasattr(controller_class, 'consume_urlconf_keyword_arguments'):
                if type(controller_class.consume_urlconf_keyword_arguments) not in (list, tuple):
                    controller_class.consume_urlconf_keyword_arguments = []
                for kwarg in controller_class.consume_urlconf_keyword_arguments:
                    if kwarg in kwargs:
                        del(kwargs[kwarg])
            return controller_class(site, request, helper, url_params=kwargs_all)._call_action(action_name, *args, **kwargs)
        else:
            raise InvalidActionError(action_name)
        # else:
            # raise InvalidControllerError()
    # except InvalidControllerError, e:
        # error_msg = _("No such controller: %(controller_name)s") % {'controller_name' : controller_name}
    except InvalidActionError as e:
        error_msg = _("Action '%(action_name)s' not found in controller '%(controller_name)s'") % {'action_name' : e.message, 'controller_name' : controller_name}

    raise Http404(error_msg)


def _get_arg_name_and_default(action_func):
    arg_spec = inspect.getargspec(action_func)
    arguments = arg_spec.args
    has_default = True<commit_msg>fixed bug with decorated functions, closes #11 - some decorated functions would not be properly autodiscovered<commit_after>import inspect
from functools import wraps
from django.http import *
import re
import sys

import warnings
from .helper import ApplicationHelper
from django.utils.translation import ugettext as _
from django.conf.urls import url, include
from django import VERSION
if VERSION[:2]<(1,9):
    from django.conf.urls import patterns

from .exceptions import InvalidActionError
from .exceptions import InvalidControllerError

def get_controller_name(controller_class, with_prefix = True):
    controller_name = getattr(controller_class, 'controller_name', None)
    if controller_name is None:
        name_ = [controller_class.__name__[0]]
        prev = ''
        for l in re.sub(r"Controller$",'',controller_class.__name__[1:]):
            if l.isupper() and prev.islower():
                name_.append('_'+l)
            else:
                name_.append(l)
            prev = l
        controller_name = ''.join(name_).lower()

    controller_prefix = getattr(controller_class, 'controller_prefix', None)
    if with_prefix and controller_prefix not in (None, ''):
        controller_name = controller_class.controller_prefix + controller_name
    return controller_name

def autoview_function(site, request, controller_name, controller_class, action_name = 'index', *args, **kwargs):
    error_msg = None
    try:
        # if controller_name in self.controllers:
        # controller_class = self.controllers[controller_name]
        if action_name in get_actions(controller_class):
            helper = ApplicationHelper#self.helpers.get(controller_name, ApplicationHelper)
            kwargs_all = kwargs.copy()
            if hasattr(controller_class, 'consume_urlconf_keyword_arguments'):
                if type(controller_class.consume_urlconf_keyword_arguments) not in (list, tuple):
                    controller_class.consume_urlconf_keyword_arguments = []
                for kwarg in controller_class.consume_urlconf_keyword_arguments:
                    if kwarg in kwargs:
                        del(kwargs[kwarg])
            return controller_class(site, request, helper, url_params=kwargs_all)._call_action(action_name, *args, **kwargs)
        else:
            raise InvalidActionError(action_name)
        # else:
            # raise InvalidControllerError()
    # except InvalidControllerError, e:
        # error_msg = _("No such controller: %(controller_name)s") % {'controller_name' : controller_name}
    except InvalidActionError as e:
        error_msg = _("Action '%(action_name)s' not found in controller '%(controller_name)s'") % {'action_name' : e.message, 'controller_name' : controller_name}

    raise Http404(error_msg)


def _get_arg_name_and_default(action_func):
    """
    This extracts the 3rd argument of the provided function and checks if it has a default value.
    `def action(self, request, returns_this_name=?):`

    :param action_func: the function to extract from
    :return: tuple with the argument name and a boolean of whether it has a default value or not
    """

    # if the passed function was wrapped with a decorator, let's make sure to get the actual function
    while hasattr(action_func,"__wrapped__"):
        action_func = action_func.__wrapped__

    arg_spec = inspect.getfullargspec(action_func)
    arguments = arg_spec.args
    has_default = True
{'fraction_non_alphanumeric': 0.08367801463569838, 'fraction_numerical': 0.0030225898822780783, 'mean_word_length': 3.381184668989547, 'pattern_counts': {'":': 0, '<': 5, '<?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': '800699', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1704, 'n_words': 456}