def identifier(self) -> bool: """Return True is the identifier is validated overcoming the checks, False otherwise.""" id_ = self._identifier if not check.is_printable(id_): return self._report("identifier", False) ok = True if check.is_empty(id_): return self._report("empty identifier", kind=2) if check.uses_nums(id_): self._report("identifier with numbers", kind=2) ok &= False id2iter = id_.split("<<") if len(id2iter) == 1: secondary = id2iter[0] primary = "" ok &= False if self._compute_warnings else ok # print("Only one identifier") self._report("only one identifier", kind=1) else: secondary = id2iter[1] primary = id2iter[0] # print("Debug. (name, surname):", (secondary, primary)) # secondary is not ok. secondary -= padding # secondary.replace(padding, "") padding = id_[id_.find(secondary) + len(secondary):] padding = padding if primary != secondary else padding.replace(secondary, "") # print("Debug. padding:", padding) if not len(padding) and id_[-1] in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": self._report("possible truncating", kind=1) ok &= False if self._compute_warnings else ok # TODO: compute as False? if not check.is_empty(padding): # print("Error, Padding is not empty") self._report("more than two identifiers", kind=2) ok &= False if check.begin_by(primary, "<") or check.begin_by(secondary, "<"): self._report("some identifier begin by '<'", kind=2) ok &= False for i in range(2): for itm in id2iter[i].split("<"): if not itm: pass else: for tit in titles: if tit == itm: if i == 1: self._report("Possible unauthorized prefix or suffix in identifier", kind=1) else: self._report("Possible not recommended prefix or suffix in identifier", kind=1) ok &= False if self._compute_warnings else ok return self._report("identifier", ok)
def document_number(self) -> bool: """Return True if the document number format is validated, False otherwise.""" s = self._document_number return self._report( "document number format", not check.is_empty(s) and check.is_printable(s) and not check.begin_by(s, "<"))
def optional_data_hash(self) -> bool: """Return True if hash of optional data is True, False otherwise.""" if check.is_empty( self._optional_data) and self._optional_data_hash == "<": ok = True else: ok = hash_is_ok(self._optional_data, self._optional_data_hash) return self._report("optional data hash", ok)
def identifier(self) -> bool: """Return True is the identifier is validated overcoming the checks, False otherwise.""" full_id = self._identifier.rstrip("<") padding = self._identifier[len(full_id):] id2iter = full_id.split("<<") id_len = len(id2iter) primary = secondary = None if not check.is_printable(self._identifier): ok = False elif check.is_empty(self._identifier): self._report("empty identifier", level=Kind.ERROR) ok = False else: if id_len == len([i for i in id2iter if i]): if id_len == 2: primary, secondary = id2iter ok = True elif id_len == 1: primary, secondary = id2iter[0], "" self._report("only one identifier", level=Kind.WARNING) ok = not self._compute_warnings else: self._report("more than two identifiers", level=Kind.ERROR) ok = False else: # too many '<' in id self._report("invalid identifier format", level=Kind.ERROR) ok = False # print("Debug. id2iter ............:", id2iter) # print("Debug. (secondary, primary):", (secondary, primary)) # print("Debug. padding ............:", padding) if ok: if check.uses_nums(full_id): self._report("identifier with numbers", level=Kind.ERROR) ok = False if primary.startswith( "<") or secondary and secondary.startswith("<"): self._report("some identifier begin by '<'", level=Kind.ERROR) ok = False if not padding: self._report("possible truncating", level=Kind.WARNING) ok = False if self._compute_warnings else ok for i in range(id_len): for itm in id2iter[i].split("<"): if itm: for tit in titles: if tit == itm: if i: # secondary id self._report( "Possible unauthorized prefix or suffix in identifier", level=Kind.WARNING) else: # primary id self._report( "Possible not recommended prefix or suffix in identifier", level=Kind.WARNING) ok = False if self._compute_warnings else ok self._id_secondary = str(secondary) self._id_primary = str(primary) return self._report("identifier", ok)
def optional_data_2(self) -> bool: """Return True if the format of the optional data field is validated, False otherwise.""" s = self._optional_data_2 return True if check.is_empty(s) else self._report("optional data 2 format", check.is_printable(s))
def identifier(self) -> bool: """Return True is the identifier is validated overcoming the checks, False otherwise.""" full_id = self._identifier.rstrip("<") padding = self._identifier[len(full_id):] id2iter = full_id.lstrip("<<").split( "<<") if full_id[2] in ascii_uppercase else full_id.split("<<") id_len = len(id2iter) primary = secondary = None if not check.is_printable(self._identifier): ok = False elif check.is_empty(self._identifier): self._report("empty identifier", kind=2) ok = False else: if id_len == len([i for i in id2iter if i]): if id_len == 2: primary, secondary = id2iter ok = True elif id_len == 1: primary, secondary = id2iter[0], "" self._report("only one identifier", kind=1) ok = not self._compute_warnings else: self._report("more than two identifiers", kind=2) ok = False else: # too many '<' in id self._report("invalid identifier format", kind=2) ok = False # print("Debug. id2iter ............:", id2iter) # print("Debug. (secondary, primary):", (secondary, primary)) # print("Debug. padding ............:", padding) if ok: if False and not full_id.startswith("<<"): self._report("identifier doesn't starts with '<<'", kind=2) ok = False # If you want to report as a warning instead of as an error uncomment lines below # self._report("identifier doesn't starts with '<<'", kind=1) # ok = False if self._compute_warnings else ok if check.uses_nums(full_id): self._report("identifier with numbers", kind=2) ok = False if primary.startswith( "<") or secondary and secondary.startswith("<"): self._report("some identifier begin by '<'", kind=2) ok = False if not padding: self._report("possible truncating", kind=1) ok = False if self._compute_warnings else ok for i in range(id_len): for itm in id2iter[i].split("<"): if itm: for tit in titles: if tit == itm: if i: # secondary id self._report( "Possible unauthorized prefix or suffix in identifier", kind=1) else: # primary id self._report( "Possible not recommended prefix or suffix in identifier", kind=1) ok = False if self._compute_warnings else ok return self._report("identifier", ok)
def optional_data(self) -> bool: """Return True if the format of the optional data field is validated, False otherwise.""" s = self._optional_data = self.mrz_code.splitlines()[1][28:36] return True if check.is_empty(s) else self.report.add( "optional data format", check.is_printable(s))
def optional_data(self) -> bool: """Return True if the format of the optional data field is validated, False otherwise.""" s = self._optional_data return True if check.is_empty(s) else self.report.add( "id number format", check.is_printable(s))