Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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::
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
@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)