def validate_iban(iban): # check if country code is valid, # then check if iban length is correct for that country country_code = iban[:2].upper() length_for_country = bban_format.get(country_code, {}).get("length", 0) if not length_for_country or len(iban) != length_for_country: return False return _to_base_10_Str(iban) % 97 == 1
def _generate_bban(data): country = data.get("country_code") bban = bban_format.get(country, {}).get("composition").format(**data) return bban
def extract_account_number(iban): if validate_iban(iban): country_code = iban[:2] snippet = bban_format.get(country_code).get("account_number") return int(iban[snippet[0]:snippet[1]])
def extract_bank_code(iban): if validate_iban(iban): country_code = iban[:2] snippet = bban_format.get(country_code).get("bank_code") return int(iban[snippet[0]:snippet[1]])