本文整理汇总了Python中phonenumbers.phonenumberutil.NumberParseException方法的典型用法代码示例。如果您正苦于以下问题:Python phonenumberutil.NumberParseException方法的具体用法?Python phonenumberutil.NumberParseException怎么用?Python phonenumberutil.NumberParseException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phonenumbers.phonenumberutil
的用法示例。
在下文中一共展示了phonenumberutil.NumberParseException方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_user_by_phone
# 需要导入模块: from phonenumbers import phonenumberutil [as 别名]
# 或者: from phonenumbers.phonenumberutil import NumberParseException [as 别名]
def get_user_by_phone(phone: str, region: str, should_raise=False) -> Optional[User]:
try:
user = User.query.execution_options(show_all=True).filter_by(
phone=proccess_phone_number(phone_number=phone, region=region)
).first()
except NumberParseException as e:
if should_raise:
raise e
else:
return None
if user is not None:
return user
else:
if should_raise:
raise Exception('User not found.')
else:
return None
示例2: upsell_unregistered_recipient
# 需要导入模块: from phonenumbers import phonenumberutil [as 别名]
# 或者: from phonenumbers.phonenumberutil import NumberParseException [as 别名]
def upsell_unregistered_recipient(self, user_input):
try:
recipient_phone = proccess_phone_number(user_input)
except NumberParseException:
return None
self.send_sms(
self.user.phone,
'upsell_message_sender',
recipient_phone=recipient_phone,
)
self.send_sms(
recipient_phone,
'upsell_message_recipient',
first_name=self.user.first_name,
last_name=self.user.last_name,
token_name=default_token(self.user).name
)
示例3: get_predefined_users
# 需要导入模块: from phonenumbers import phonenumberutil [as 别名]
# 或者: from phonenumbers.phonenumberutil import NumberParseException [as 别名]
def get_predefined_users(config):
users = {}
config_users = []
try:
config_users = config['sync_script']['preset_users']
except KeyError:
return {}
for user in config_users:
users[user['name']] = user
for key in ('sms', 'call'):
try:
users[user['name']][key] = normalize_phone_number(users[user['name']][key])
except (NumberParseException, KeyError, AttributeError):
users[user['name']][key] = None
return users
示例4: parse
# 需要导入模块: from phonenumbers import phonenumberutil [as 别名]
# 或者: from phonenumbers.phonenumberutil import NumberParseException [as 别名]
def parse(self, raw_value):
"""CharFields check that input values are string types before
stripping them of leading and trailing whitespace
"""
value = self.empty_value
if raw_value is not UNSET:
self.assert_parse_received_correct_type(raw_value, str)
raw_value = self.parse_as_text(raw_value)
if raw_value:
digits_only = extract_digit_chars(raw_value)
if not digits_only:
self.add_error(
self.parse_error_message.format(raw_value))
else:
try:
value = str(
self.parse_phone_number(digits_only).national_number)
except (NumberParseException,
exceptions.InvalidPhoneNumberException) as error:
if not self.skip_validation_parse_only:
self.add_error(
self.parse_error_message.format(raw_value))
return value
示例5: get_predefined_users
# 需要导入模块: from phonenumbers import phonenumberutil [as 别名]
# 或者: from phonenumbers.phonenumberutil import NumberParseException [as 别名]
def get_predefined_users(config):
users = {}
try:
config_users = config['sync_script']['preset_users']
except KeyError:
return {}
for user in config_users:
users[user['name']] = user
for key in ['sms', 'call']:
try:
users[user['name']][key] = normalize_phone_number(users[user['name']][key])
except (NumberParseException, KeyError, AttributeError):
users[user['name']][key] = None
return users
示例6: clean
# 需要导入模块: from phonenumbers import phonenumberutil [as 别名]
# 或者: from phonenumbers.phonenumberutil import NumberParseException [as 别名]
def clean(self):
data = self.cleaned_data
if data['password'] != data['confirm_password']:
self.add_error(
'password',
'Password and confirmation did not match'
)
phone_number = data['country_code'] + data['phone_number']
try:
phone_number = phonenumbers.parse(phone_number, None)
if not phonenumbers.is_valid_number(phone_number):
self.add_error('phone_number', 'Invalid phone number')
except NumberParseException as e:
self.add_error('phone_number', e)
示例7: find_user_from_public_identifier
# 需要导入模块: from phonenumbers import phonenumberutil [as 别名]
# 或者: from phonenumbers.phonenumberutil import NumberParseException [as 别名]
def find_user_from_public_identifier(*public_identifiers):
"""
:param public_identifiers: email, phone, public_serial_number, nfc_serial_number or address
:return: First user found
"""
user = None
for public_identifier in list(filter(lambda x: x is not None, public_identifiers)):
if public_identifier is None:
continue
user = User.query.execution_options(show_all=True).filter_by(
email=str(public_identifier).lower()).first()
if user:
break
try:
user = User.query.execution_options(show_all=True).filter_by(
phone=proccess_phone_number(public_identifier)).first()
if user:
break
except NumberParseException:
pass
user = User.query.execution_options(show_all=True).filter_by(
public_serial_number=str(public_identifier).lower()).first()
if user:
break
user = User.query.execution_options(show_all=True).filter_by(
nfc_serial_number=public_identifier.upper()).first()
if user:
break
try:
checksummed = to_checksum_address(public_identifier)
blockchain_address = BlockchainAddress.query.filter_by(
address=checksummed).first()
if blockchain_address and blockchain_address.transfer_account:
user = blockchain_address.transfer_account.primary_user
if user:
break
except Exception:
pass
return user