本文整理汇总了Python中django.utils.ipv6.clean_ipv6_address方法的典型用法代码示例。如果您正苦于以下问题:Python ipv6.clean_ipv6_address方法的具体用法?Python ipv6.clean_ipv6_address怎么用?Python ipv6.clean_ipv6_address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.ipv6
的用法示例。
在下文中一共展示了ipv6.clean_ipv6_address方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_python
# 需要导入模块: from django.utils import ipv6 [as 别名]
# 或者: from django.utils.ipv6 import clean_ipv6_address [as 别名]
def to_python(self, value):
if value in self.empty_values:
return ''
value = value.strip()
if value and ':' in value:
return clean_ipv6_address(value, self.unpack_ipv4)
return value
示例2: to_python
# 需要导入模块: from django.utils import ipv6 [as 别名]
# 或者: from django.utils.ipv6 import clean_ipv6_address [as 别名]
def to_python(self, value):
if value and ':' in value:
return clean_ipv6_address(value,
self.unpack_ipv4, self.error_messages['invalid'])
return value
示例3: get_prep_value
# 需要导入模块: from django.utils import ipv6 [as 别名]
# 或者: from django.utils.ipv6 import clean_ipv6_address [as 别名]
def get_prep_value(self, value):
value = super(GenericIPAddressField, self).get_prep_value(value)
if value is None:
return None
if value and ':' in value:
try:
return clean_ipv6_address(value, self.unpack_ipv4)
except exceptions.ValidationError:
pass
return six.text_type(value)
示例4: to_python
# 需要导入模块: from django.utils import ipv6 [as 别名]
# 或者: from django.utils.ipv6 import clean_ipv6_address [as 别名]
def to_python(self, value):
if value is None:
return None
if not isinstance(value, str):
value = str(value)
value = value.strip()
if ':' in value:
return clean_ipv6_address(value, self.unpack_ipv4, self.error_messages['invalid'])
return value
示例5: get_prep_value
# 需要导入模块: from django.utils import ipv6 [as 别名]
# 或者: from django.utils.ipv6 import clean_ipv6_address [as 别名]
def get_prep_value(self, value):
value = super().get_prep_value(value)
if value is None:
return None
if value and ':' in value:
try:
return clean_ipv6_address(value, self.unpack_ipv4)
except exceptions.ValidationError:
pass
return str(value)
示例6: to_python
# 需要导入模块: from django.utils import ipv6 [as 别名]
# 或者: from django.utils.ipv6 import clean_ipv6_address [as 别名]
def to_python(self, value):
if value is None:
return None
if not isinstance(value, six.string_types):
value = force_text(value)
value = value.strip()
if ':' in value:
return clean_ipv6_address(value, self.unpack_ipv4, self.error_messages['invalid'])
return value
示例7: to_python
# 需要导入模块: from django.utils import ipv6 [as 别名]
# 或者: from django.utils.ipv6 import clean_ipv6_address [as 别名]
def to_python(self, value):
if value in validators.EMPTY_VALUES:
return ''
if value and ':' in value:
return clean_ipv6_address(value,
self.unpack_ipv4, self.error_messages['invalid'])
return value
示例8: get_prep_value
# 需要导入模块: from django.utils import ipv6 [as 别名]
# 或者: from django.utils.ipv6 import clean_ipv6_address [as 别名]
def get_prep_value(self, value):
if value and ':' in value:
try:
return clean_ipv6_address(value, self.unpack_ipv4)
except exceptions.ValidationError:
pass
return value
示例9: to_python
# 需要导入模块: from django.utils import ipv6 [as 别名]
# 或者: from django.utils.ipv6 import clean_ipv6_address [as 别名]
def to_python(self, value):
if value is None:
return None
if not isinstance(value, six.string_types):
value = force_text(value)
value = value.strip()
if ':' in value:
return clean_ipv6_address(value,
self.unpack_ipv4, self.error_messages['invalid'])
return value
示例10: to_internal_value
# 需要导入模块: from django.utils import ipv6 [as 别名]
# 或者: from django.utils.ipv6 import clean_ipv6_address [as 别名]
def to_internal_value(self, data):
if not isinstance(data, six.string_types):
self.fail('invalid', value=data)
if ':' in data:
try:
if self.protocol in ('both', 'ipv6'):
return clean_ipv6_address(data, self.unpack_ipv4)
except DjangoValidationError:
self.fail('invalid', value=data)
return super(IPAddressField, self).to_internal_value(data)
# Number types...
示例11: test_cleans_plain_address
# 需要导入模块: from django.utils import ipv6 [as 别名]
# 或者: from django.utils.ipv6 import clean_ipv6_address [as 别名]
def test_cleans_plain_address(self):
self.assertEqual(clean_ipv6_address('DEAD::0:BEEF'), 'dead::beef')
self.assertEqual(clean_ipv6_address('2001:000:a:0000:0:fe:fe:beef'), '2001:0:a::fe:fe:beef')
self.assertEqual(clean_ipv6_address('2001::a:0000:0:fe:fe:beef'), '2001:0:a::fe:fe:beef')
示例12: test_cleans_with_v4_mapping
# 需要导入模块: from django.utils import ipv6 [as 别名]
# 或者: from django.utils.ipv6 import clean_ipv6_address [as 别名]
def test_cleans_with_v4_mapping(self):
self.assertEqual(clean_ipv6_address('::ffff:0a0a:0a0a'), '::ffff:10.10.10.10')
self.assertEqual(clean_ipv6_address('::ffff:1234:1234'), '::ffff:18.52.18.52')
self.assertEqual(clean_ipv6_address('::ffff:18.52.18.52'), '::ffff:18.52.18.52')
self.assertEqual(clean_ipv6_address('::ffff:0.52.18.52'), '::ffff:0.52.18.52')
self.assertEqual(clean_ipv6_address('::ffff:0.0.0.0'), '::ffff:0.0.0.0')
示例13: test_unpacks_ipv4
# 需要导入模块: from django.utils import ipv6 [as 别名]
# 或者: from django.utils.ipv6 import clean_ipv6_address [as 别名]
def test_unpacks_ipv4(self):
self.assertEqual(clean_ipv6_address('::ffff:0a0a:0a0a', unpack_ipv4=True), '10.10.10.10')
self.assertEqual(clean_ipv6_address('::ffff:1234:1234', unpack_ipv4=True), '18.52.18.52')
self.assertEqual(clean_ipv6_address('::ffff:18.52.18.52', unpack_ipv4=True), '18.52.18.52')