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

# Copyright(C) 2010-2012 <NAME>
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.


from datetime import datetime, date

from .base import CapBaseObject
from .collection import ICapCollection, CollectionNotFound


__all__ = ['Account', 'AccountNotFound', 'TransferError', 'ICapBank', 'Transaction']


class AccountNotFound(Exception):
    def __init__(self, msg=None):
        if msg is None:
            msg = 'Account not found'
        Exception.__init__(self, msg)

class TransferError(Exception):
    pass

class Recipient(CapBaseObject):
    def __init__(self):
        CapBaseObject.__init__(self, 0)
        self.add_field('label', basestring)

class Account(Recipient):
    def __init__(self):
        Recipient.__init__(self)
        self.add_field('balance', float)
        self.add_field('coming', float)
        self.link_id = None

    def __repr__(self):
        return u"<Account id=%r label=%r>" % (self.id, self.label)


class Transaction(CapBaseObject):
    TYPE_UNKNOWN      = 0
    TYPE_TRANSFER     = 1
    TYPE_ORDER        = 2
    TYPE_CHECK        = 3
    TYPE_DEPOSIT      = 4
    TYPE_PAYBACK      = 5
    TYPE_WITHDRAWAL   = 6
    TYPE_CARD         = 7
    TYPE_LOAN_PAYMENT = 8
    TYPE_BANK         = 9

    def __init__(self, id):
        CapBaseObject.__init__(self, id)
        self.add_field('date', (basestring, datetime, date))
        self.add_field('type', int, self.TYPE_UNKNOWN)
        self.add_field('raw', unicode)
        self.add_field('category', unicode)
        self.add_field('label', unicode)
        self.add_field('amount', float)

    def __repr__(self):
        return "<Transaction date='%s' label='%s' amount=%s>" % (self.date,
            self.label, self.amount)

class Transfer(CapBaseObject):
    def __init__(self, id):
        CapBaseObject.__init__(self, id)
        self.add_field('amount', float)
        self.add_field('date', (basestring, datetime, date))
        self.add_field('origin', (int, long, basestring))
        self.add_field('recipient', (int, long, basestring))

class ICapBank(ICapCollection):
    def iter_resources(self, objs, split_path):
        if Account in objs:
            if len(split_path) > 0:
                raise CollectionNotFound(split_path)

            return self.iter_accounts()

    def iter_accounts(self):
        raise NotImplementedError()

    def get_account(self, _id):
        raise NotImplementedError()

    def iter_history(self, account):
        """
        Iter history of transactions on a specific account.

        @param account [Account]
        @return [iter(Transaction)]
        """
        raise NotImplementedError()

    def iter_coming(self, account):
        """
        Iter coming transactions on a specific account.

        @param account [Account]
        @return [iter(Transaction)]
        """
        raise NotImplementedError()

    def iter_transfer_recipients(self, account):
        """
        Iter recipients availables for a transfer from a specific account.

        @param account [Account] account which initiate the transfer
        @return [iter(Recipient)]
        """
        raise NotImplementedError()

    def transfer(self, account, recipient, amount, reason=None):
        """
        Make a transfer from an account to a recipient.

        @param account [Account]  account to take money
        @param recipient [Recipient]  account to send money
        @param amount [float]  amount
        @param reason [str]  reason of transfer
        @return [Transfer]  a Transfer object
        """
        raise NotImplementedError()
<commit_msg>add field Account.type<commit_after># -*- coding: utf-8 -*-

# Copyright(C) 2010-2012 <NAME>
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.


from datetime import datetime, date

from .base import CapBaseObject
from .collection import ICapCollection, CollectionNotFound


__all__ = ['Account', 'AccountNotFound', 'TransferError', 'ICapBank', 'Transaction']


class AccountNotFound(Exception):
    def __init__(self, msg=None):
        if msg is None:
            msg = 'Account not found'
        Exception.__init__(self, msg)

class TransferError(Exception):
    pass

class Recipient(CapBaseObject):
    def __init__(self):
        CapBaseObject.__init__(self, 0)
        self.add_field('label', basestring)

class Account(Recipient):
    TYPE_UNKNOWN          = 0
    TYPE_CHECKING         = 1
    TYPE_LIABILITY        = 2
    TYPE_ASSET            = 3
    TYPE_INVESTMENT       = 4
    TYPE_LOAN             = 5
    TYPE_CASH             = 6
    TYPE_CREDIT_CARD      = 7
    TYPE_SAVINGS          = 8

    def __init__(self):
        Recipient.__init__(self)
        self.add_field('type', int, self.TYPE_UNKNOWN)
        self.add_field('balance', float)
        self.add_field('coming', float)

    def __repr__(self):
        return u"<Account id=%r label=%r>" % (self.id, self.label)


class Transaction(CapBaseObject):
    TYPE_UNKNOWN      = 0
    TYPE_TRANSFER     = 1
    TYPE_ORDER        = 2
    TYPE_CHECK        = 3
    TYPE_DEPOSIT      = 4
    TYPE_PAYBACK      = 5
    TYPE_WITHDRAWAL   = 6
    TYPE_CARD         = 7
    TYPE_LOAN_PAYMENT = 8
    TYPE_BANK         = 9

    def __init__(self, id):
        CapBaseObject.__init__(self, id)
        self.add_field('date', (basestring, datetime, date))
        self.add_field('type', int, self.TYPE_UNKNOWN)
        self.add_field('raw', unicode)
        self.add_field('category', unicode)
        self.add_field('label', unicode)
        self.add_field('amount', float)

    def __repr__(self):
        return "<Transaction date='%s' label='%s' amount=%s>" % (self.date,
            self.label, self.amount)

class Transfer(CapBaseObject):
    def __init__(self, id):
        CapBaseObject.__init__(self, id)
        self.add_field('amount', float)
        self.add_field('date', (basestring, datetime, date))
        self.add_field('origin', (int, long, basestring))
        self.add_field('recipient', (int, long, basestring))

class ICapBank(ICapCollection):
    def iter_resources(self, objs, split_path):
        if Account in objs:
            if len(split_path) > 0:
                raise CollectionNotFound(split_path)

            return self.iter_accounts()

    def iter_accounts(self):
        raise NotImplementedError()

    def get_account(self, _id):
        raise NotImplementedError()

    def iter_history(self, account):
        """
        Iter history of transactions on a specific account.

        @param account [Account]
        @return [iter(Transaction)]
        """
        raise NotImplementedError()

    def iter_coming(self, account):
        """
        Iter coming transactions on a specific account.

        @param account [Account]
        @return [iter(Transaction)]
        """
        raise NotImplementedError()

    def iter_transfer_recipients(self, account):
        """
        Iter recipients availables for a transfer from a specific account.

        @param account [Account] account which initiate the transfer
        @return [iter(Recipient)]
        """
        raise NotImplementedError()

    def transfer(self, account, recipient, amount, reason=None):
        """
        Make a transfer from an account to a recipient.

        @param account [Account]  account to take money
        @param recipient [Recipient]  account to send money
        @param amount [float]  amount
        @param reason [str]  reason of transfer
        @return [Transfer]  a Transfer object
        """
        raise NotImplementedError()

{'fraction_non_alphanumeric': 0.09518413597733712, 'fraction_numerical': 0.0060056657223796035, 'mean_word_length': 2.6380873866446826, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4411932', 'n_tokens_mistral': 2575, 'n_tokens_neox': 2467, 'n_words': 783}