<commit_before>import importlib
from django.conf import settings
from django.http import HttpResponse
from django.db.models.loading import get_model
from django.shortcuts import render
from buysafe.models import PaymentMethod
from buysafe.forms import BuySafeReceiveForm, WebATMReceiveForm


PAYMENT_RECEIVE_FORMS = {
    PaymentMethod.TYPE_BUYSAFE: BuySafeReceiveForm,
    PaymentMethod.TYPE_WEBATM: WebATMReceiveForm
}


def default_order_info_handler(request, context, **kwargs):
    order_id = kwargs['order_id']
    Order = get_model('shop', 'Order')
    order = Order.objects.get(id=int(order_id))
    return {
        'price': order.total,
        'order_info': unicode(order),
        'order_id': order.id,
        'name': order.billing_detail_first_name,
        'phone': order.billing_detail_phone,
        'email': order.billing_detail_email
    }


def make_response_handler(response_type, content=None):
    if content is not None:
        def f(**kwargs):
            return response_type(content)
    else:
        def f(**kwargs):
            return response_type()
    return f


def call_handler(name, default_handler, **kwargs):
    """
    Call the handler with `name` set in settings.py with provided keyword
    arguments, and fallback to `default_handler` if the name is not set. If
    `default_handler` is none and the name is not set, nothing happends and
    None will be returned.
    """
    try:
        handler_name = getattr(settings, name)
    except AttributeError:
        if default_handler is not None:
            result = default_handler(**kwargs)
        else:
            result = None
    else:
        components = handler_name.split('.')
        module_name, function_name = '.'.join(components[:-1]), components[-1]
        module = importlib.import_module(module_name)
        result = getattr(module, function_name)(**kwargs)
    return result


def call_handler_and_render(name, default_handler, **kwargs):
    result = call_handler(name, default_handler, **kwargs)
    if isinstance(result, HttpResponse):
        return result
    return render(kwargs['request'], kwargs['template'], kwargs['context'])


def get_payment_form(payment_type, querydict):
    methods = PaymentMethod.enabled.filter(payment_type=payment_type)
    form = None
    form_type = PAYMENT_RECEIVE_FORMS[payment_type]
    for method in methods:
        password = <PASSWORD>
        form = form_type(password, querydict)
        if form.is_valid():
            break
        else:
            form = None
    return form<commit_msg>Bug fix<commit_after>import importlib
from django.conf import settings
from django.http import HttpResponse
from django.db.models.loading import get_model
from django.shortcuts import render
from buysafe.models import PaymentMethod
from buysafe.forms import BuySafeReceiveForm, WebATMReceiveForm


PAYMENT_RECEIVE_FORMS = {
    PaymentMethod.TYPE_BUYSAFE: BuySafeReceiveForm,
    PaymentMethod.TYPE_WEBATM: WebATMReceiveForm
}


def default_order_info_handler(request, context, **kwargs):
    order_id = kwargs['order_id']
    Order = get_model('shop', 'Order')
    order = Order.objects.get(id=int(order_id))
    return {
        'price': order.total,
        'order_info': unicode(order),
        'order_id': order.id,
        'name': order.billing_detail_first_name,
        'phone': order.billing_detail_phone,
        'email': order.billing_detail_email
    }


def make_response_handler(response_type, content=None):
    if content is not None:
        def f(**kwargs):
            return response_type(content)
    else:
        def f(**kwargs):
            return response_type()
    f._is_response_handler = True
    return f


def call_handler(name, default_handler, **kwargs):
    """
    Call the handler with `name` set in settings.py with provided keyword
    arguments, and fallback to `default_handler` if the name is not set. If
    `default_handler` is none and the name is not set, nothing happends and
    None will be returned.
    """
    try:
        handler_name = getattr(settings, name)
    except AttributeError:
        if default_handler is not None:
            result = default_handler(**kwargs)
        else:
            result = None
    else:
        components = handler_name.split('.')
        module_name, function_name = '.'.join(components[:-1]), components[-1]
        module = importlib.import_module(module_name)
        result = getattr(module, function_name)(**kwargs)
    return result


def call_handler_and_render(name, default_handler, **kwargs):
    result = call_handler(name, default_handler, **kwargs)
    if result is None and default_handler._is_response_handler:
        return default_handler(**kwargs)
    if isinstance(result, HttpResponse):
        return result
    return render(kwargs['request'], kwargs['template'], kwargs['context'])


def get_payment_form(payment_type, querydict):
    methods = PaymentMethod.enabled.filter(payment_type=payment_type)
    form = None
    form_type = PAYMENT_RECEIVE_FORMS[payment_type]
    for method in methods:
        password = <PASSWORD>
        form = form_type(password, querydict)
        if form.is_valid():
            break
        else:
            form = None
    return form
{'fraction_non_alphanumeric': 0.09196718183552757, 'fraction_numerical': 0.0007632131272657889, 'mean_word_length': 3.2583265637692933, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3659973', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1492, 'n_words': 392}