本文整理汇总了Python中ipaddress.NetmaskValueError方法的典型用法代码示例。如果您正苦于以下问题:Python ipaddress.NetmaskValueError方法的具体用法?Python ipaddress.NetmaskValueError怎么用?Python ipaddress.NetmaskValueError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipaddress
的用法示例。
在下文中一共展示了ipaddress.NetmaskValueError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _validate_cidr
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import NetmaskValueError [as 别名]
def _validate_cidr(self, rule):
"""Validate the cidr block in a rule.
Returns:
True: Upon successful completion.
Raises:
SpinnakerSecurityGroupCreationFailed: CIDR definition is invalid or
the network range is too wide.
"""
try:
network = ipaddress.IPv4Network(rule['app'])
except (ipaddress.NetmaskValueError, ValueError) as error:
raise SpinnakerSecurityGroupCreationFailed(error)
self.log.debug('Validating CIDR: %s', network.exploded)
return True
示例2: ip_address_full_to_tuple
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import NetmaskValueError [as 别名]
def ip_address_full_to_tuple(addr):
try:
net = ipaddress.ip_network(addr)
except (ipaddress.AddressValueError, ipaddress.NetmaskValueError) as err:
raise NmstateValueError(f"Invalid IP address, error: {err}")
return f"{net.network_address}", net.prefixlen
示例3: assertNetmaskError
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import NetmaskValueError [as 别名]
def assertNetmaskError(self, details, *args):
"""Ensure a clean NetmaskValueError"""
return self.assertCleanError(ipaddress.NetmaskValueError,
details, *args)
示例4: validate_ipv4
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import NetmaskValueError [as 别名]
def validate_ipv4(obj):
try:
import ipaddress
obj = text_type(obj)
ipaddress.IPv4Address(obj)
except ImportError:
raise ValidationError('IPv4 relies on ipaddress package', obj)
except (ipaddress.AddressValueError, ipaddress.NetmaskValueError):
raise ValidationError('{!r} does not appear to '
'be an IPv4 address'.format(obj))
return obj
示例5: validate_ipv6
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import NetmaskValueError [as 别名]
def validate_ipv6(obj):
try:
import ipaddress
obj = text_type(obj)
ipaddress.IPv6Address(obj)
except ImportError:
raise ValidationError('IPv6 relies on ipaddress package', obj)
except (ipaddress.AddressValueError, ipaddress.NetmaskValueError):
raise ValidationError('{!r} does not appear to '
'be an IPv6 address'.format(obj))
return obj
示例6: __call__
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import NetmaskValueError [as 别名]
def __call__(self, value):
try:
import ipaddress
except ImportError:
from gluon.contrib import ipaddr as ipaddress
try:
ip = ipaddress.IPv6Address(value)
ok = True
except ipaddress.AddressValueError:
return (value, translate(self.error_message))
if self.subnets:
# iterate through self.subnets to see if value is a member
ok = False
if isinstance(self.subnets, str):
self.subnets = [self.subnets]
for network in self.subnets:
try:
ipnet = ipaddress.IPv6Network(network)
except (ipaddress.NetmaskValueError, ipaddress.AddressValueError):
return (value, translate('invalid subnet provided'))
if ip in ipnet:
ok = True
if self.is_routeable:
self.is_private = False
self.is_link_local = False
self.is_reserved = False
self.is_multicast = False
if not (self.is_private is None or self.is_private ==
ip.is_private):
ok = False
if not (self.is_link_local is None or self.is_link_local ==
ip.is_link_local):
ok = False
if not (self.is_reserved is None or self.is_reserved ==
ip.is_reserved):
ok = False
if not (self.is_multicast is None or self.is_multicast ==
ip.is_multicast):
ok = False
if not (self.is_6to4 is None or self.is_6to4 ==
ip.is_6to4):
ok = False
if not (self.is_teredo is None or self.is_teredo ==
ip.is_teredo):
ok = False
if ok:
return (value, None)
return (value, translate(self.error_message))