Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.valid = False
class EmailResult(Result):
category = ExtractedEntity.EMAIL
def __init__(self, ctx, label, start, end):
super(EmailResult, self).__init__(ctx, label, start, end)
self.key = self.label_key(self.label)
self.valid = self.key is not None
# TODO: do we want to do TLD -> country?
class PhoneResult(Result):
FORMAT = phonenumbers.PhoneNumberFormat.E164
category = ExtractedEntity.PHONE
def __init__(self, ctx, label, start, end):
super(PhoneResult, self).__init__(ctx, label, start, end)
number = self._parse(label)
for country in ctx.countries:
if number is None:
number = self._parse(label, country)
self.valid = number is not None
if number is not None:
self.countries = [geocoder.region_code_for_number(number)]
self.label = phonenumbers.format_number(number, self.FORMAT)
self.key = self.label
def _parse(self, number, region=None):
try:
num = phonenumbers.parse(number, region)