<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function

import copy
import json
import logging
import random
import re
import string
import time

from . import signing
from . import compat

import warnings


_log = logging.getLogger(__name__)


class InvalidTokenException(Exception):
    pass


class InvalidItemDefinition(Exception):
    def __init__(self, message):
        self.message = message

    def __repr__(self):
        return self.message


class APIException(Exception):
    """
    Thrown when generating the url
    """


class ItemDefinition(object):

    def __init__(self, item_id, pricing, vat, url, title, purchasedatetime=None, cp=None, expires_at=None):

        for price in pricing.split(','):
            if not re.match('[A-Z]{3}\d+', price):
                raise InvalidItemDefinition('Pricing is not valid: %s' % pricing)

        for v in vat.split(','):

            if len(v) < 2:
                raise InvalidItemDefinition('Invalid length for vat: %s' % v)

            if not all((65 <= ord(c) <= 90) for c in v[:2]):
                raise InvalidItemDefinition('Invalid country for vat: %s' % vat)

            try:
                float(v[2:])
            except:
                raise InvalidItemDefinition('Invalid number part for vat: %s' % vat)

        if purchasedatetime is not None and not isinstance(purchasedatetime, int):
            raise InvalidItemDefinition("Invalid purchasedatetime %s. This should be a UTC-based epoch timestamp "
                                        "in seconds of type int")

        self.data = {
            'article_id': item_id,
            'purchasedatetime': int(time.time()) if purchasedatetime is None else purchasedatetime,
            'pricing': pricing,
            'vat': vat,
            'url': url,
            'title': title,
            'cp': cp,
            'expires': expires_at,
        }


class LaterPayClient(object):

    def __init__(self,
                 cp_key,
                 shared_secret,
                 api_root='https://api.laterpay.net',
                 web_root='https://web.laterpay.net',
                 lptoken=None):

        self.cp_key = cp_key
        self.api_root = api_root
        self.web_root = web_root
        self.shared_secret = shared_secret
        self.lptoken = lptoken

    def get_gettoken_redirect(self, return_to):
        url = self._gettoken_url
        data = {
            'redir': return_to,
            'cp': self.cp_key,
        }
        params = self._sign_and_encode(
            params=data,
            url=url,
            method="GET",
        )
        url = '%s?%s' % (url, params)<commit_msg>forgot to rename the key to expires_at<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function

import copy
import json
import logging
import random
import re
import string
import time

from . import signing
from . import compat

import warnings


_log = logging.getLogger(__name__)


class InvalidTokenException(Exception):
    pass


class InvalidItemDefinition(Exception):
    def __init__(self, message):
        self.message = message

    def __repr__(self):
        return self.message


class APIException(Exception):
    """
    Thrown when generating the url
    """


class ItemDefinition(object):

    def __init__(self, item_id, pricing, vat, url, title, purchasedatetime=None, cp=None, expires_at=None):

        for price in pricing.split(','):
            if not re.match('[A-Z]{3}\d+', price):
                raise InvalidItemDefinition('Pricing is not valid: %s' % pricing)

        for v in vat.split(','):

            if len(v) < 2:
                raise InvalidItemDefinition('Invalid length for vat: %s' % v)

            if not all((65 <= ord(c) <= 90) for c in v[:2]):
                raise InvalidItemDefinition('Invalid country for vat: %s' % vat)

            try:
                float(v[2:])
            except:
                raise InvalidItemDefinition('Invalid number part for vat: %s' % vat)

        if purchasedatetime is not None and not isinstance(purchasedatetime, int):
            raise InvalidItemDefinition("Invalid purchasedatetime %s. This should be a UTC-based epoch timestamp "
                                        "in seconds of type int")

        self.data = {
            'article_id': item_id,
            'purchasedatetime': int(time.time()) if purchasedatetime is None else purchasedatetime,
            'pricing': pricing,
            'vat': vat,
            'url': url,
            'title': title,
            'cp': cp,
            'expires_at': expires_at,
        }


class LaterPayClient(object):

    def __init__(self,
                 cp_key,
                 shared_secret,
                 api_root='https://api.laterpay.net',
                 web_root='https://web.laterpay.net',
                 lptoken=None):

        self.cp_key = cp_key
        self.api_root = api_root
        self.web_root = web_root
        self.shared_secret = shared_secret
        self.lptoken = lptoken

    def get_gettoken_redirect(self, return_to):
        url = self._gettoken_url
        data = {
            'redir': return_to,
            'cp': self.cp_key,
        }
        params = self._sign_and_encode(
            params=data,
            url=url,
            method="GET",
        )
        url = '%s?%s' % (url, params)
{'fraction_non_alphanumeric': 0.10231023102310231, 'fraction_numerical': 0.0033003300330033004, 'mean_word_length': 1.9598480737927293, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '617551', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1512, 'n_words': 421}