<commit_before># -*- coding: utf-8 -*-

from functools import wraps
from inspect import isfunction, getargspec

from flask import request

__all__ = (
    'request_args',
    'get',
    'post',
    'args',
    'files',
    'cookies',
    'session',
    'collection'
)


def _get_storage_dict_map(request):
    result = {
        '_post': request.form,
        '_get': request.args,
        '_args': request.values,
        '_files': request.files,
        '_cookies': request.cookies,
        '_request': request,
    }
    if hasattr(request, 'session'):
        result['_session'] = request.session
    return result


def _extract_method(kwargs):
    result = kwargs.pop('_method', 'args')
    if result not in ('post', 'get', 'args'):
        result = 'args'
    return result


def _extract_storage_type(kwargs):
    return kwargs.pop('_storage', dict)


def request_args(*args, **kwargs):
    method = _extract_method(kwargs)
    def decorator(func, spec=True):
        func_arg_names = getargspec(func)[0]
        if spec:
            kwargs.update(zip(func_arg_names, args))

        @wraps(func)
        def wrapper(**func_args):
            storage_dict_map = _get_storage_dict_map(request)
            storage_dict = storage_dict_map['_' + method]

            values = {}
            for arg_name in func_arg_names:
                if arg_name in func_args:
                    values[arg_name] = func_args[arg_name]
                elif arg_name in storage_dict_map:
                    values[arg_name] = storage_dict_map[arg_name]
                elif arg_name in kwargs:
                    values[arg_name] = kwargs[arg_name](request, arg_name)
                else:
                    values[arg_name] = storage_dict.get(arg_name)
            return func(**values)
        return wrapper

    if len(args) == 1 and len(kwargs) == 0 and isfunction(args[0]):
        return decorator(args[0], False)
    return decorator


def get(name=None, default=None, type=None):
    def getter(request, arg_name):
        return request.args.get(name or arg_name, default, type)
    return getter


def post(name=None, default=None, type=None):
    def getter(request, arg_name):
        return request.form.get(name or arg_name, default, type)
    return getter


def args(name=None, default=None, type=None):
    def getter(request, arg_name):
        return request.values.get(name or arg_name, default, type)
    return getter


def files(name=None):
    def getter(request, arg_name):
        return request.files.get(name or arg_name)
    return getter


def cookies(name=None, default=None, type=None):
    def getter(request, arg_name):
        return request.cookies.get(name or arg_name, default, type)
    return getter


def session(name=None, default=None, type=None, remove=False):
    def getter(request, arg_name):
        arg = name or arg_name
        result = default
        if arg in request.session:
            result = request.session[arg]
            if type:
                try:
                    result = type(result)
                except TypeError:
                    result = default
            if remove:
                del request.session[arg]
        return result
    return getter


def collection(*args, **kwargs):
    method = _extract_method(kwargs)
    storage_type = _extract_storage_type(kwargs)

    def getter(request, arg_name):
        storage_dict_map = _get_storage_dict_map(request)
        storage_dict = storage_dict_map['_' + method]

        values = {}
        for arg in args:
            values[arg] = storage_dict.get(arg)
        for arg, arg_getter in kwargs.items():
            values[arg] = arg_getter(request, arg)
        return storage_type(**values)
    return getter

<commit_msg>Remove session()<commit_after># -*- coding: utf-8 -*-

from functools import wraps
from inspect import isfunction, getargspec

from flask import request

__all__ = (
    'request_args',
    'get',
    'post',
    'args',
    'files',
    'cookies',
    'collection'
)


def _get_storage_dict_map(request):
    result = {
        '_post': request.form,
        '_get': request.args,
        '_args': request.values,
        '_files': request.files,
        '_cookies': request.cookies,
        '_request': request,
    }
    return result


def _extract_method(kwargs):
    result = kwargs.pop('_method', 'args')
    if result not in ('post', 'get', 'args'):
        result = 'args'
    return result


def _extract_storage_type(kwargs):
    return kwargs.pop('_storage', dict)


def request_args(*args, **kwargs):
    method = _extract_method(kwargs)
    def decorator(func, spec=True):
        func_arg_names = getargspec(func)[0]
        if spec:
            kwargs.update(zip(func_arg_names, args))

        @wraps(func)
        def wrapper(**func_args):
            storage_dict_map = _get_storage_dict_map(request)
            storage_dict = storage_dict_map['_' + method]

            values = {}
            for arg_name in func_arg_names:
                if arg_name in func_args:
                    values[arg_name] = func_args[arg_name]
                elif arg_name in storage_dict_map:
                    values[arg_name] = storage_dict_map[arg_name]
                elif arg_name in kwargs:
                    values[arg_name] = kwargs[arg_name](request, arg_name)
                else:
                    values[arg_name] = storage_dict.get(arg_name)
            return func(**values)
        return wrapper

    if len(args) == 1 and len(kwargs) == 0 and isfunction(args[0]):
        return decorator(args[0], False)
    return decorator


def get(name=None, default=None, type=None):
    def getter(request, arg_name):
        return request.args.get(name or arg_name, default, type)
    return getter


def post(name=None, default=None, type=None):
    def getter(request, arg_name):
        return request.form.get(name or arg_name, default, type)
    return getter


def args(name=None, default=None, type=None):
    def getter(request, arg_name):
        return request.values.get(name or arg_name, default, type)
    return getter


def files(name=None):
    def getter(request, arg_name):
        return request.files.get(name or arg_name)
    return getter


def cookies(name=None, default=None, type=None):
    def getter(request, arg_name):
        return request.cookies.get(name or arg_name, default, type)
    return getter


def collection(*args, **kwargs):
    method = _extract_method(kwargs)
    storage_type = _extract_storage_type(kwargs)

    def getter(request, arg_name):
        storage_dict_map = _get_storage_dict_map(request)
        storage_dict = storage_dict_map['_' + method]

        values = {}
        for arg in args:
            values[arg] = storage_dict.get(arg)
        for arg, arg_getter in kwargs.items():
            values[arg] = arg_getter(request, arg)
        return storage_type(**values)
    return getter


{'fraction_non_alphanumeric': 0.10500504831963076, 'fraction_numerical': 0.0017308524448290783, 'mean_word_length': 2.472208312468703, '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': '6567818', 'n_tokens_mistral': 2135, 'n_tokens_neox': 2077, 'n_words': 510}