当前位置: 首页>>代码示例>>Python>>正文


Python ipaddress.NetmaskValueError方法代码示例

本文整理汇总了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 
开发者ID:foremast,项目名称:foremast,代码行数:20,代码来源:create_securitygroup.py

示例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 
开发者ID:nmstate,项目名称:nmstate,代码行数:9,代码来源:iplib.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_ipaddress.py

示例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 
开发者ID:johnnoone,项目名称:json-spec,代码行数:13,代码来源:util.py

示例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 
开发者ID:johnnoone,项目名称:json-spec,代码行数:13,代码来源:util.py

示例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)) 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:56,代码来源:validators.py


注:本文中的ipaddress.NetmaskValueError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。