當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。