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

from __future__ import unicode_literals

import importlib
import logging

from django.conf import settings
from django.core.urlresolvers import reverse
import mercadopago
import pprint


logger = logging.getLogger(__name__)


class BackUrlsBuilder(object):
    """Generates the URLs for the 'back-urls'
    checkout preference
    """

    def __init__(self):
        self._success_url = None
        self._failure_url = None
        self._pending_url = None

    def build(self,
              request,
              success_url=None,
              failure_url=None,
              pending_url=None):
        """Generate default urls"""
        self._success_url = success_url or request.build_absolute_uri(
            reverse('djmercadopago:back-urls-success'))
        self._failure_url = failure_url or request.build_absolute_uri(
            reverse('djmercadopago:back-urls-failure'))
        self._pending_url = pending_url or request.build_absolute_uri(
            reverse('djmercadopago:back-urls-pending'))
        return self

    @property
    def success_url(self):
        return self._success_url

    @property
    def failure_url(self):
        return self._failure_url

    @property
    def pending_url(self):
        return self._pending_url


class CheckoutPreference(object):
    """Encapsulate the checkout preference (dict), plus
    utility methods.
    """
    def __init__(self, checkout_preferences):
        self._preferences = checkout_preferences

        # FIXME: generate custom exception with better messages
        # FIXME: add doc about requeriment of 'external_reference'
        assert self._preferences.get("items")
        for item in self._preferences["items"]:
            assert "external_reference" in item

    @property
    def preferences(self):
        return self._preferences

    def dump_as_string(self):
        return pprint.pformat(self._preferences)


class CheckoutPreferenceResult(object):
    """Encapsulate the RESULT of checkout (dict), plus
    utility methods
    """
    def __init__(self, result):
        self._result = result

    @property
    def url(self):
        assert "response" in self._result
        if settings.DJMERCADOPAGO_SANDBOX_MODE:
            url = self._result["response"]["sandbox_init_point"]
        else:
            url = self._result["response"]["init_point"]

        logger.debug("url: '%s' (sandbox mode: %s)", url,
                     settings.DJMERCADOPAGO_SANDBOX_MODE)
        return url

    def dump_as_string(self):<commit_msg>Returns copy of the dicts<commit_after># -*- coding: utf-8 -*-

from __future__ import unicode_literals

import importlib
import logging

from django.conf import settings
from django.core.urlresolvers import reverse
import mercadopago
import pprint
from copy import deepcopy


logger = logging.getLogger(__name__)


class BackUrlsBuilder(object):
    """Generates the URLs for the 'back-urls'
    checkout preference
    """

    def __init__(self):
        self._success_url = None
        self._failure_url = None
        self._pending_url = None

    def build(self,
              request,
              success_url=None,
              failure_url=None,
              pending_url=None):
        """Generate default urls"""
        self._success_url = success_url or request.build_absolute_uri(
            reverse('djmercadopago:back-urls-success'))
        self._failure_url = failure_url or request.build_absolute_uri(
            reverse('djmercadopago:back-urls-failure'))
        self._pending_url = pending_url or request.build_absolute_uri(
            reverse('djmercadopago:back-urls-pending'))
        return self

    @property
    def success_url(self):
        return self._success_url

    @property
    def failure_url(self):
        return self._failure_url

    @property
    def pending_url(self):
        return self._pending_url


class CheckoutPreference(object):
    """Encapsulate the checkout preference (dict), plus
    utility methods.
    """
    def __init__(self, checkout_preferences):
        self._preferences = checkout_preferences

        # FIXME: generate custom exception with better messages
        # FIXME: add doc about requeriment of 'external_reference'
        assert self._preferences.get("items")
        for item in self._preferences["items"]:
            assert "external_reference" in item

    @property
    def preferences(self):
        return deepcopy(self._preferences)

    def dump_as_string(self):
        return pprint.pformat(self._preferences)


class CheckoutPreferenceResult(object):
    """Encapsulate the RESULT of checkout (dict), plus
    utility methods
    """
    def __init__(self, result):
        self._result = result

    @property
    def result(self):
        return deepcopy(self._result)

    @property
    def url(self):
        assert "response" in self._result
        if settings.DJMERCADOPAGO_SANDBOX_MODE:
            url = self._result["response"]["sandbox_init_point"]
        else:
            url = self._result["response"]["init_point"]

        logger.debug("url: '%s' (sandbox mode: %s)", url,
                     settings.DJMERCADOPAGO_SANDBOX_MODE)
        return url

    def dump_as_string(self):
{'fraction_non_alphanumeric': 0.08714638314030758, 'fraction_numerical': 0.00037972280235428136, 'mean_word_length': 2.699438202247191, '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': '890547', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1462, 'n_words': 358}