def ip_address_get(value):
'''
Get an IP address from a string. Raises a GetError if the string
is not a valid IP address. Supports both IPv4 and IPv6.
'''
if isinstance(value, (ipaddress.IPv4Network, ipaddress.IPv6Network)):
raise GetError(
"%s not allowed to be converted to IP address, use class attributes" %
type(value).__name__,
)
try:
return ipaddress.ip_address(value)
except ValueError:
raise GetError("value '%s' is not a valid IPv4/IPv6 address" % value)
评论列表
文章目录