当前位置: 首页>>代码示例>>Python>>正文


Python URN.validate方法代码示例

本文整理汇总了Python中temba.contacts.models.URN.validate方法的典型用法代码示例。如果您正苦于以下问题:Python URN.validate方法的具体用法?Python URN.validate怎么用?Python URN.validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在temba.contacts.models.URN的用法示例。


在下文中一共展示了URN.validate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: validate_urn

# 需要导入模块: from temba.contacts.models import URN [as 别名]
# 或者: from temba.contacts.models.URN import validate [as 别名]
def validate_urn(value, strict=True):
    try:
        normalized = URN.normalize(value)

        if strict and not URN.validate(normalized):
            raise ValueError()
    except ValueError:
        raise serializers.ValidationError("Invalid URN: %s. Ensure phone numbers contain country codes." % value)
    return normalized
开发者ID:Ilhasoft,项目名称:rapidpro,代码行数:11,代码来源:fields.py

示例2: to_internal_value

# 需要导入模块: from temba.contacts.models import URN [as 别名]
# 或者: from temba.contacts.models.URN import validate [as 别名]
    def to_internal_value(self, data):
        try:
            normalized = URN.normalize(data)
            if not URN.validate(normalized):
                raise ValueError()
        except ValueError:
            raise serializers.ValidationError("Invalid URN: %s. Ensure phone numbers contain country codes." % data)

        return normalized
开发者ID:eHealthAfrica,项目名称:rapidpro,代码行数:11,代码来源:fields.py

示例3: validate_urns

# 需要导入模块: from temba.contacts.models import URN [as 别名]
# 或者: from temba.contacts.models.URN import validate [as 别名]
    def validate_urns(self, value):
        if value is not None:
            self.parsed_urns = []
            for urn in value:
                try:
                    normalized = URN.normalize(urn)
                    scheme, path, query, display = URN.to_parts(normalized)
                    # for backwards compatibility we don't validate phone numbers here
                    if scheme != TEL_SCHEME and not URN.validate(normalized):  # pragma: needs cover
                        raise ValueError()
                except ValueError:
                    raise serializers.ValidationError("Invalid URN: '%s'" % urn)

                self.parsed_urns.append(normalized)

        return value
开发者ID:teehamaral,项目名称:rapidpro,代码行数:18,代码来源:serializers.py

示例4: validate_urn

# 需要导入模块: from temba.contacts.models import URN [as 别名]
# 或者: from temba.contacts.models.URN import validate [as 别名]
    def validate_urn(self, value):
        urns = []
        if value:
            # if we have tel URNs, we may need a country to normalize by
            country = self.org.get_country_code()

            for urn in value:
                try:
                    normalized = URN.normalize(urn, country)
                except ValueError as e:  # pragma: needs cover
                    raise serializers.ValidationError(str(e))

                if not URN.validate(normalized, country):  # pragma: needs cover
                    raise serializers.ValidationError("Invalid URN: '%s'" % urn)
                urns.append(normalized)

        return urns
开发者ID:teehamaral,项目名称:rapidpro,代码行数:19,代码来源:serializers.py

示例5: to_internal_value

# 需要导入模块: from temba.contacts.models import URN [as 别名]
# 或者: from temba.contacts.models.URN import validate [as 别名]
    def to_internal_value(self, data):
        if not URN.validate(data):
            raise ValidationError("Invalid URN: %s" % data)

        return URN.normalize(data)
开发者ID:ewheeler,项目名称:rapidpro,代码行数:7,代码来源:serializers.py


注:本文中的temba.contacts.models.URN.validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。