in scripts/ValidateParameters/netaddr/eui/__init__.py [0:0]
def __init__(self, iab, strict=False):
"""
Constructor
:param iab: an IAB string ``00-50-C2-XX-X0-00`` or an unsigned \
integer. This address looks like an EUI-48 but it should not \
have any non-zero bits in the last 3 bytes.
:param strict: If True, raises a ValueError if the last 12 bits \
of IAB MAC/EUI-48 address are non-zero, ignores them otherwise. \
(Default: False)
"""
super(IAB, self).__init__()
# Lazy loading of IEEE data structures.
from netaddr.eui import ieee
self.record = {
'idx': 0,
'iab': '',
'org': '',
'address': [],
'offset': 0,
'size': 0,
}
if isinstance(iab, str):
#TODO: Improve string parsing here.
#TODO: '00-50-C2' is actually invalid.
#TODO: Should be '00-50-C2-00-00-00' (i.e. a full MAC/EUI-48)
int_val = int(iab.replace('-', ''), 16)
iab_int, user_int = self.split_iab_mac(int_val, strict=strict)
self._value = iab_int
elif _is_int(iab):
iab_int, user_int = self.split_iab_mac(iab, strict=strict)
self._value = iab_int
else:
raise TypeError('unexpected IAB format: %r!' % iab)
# Discover offsets.
if self._value in ieee.IAB_INDEX:
fh = open(ieee.IAB_REGISTRY_PATH, 'rb')
(offset, size) = ieee.IAB_INDEX[self._value][0]
self.record['offset'] = offset
self.record['size'] = size
fh.seek(offset)
data = fh.read(size).decode('UTF-8')
self._parse_data(data, offset, size)
fh.close()
else:
raise NotRegisteredError('IAB %r not unregistered!' % iab)