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, "<"))