本文整理汇总了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
示例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
示例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
示例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
示例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)