<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.http import HttpResponse
from django.views.decorators.http import require_POST
from paypal.standard.ipn.forms import PayPalIPNForm
from paypal.standard.ipn.models import PayPalIPN

def handle_ipn_post(request, item_check_callable=None, from_view='notify'):
    """Naive wrapper for ipn view, so we can set the view whence the ipn came from
    """

    form = PayPalIPNForm(request.POST)
    if form.is_valid():
        try:
            ipn_obj = form.save(commit=False)
        except Exception, e:
            ipn_obj = PayPalIPN()
            ipn_obj.set_flag("Exception while processing. (%s)" % form.errors)
    else:
        ipn_obj.set_flag("Invalid form. (%s)" % form.errors)

    # notify/return/cancel
    ipn_obj.from_view = from_view

    ipn_obj.initialize(request)
    if not ipn_obj.flag:
        # Secrets should only be used over SSL.
        if request.is_secure() and 'secret' in request.GET:
            ipn_obj.verify_secret(form, request.GET['secret'])
        else:
            ipn_obj.verify(item_check_callable)

    return ipn_obj

@require_POST
def ipn(request, item_check_callable=None):
    """<commit_msg>Fix object referenced before assignment bug<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.http import HttpResponse
from django.views.decorators.http import require_POST
from paypal.standard.ipn.forms import PayPalIPNForm
from paypal.standard.ipn.models import PayPalIPN

def handle_ipn_post(request, item_check_callable=None, from_view='notify'):
    """Naive wrapper for ipn view, so we can set the view whence the ipn came from
    """

    form = PayPalIPNForm(request.POST)
    if form.is_valid():
        try:
            ipn_obj = form.save(commit=False)
        except Exception, e:
            ### FIXME: This needs to contain as much data as possible from the POST!
            ipn_obj = PayPalIPN()
            ipn_obj.set_flag("Exception while processing. (%s)" % form.errors)
    else:
        ### FIXME: This needs to contain as much data as possible from the POST!
        ipn_obj = PayPalIPN()
        ipn_obj.set_flag("Invalid form. (%s)" % form.errors)

    # notify/return/cancel
    ipn_obj.from_view = from_view

    ipn_obj.initialize(request)
    if not ipn_obj.flag:
        # Secrets should only be used over SSL.
        if request.is_secure() and 'secret' in request.GET:
            ipn_obj.verify_secret(form, request.GET['secret'])
        else:
            ipn_obj.verify(item_check_callable)

    return ipn_obj

@require_POST
def ipn(request, item_check_callable=None):
    """
{'fraction_non_alphanumeric': 0.10030280090840273, 'fraction_numerical': 0.000757002271006813, 'mean_word_length': 2.9744360902255638, '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': '2604037', 'n_tokens_mistral': 845, 'n_tokens_neox': 822, 'n_words': 217}