def _parse_and_verify(self, candidate, offset): """Parses a phone number from the candidate using phonenumberutil.parse and verifies it matches the requested leniency. If parsing and verification succeed, a corresponding PhoneNumberMatch is returned, otherwise this method returns None. Arguments: candidate -- The candidate match. offset -- The offset of candidate within self.text. Returns the parsed and validated phone number match, or None. """ try: numobj = phonenumberutil.parse(candidate, self.preferred_region) if _verify(self.leniency, numobj): return PhoneNumberMatch(offset, candidate, numobj) except phonenumberutil.NumberParseException: # ignore and continue pass return None
def _parse_and_verify(self, candidate, offset): """Parses a phone number from the candidate using phonenumberutil.parse and verifies it matches the requested leniency. If parsing and verification succeed, a corresponding PhoneNumberMatch is returned, otherwise this method returns None. Arguments: candidate -- The candidate match. offset -- The offset of candidate within self.text. Returns the parsed and validated phone number match, or None. """ try: # Check the candidate doesn't contain any formatting which would # indicate that it really isn't a phone number. if not fullmatch(_MATCHING_BRACKETS, candidate): return None numobj = phonenumberutil.parse(candidate, self.preferred_region) if _verify(self.leniency, numobj): return PhoneNumberMatch(offset, candidate, numobj) except phonenumberutil.NumberParseException: # ignore and continue pass return None