Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def email_to_phone(from_email):
'''Converts an email address like 14155551212@sms.example.com
into a phone number like +14155551212'''
(username, domain) = from_email.split('@')
potential_number = '+' + username
try:
ph_num = ph.parse(potential_number, 'US')
return ph.format_number(ph_num, ph.PhoneNumberFormat.E164)
except:
raise InvalidPhoneNumberInEmail(from_email)
test("Running local scan...")
FormattedPhoneNumber = "+" + formatNumber(InputNumber)
try:
PhoneNumberObject = phonenumbers.parse(FormattedPhoneNumber, None)
except Exception as e:
throw(e)
else:
if not phonenumbers.is_valid_number(PhoneNumberObject):
return False
number = phonenumbers.format_number(
PhoneNumberObject, phonenumbers.PhoneNumberFormat.E164
).replace("+", "")
numberCountryCode = phonenumbers.format_number(
PhoneNumberObject, phonenumbers.PhoneNumberFormat.INTERNATIONAL
).split(" ")[0]
numberCountry = phonenumbers.region_code_for_country_code(
int(numberCountryCode)
)
localNumber = phonenumbers.format_number(
PhoneNumberObject, phonenumbers.PhoneNumberFormat.E164
).replace(numberCountryCode, "")
internationalNumber = phonenumbers.format_number(
PhoneNumberObject, phonenumbers.PhoneNumberFormat.INTERNATIONAL
)
country = geocoder.country_name_for_number(PhoneNumberObject, "en")
location = geocoder.description_for_number(PhoneNumberObject, "en")
carrierName = carrier.name_for_number(PhoneNumberObject, "en")
def e164(self):
"""
Ritorna il numero formattato come numero internazionale E.164.
:return: Stringa che rappresenta il numero in formato internazionale E.164.
"""
return phonenumbers.format_number(self._phonenumber(), phonenumbers.PhoneNumberFormat.E164)
def parse_numero(numero, paese="IT"):
try:
n = phonenumbers.parse(numero, paese)
except phonenumbers.phonenumberutil.NumberParseException:
return numero
f = phonenumbers.format_number(n, phonenumbers.PhoneNumberFormat.E164)
return f
def phone_number_in_e164(number, country=None):
"""Given a phone number and a country code, returns the number in
E.164 format. Returns None if the number could not be so formatted."""
if country is None:
country = get_country()
try:
pn = phonenumbers.parse(number, country)
output = phonenumbers.format_number(pn, phonenumbers.PhoneNumberFormat.E164)
except:
return None
return output
"""
if not value:
return None
if value[0] == '+':
# Phone number may already be in E.164 format.
parse_type = None
else:
# Assume US format otherwise
parse_type = 'US'
try:
phone_representation = phonenumbers.parse(value, parse_type)
except phonenumbers.NumberParseException:
return None
else:
return phonenumbers.format_number(
phone_representation, phonenumbers.PhoneNumberFormat.E164)
def validar_telefono(valor):
valor = valor.strip()
if valor.startswith(('15', '4')):
valor = f'{CARACTERISTICA_DEFAULT} {valor}'
elif valor.startswith('11') and 9 <= len(valor) <= 11:
valor = f'9 {valor}'
valor = phonenumbers.parse(valor, 'AR')
formato = phonenumbers.PhoneNumberFormat.INTERNATIONAL
valor = phonenumbers.format_number(valor, formato)
return valor