當前位置: 首頁>>代碼示例>>Python>>正文


Python phonenumberutil.NumberParseException方法代碼示例

本文整理匯總了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 
開發者ID:teamsempo,項目名稱:SempoBlockchain,代碼行數:20,代碼來源:user.py

示例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
        ) 
開發者ID:teamsempo,項目名稱:SempoBlockchain,代碼行數:20,代碼來源:kenya_ussd_state_machine.py

示例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 
開發者ID:linkedin,項目名稱:iris,代碼行數:20,代碼來源:sync_targets.py

示例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 
開發者ID:codeforamerica,項目名稱:intake,代碼行數:25,代碼來源:field_types.py

示例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 
開發者ID:linkedin,項目名稱:oncall,代碼行數:19,代碼來源:ldap_sync.py

示例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) 
開發者ID:TwilioDevEd,項目名稱:account-security-quickstart-django,代碼行數:17,代碼來源:forms.py

示例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 
開發者ID:teamsempo,項目名稱:SempoBlockchain,代碼行數:50,代碼來源:user.py


注:本文中的phonenumbers.phonenumberutil.NumberParseException方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。