def network(cls, value, raise_exception=False):
""" Network address validation """
if not isinstance(value, basestring):
if raise_exception:
raise TypeError('Invalid type \'{}\''.format(type(value)))
return False
terms = value.split()
if len(terms) is 2:
if cls.ip(terms[0]):
if cls.netmask(terms[1]):
terms[1] = NetTest.convert.netmask.prefix(terms[1])
elif cls.wildcard(terms[1]):
terms[1] = NetTest.convert.wildcard.prefix(terms[1])
terms[1] = unicode(terms[1])
value = u'/'.join(terms)
try:
value = unicode(value)
ipaddress.IPv4Interface(value)
except (ValueError, TypeError):
if raise_exception:
raise
return False
return True
评论列表
文章目录