當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。