in scripts/ValidateParameters/netaddr/strategy/eui48.py [0:0]
def str_to_int(addr):
"""
:param addr: An IEEE EUI-48 (MAC) address in string form.
:return: An unsigned integer that is equivalent to value represented
by EUI-48/MAC string address formatted according to the dialect
settings.
"""
words = []
if _is_str(addr):
found_match = False
for regexp in RE_MAC_FORMATS:
match_result = regexp.findall(addr)
if len(match_result) != 0:
found_match = True
if isinstance(match_result[0], tuple):
words = match_result[0]
else:
words = (match_result[0],)
break
if not found_match:
raise AddrFormatError('%r is not a supported MAC format!' % addr)
else:
raise TypeError('%r is not str() or unicode()!' % addr)
int_val = None
if len(words) == 6:
# 2 bytes x 6 (UNIX, Windows, EUI-48)
int_val = int(''.join(['%.2x' % int(w, 16) for w in words]), 16)
elif len(words) == 3:
# 4 bytes x 3 (Cisco)
int_val = int(''.join(['%.4x' % int(w, 16) for w in words]), 16)
elif len(words) == 2:
# 6 bytes x 2 (PostgreSQL)
int_val = int(''.join(['%.6x' % int(w, 16) for w in words]), 16)
elif len(words) == 1:
# 12 bytes (bare, no delimiters)
int_val = int('%012x' % int(words[0], 16), 16)
else:
raise AddrFormatError('unexpected word count in MAC address %r!' % addr)
return int_val