summaryrefslogtreecommitdiff
path: root/netaddr/ip
diff options
context:
space:
mode:
Diffstat (limited to 'netaddr/ip')
-rw-r--r--netaddr/ip/__init__.py16
-rw-r--r--netaddr/ip/glob.py6
-rwxr-xr-xnetaddr/ip/iana.py17
-rw-r--r--netaddr/ip/nmap.py10
-rw-r--r--netaddr/ip/rfc1924.py2
5 files changed, 25 insertions, 26 deletions
diff --git a/netaddr/ip/__init__.py b/netaddr/ip/__init__.py
index ecf72d0..cb43012 100644
--- a/netaddr/ip/__init__.py
+++ b/netaddr/ip/__init__.py
@@ -316,7 +316,7 @@ class IPAddress(BaseIP):
if 0 <= int(addr) <= self._module.max_int:
self._value = int(addr)
else:
- raise AddrFormatError('bad address format: %r' % addr)
+ raise AddrFormatError('bad address format: %r' % (addr,))
def __getstate__(self):
""":returns: Pickled state of an `IPAddress` object."""
@@ -935,7 +935,7 @@ class IPNetwork(BaseIP, IPListMixin):
pass
if value is None:
- raise AddrFormatError('invalid IPNetwork %s' % addr)
+ raise AddrFormatError('invalid IPNetwork %s' % (addr,))
self._value = value
self._prefixlen = prefixlen
@@ -960,13 +960,13 @@ class IPNetwork(BaseIP, IPListMixin):
self._module = _ipv6
else:
raise ValueError('unpickling failed for object state %s' \
- % str(state))
+ % (state,))
if 0 <= prefixlen <= self._module.width:
self._prefixlen = prefixlen
else:
raise ValueError('unpickling failed for object state %s' \
- % str(state))
+ % (state,))
def _set_prefixlen(self, value):
if not isinstance(value, _int_type):
@@ -1505,7 +1505,7 @@ def cidr_abbrev_to_verbose(abbrev_cidr):
try:
if not 0 <= int(prefix) <= 32:
raise ValueError('prefixlen in address %r out of range' \
- ' for IPv4!' % abbrev_cidr)
+ ' for IPv4!' % (abbrev_cidr,))
except ValueError:
return abbrev_cidr
else:
@@ -1783,7 +1783,7 @@ def smallest_matching_cidr(ip, cidrs):
if not hasattr(cidrs, '__iter__'):
raise TypeError('IP address/subnet sequence expected, not %r!'
- % cidrs)
+ % (cidrs,))
ip = IPAddress(ip)
for cidr in sorted([IPNetwork(cidr) for cidr in cidrs]):
@@ -1812,7 +1812,7 @@ def largest_matching_cidr(ip, cidrs):
if not hasattr(cidrs, '__iter__'):
raise TypeError('IP address/subnet sequence expected, not %r!'
- % cidrs)
+ % (cidrs,))
ip = IPAddress(ip)
for cidr in sorted([IPNetwork(cidr) for cidr in cidrs]):
@@ -1839,7 +1839,7 @@ def all_matching_cidrs(ip, cidrs):
if not hasattr(cidrs, '__iter__'):
raise TypeError('IP address/subnet sequence expected, not %r!'
- % cidrs)
+ % (cidrs,))
ip = IPAddress(ip)
for cidr in sorted([IPNetwork(cidr) for cidr in cidrs]):
diff --git a/netaddr/ip/glob.py b/netaddr/ip/glob.py
index e94fcbc..ed43b1b 100644
--- a/netaddr/ip/glob.py
+++ b/netaddr/ip/glob.py
@@ -77,7 +77,7 @@ def glob_to_iptuple(ipglob):
:return: a tuple contain lower and upper bound IP objects.
"""
if not valid_glob(ipglob):
- raise AddrFormatError('not a recognised IP glob range: %r!' % ipglob)
+ raise AddrFormatError('not a recognised IP glob range: %r!' % (ipglob,))
start_tokens = []
end_tokens = []
@@ -107,7 +107,7 @@ def glob_to_iprange(ipglob):
:return: an IPRange object.
"""
if not valid_glob(ipglob):
- raise AddrFormatError('not a recognised IP glob range: %r!' % ipglob)
+ raise AddrFormatError('not a recognised IP glob range: %r!' % (ipglob,))
start_tokens = []
end_tokens = []
@@ -242,7 +242,7 @@ class IPGlob(IPRange):
A few basic rules also apply :
- 1. ``x`` must always be greater than ``y``, therefore :
+ 1. ``x`` must always be less than ``y``, therefore :
- ``x`` can only be ``0`` through ``254``
- ``y`` can only be ``1`` through ``255``
diff --git a/netaddr/ip/iana.py b/netaddr/ip/iana.py
index f8945e6..116c8ff 100755
--- a/netaddr/ip/iana.py
+++ b/netaddr/ip/iana.py
@@ -29,13 +29,12 @@ More details can be found at the following URLs :-
- IEEE Protocols Information Home Page - http://www.iana.org/protocols/
"""
-import os.path as _path
import sys as _sys
from xml.sax import make_parser, handler
from netaddr.core import Publisher, Subscriber
from netaddr.ip import IPAddress, IPNetwork, IPRange, cidr_abbrev_to_verbose
-from netaddr.compat import _dict_items, _callable
+from netaddr.compat import _dict_items, _callable, _importlib_resources
@@ -362,21 +361,21 @@ def load_info():
Parse and load internal IANA data lookups with the latest information from
data files.
"""
- PATH = _path.dirname(__file__)
-
- ipv4 = IPv4Parser(open(_path.join(PATH, 'ipv4-address-space.xml')))
+ ipv4 = IPv4Parser(_importlib_resources.open_binary(__package__, 'ipv4-address-space.xml'))
ipv4.attach(DictUpdater(IANA_INFO['IPv4'], 'IPv4', 'prefix'))
ipv4.parse()
- ipv6 = IPv6Parser(open(_path.join(PATH, 'ipv6-address-space.xml')))
+ ipv6 = IPv6Parser(_importlib_resources.open_binary(__package__, 'ipv6-address-space.xml'))
ipv6.attach(DictUpdater(IANA_INFO['IPv6'], 'IPv6', 'prefix'))
ipv6.parse()
- ipv6ua = IPv6UnicastParser(open(_path.join(PATH, 'ipv6-unicast-address-assignments.xml')))
+ ipv6ua = IPv6UnicastParser(
+ _importlib_resources.open_binary(__package__, 'ipv6-unicast-address-assignments.xml'),
+ )
ipv6ua.attach(DictUpdater(IANA_INFO['IPv6_unicast'], 'IPv6_unicast', 'prefix'))
ipv6ua.parse()
- mcast = MulticastParser(open(_path.join(PATH, 'multicast-addresses.xml')))
+ mcast = MulticastParser(_importlib_resources.open_binary(__package__, 'multicast-addresses.xml'))
mcast.attach(DictUpdater(IANA_INFO['multicast'], 'multicast', 'address'))
mcast.parse()
@@ -407,7 +406,7 @@ def _within_bounds(ip, ip_range):
# IP address.
return ip == ip_range
- raise Exception('Unsupported IP range or address: %r!' % ip_range)
+ raise Exception('Unsupported IP range or address: %r!' % (ip_range,))
def query(ip_addr):
diff --git a/netaddr/ip/nmap.py b/netaddr/ip/nmap.py
index 4aa6775..bacc577 100644
--- a/netaddr/ip/nmap.py
+++ b/netaddr/ip/nmap.py
@@ -31,15 +31,15 @@ def _nmap_octet_target_values(spec):
low = int(left)
high = int(right)
if not ((0 <= low <= 255) and (0 <= high <= 255)):
- raise ValueError('octet value overflow for spec %s!' % spec)
+ raise ValueError('octet value overflow for spec %s!' % (spec,))
if low > high:
- raise ValueError('left side of hyphen must be <= right %r' % element)
+ raise ValueError('left side of hyphen must be <= right %r' % (element,))
for octet in _iter_range(low, high + 1):
values.add(octet)
else:
octet = int(element)
if not (0 <= octet <= 255):
- raise ValueError('octet value overflow for spec %s!' % spec)
+ raise ValueError('octet value overflow for spec %s!' % (spec,))
values.add(octet)
return sorted(values)
@@ -57,7 +57,7 @@ def _generate_nmap_octet_ranges(nmap_target_spec):
tokens = nmap_target_spec.split('.')
if len(tokens) != 4:
- raise AddrFormatError('invalid nmap range: %s' % nmap_target_spec)
+ raise AddrFormatError('invalid nmap range: %s' % (nmap_target_spec,))
return (_nmap_octet_target_values(tokens[0]),
_nmap_octet_target_values(tokens[1]),
@@ -69,7 +69,7 @@ def _parse_nmap_target_spec(target_spec):
if '/' in target_spec:
_, prefix = target_spec.split('/', 1)
if not (0 < int(prefix) < 33):
- raise AddrFormatError('CIDR prefix expected, not %s' % prefix)
+ raise AddrFormatError('CIDR prefix expected, not %s' % (prefix,))
net = IPNetwork(target_spec)
if net.version != 4:
raise AddrFormatError('CIDR only support for IPv4!')
diff --git a/netaddr/ip/rfc1924.py b/netaddr/ip/rfc1924.py
index c4f0f9c..54fb96c 100644
--- a/netaddr/ip/rfc1924.py
+++ b/netaddr/ip/rfc1924.py
@@ -49,7 +49,7 @@ def base85_to_ipv6(addr):
tokens = list(addr)
if len(tokens) != 20:
- raise AddrFormatError('Invalid base 85 IPv6 address: %r' % addr)
+ raise AddrFormatError('Invalid base 85 IPv6 address: %r' % (addr,))
result = 0
for i, num in enumerate(reversed(tokens)):