def nationality(self) -> bool: """ Return True if nationality code is validated, False otherwise. """ import mrz.base.countries_ops as chk return self._report("valid nationality code", chk.is_code(self._nationality.replace("<", "")))
def identify_by_type_and_country_code(value: str, offset: int, types: List[str], max_attempts: int) -> Optional[str]: identified: bool = False for attempt in range(max_attempts): if identified: break index: int = offset - (max_attempts - attempt) if index < 0: index = offset - attempt if index < 0: break subset: str = value[index:] for i in range(len(subset)): if identified: break chars: str = replace_all(subset[i:], transliteration_substitutions) for _type in types: if identified: break if not chars.startswith(_type): continue type_length = len(_type) country_length = 3 country_code = chars[type_length:type_length + country_length] if is_code(country_code): identified = True offset = max(index + i, 0) return value[offset:] if identified else None
def country(self) -> bool: """Return True if the country code is validated, False otherwise.""" import mrz.base.countries_ops as chk return self.report.add("valid country code", chk.is_code(self._country.replace("<", "")))
from mrz.base.countries_ops import is_code from mrz.checker.td3 import TD3CodeChecker mrz_td3 = ("P<ASUMXHMWD<<EBDALRXHYM<<<<<<<<<<<<<<<<<<<<<\n" "A2222222<0ASU7108215F04120411000146819<<<<44") td3_check = TD3CodeChecker(mrz_td3, check_expiry=True) print(td3_check.mrz_code) if not td3_check: print("Falses:", td3_check.report_falses) print("Warnings:", td3_check.report_warnings) print("'%s' is code: %s" % (td3_check._country, str(is_code("ASU")))) def print_txt(title, value): print(title.ljust(20), value) fields = td3_check.fields() print_txt("Document Type:", fields.document_type) print_txt("Country:", fields.country) print_txt("Surname:", fields.surname) print_txt("Name:", fields.name) print_txt("Doc. Number", fields.document_number) print_txt("Doc. Number Hash:", fields.document_number_hash) print_txt("Nationality:", fields.nationality)