How to use the schwifty.common.Base function in schwifty

To help you get started, we’ve selected a few schwifty examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mdomke / schwifty / schwifty / bic.py View on Github external
import re
import warnings
from functools import partial

import iso3166
from pycountry import countries

from schwifty import registry
from schwifty.common import Base


_bic_re = re.compile(r"[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}(?:[A-Z0-9]{3})?")


class BIC(Base):
    """The BIC object.

    Examples:

        You can either create a new BIC object by providing a code as text::

            >>> bic = BIC('GENODEM1GLS')
            >>> bic.country_code
            'DE'
            >>> bic.location_code
            'M1'
            >>> bic.bank_code
            'GENO'

        or by using the :meth:`from_bank_code` classmethod::
github mdomke / schwifty / schwifty / iban.py View on Github external
bban = bank_code + account_code
    for i, char in enumerate(bban):
        if (i + 1) % 2 == 0:
            sum_ += _alphabet.index(char)
        else:
            sum_ += odds[_alphabet.index(char)]
    return _alphabet[sum_ % 26 + 10]


def calc_bban_checksum(country_code, bank_code, account_code):
    if country_code == "IT":
        return _calc_it_checksum(bank_code, account_code)
    return ""


class IBAN(Base):
    """The IBAN object.

    Examples:

        You create a new IBAN object by supplying an IBAN code in text form. The IBAN
        is validated behind the scenes and you can then access all relevant components
        as properties::

            >>> iban = IBAN('DE89 3704 0044 0532 0130 00')
            >>> iban.account_code
            '0532013000'
            >>> iban.bank_code
            '37040044'
            >>> iban.country_code
            'DE'
            >>> iban.checksum_digits
github mdomke / schwifty / schwifty / bic.py View on Github external
    @property
    def country(self):
        """Country: The country this BIC is registered in."""
        return countries.get(alpha_2=self.country_code)

    bank_code = property(
        partial(Base._get_component, start=0, end=4), doc="str: The bank-code part of the BIC."
    )
    country_code = property(
        partial(Base._get_component, start=4, end=6), doc="str: The ISO 3166 alpha2 country-code."
    )
    location_code = property(
        partial(Base._get_component, start=6, end=8), doc="str: The location code of the BIC."
    )
    branch_code = property(
        partial(Base._get_component, start=8, end=11),
        doc="str or None: The branch-code part of the BIC (if available)",
    )


registry.build_index("bank", "bic", key="bic", accumulate=True)
registry.build_index("bank", "bank_code", key=("country_code", "bank_code"), primary=True)