Python ipaddress.NetmaskValueError() Examples
The following are 9
code examples of ipaddress.NetmaskValueError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ipaddress
, or try the search function
.
Example #1
Source File: create_securitygroup.py From foremast with Apache License 2.0 | 6 votes |
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
Example #2
Source File: iplib.py From nmstate with GNU Lesser General Public License v2.1 | 5 votes |
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
Example #3
Source File: test_ipaddress.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def assertNetmaskError(self, details, *args): """Ensure a clean NetmaskValueError""" return self.assertCleanError(ipaddress.NetmaskValueError, details, *args)
Example #4
Source File: test_ipaddress.py From ironpython3 with Apache License 2.0 | 5 votes |
def assertNetmaskError(self, details, *args): """Ensure a clean NetmaskValueError""" return self.assertCleanError(ipaddress.NetmaskValueError, details, *args)
Example #5
Source File: test_ipaddress.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def assertNetmaskError(self, details, *args): """Ensure a clean NetmaskValueError""" return self.assertCleanError(ipaddress.NetmaskValueError, details, *args)
Example #6
Source File: util.py From json-spec with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #7
Source File: util.py From json-spec with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #8
Source File: test_ipaddress.py From android_universal with MIT License | 5 votes |
def assertNetmaskError(self, details, *args): """Ensure a clean NetmaskValueError""" return self.assertCleanError(ipaddress.NetmaskValueError, details, *args)
Example #9
Source File: validators.py From termite-visualizations with BSD 3-Clause "New" or "Revised" License | 4 votes |
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))