U .Ѫ_ @sdZddlZddlZddlmZddlmZ m Z m Z mZmZmZmZmZmZdZdZeZdZdZdedZGd d d e Z!Gd d d e!Z"Gd dde"Z#Gddde!Z$Gddde!Z%e!Z&dd'dgdddd'dgdddd'dgdddd'dgdddd'dgdddd'dgdd fZ(d!d"e(DZ(d#d$Z)d%d&Z*d'd(Z+dAd)d*Z,d+d,Z-d-d.Z.dBd/d0ZdCd1d2Z dDd3d4Z dEd5d6ZdFd7d8ZdGd9d:ZdHd;d<Zd=d>Zd?d@ZdS)Iz6 IEEE 64-bit EUI (Extended Unique Indentifier) logic. N)AddrFormatError) valid_words int_to_words words_to_int valid_bits bits_to_int int_to_bits valid_bin int_to_bin bin_to_int@zEUI-64c@s4eZdZdZdZeeZdedZdZdZ dZ dS) eui64_basez%A standard IEEE EUI-64 dialect class.r r-z%.2XN) __name__ __module__ __qualname____doc__ word_sizewidth num_wordsmax_wordword_sepword_fmt word_baserr=/Users/cjl/code/aws-vpc-ipam/lambda/netaddr/strategy/eui64.pyr+s rc@s(eZdZdZdZeeZdZdZdZ dS) eui64_unixz'A UNIX-style MAC address dialect class.r:z%xrN rrrrrrrrrrrrrrr @s r c@seZdZdZdZdS)eui64_unix_expandedz;A UNIX-style MAC address dialect class with leading zeroes.%.2xN)rrrrrrrrrr#Isr#c@s(eZdZdZdZeeZdZdZdZ dS) eui64_ciscoz2A Cisco 'triple hextet' MAC address dialect class.r.%.4xNr"rrrrr%Ns r%c@s(eZdZdZdZeeZdZdZdZ dS) eui64_barez1A bare (no delimiters) MAC address dialect class.r z%.16XrNr"rrrrr(Ws r(^r!z([0-9A-F]{1,2})r$rz([0-9A-F]{1,4})z\.z^(r)z[0-9A-F]rz)$cCsg|]}t|tjqSr)_recompile IGNORECASE).0_rrr usr2cCs(|D]}||}|r|dSqdS)Nr)findall)addressformatsregexpmatchrrr_get_match_resultxs r8cCs.zt|trWdSWntk r(YnXdS)z :param addr: An IEEE EUI-64 indentifier in string form. :return: ``True`` if EUI-64 indentifier is valid, ``False`` otherwise. TF)r8RE_EUI64_FORMATS TypeError)addrrrr valid_strs   r<cCsg}zt|t}|stWn"tk r<td|fYnXt|trJn|f}t|dkrxtddd|Dd}nZt|dkrtddd|Dd}n2t|d krtd t|d dd}n td ||S) z :param addr: An IEEE EUI-64 indentifier in string form. :return: An unsigned integer that is equivalent to value represented by EUI-64 string address formatted according to the dialect z#invalid IEEE EUI-64 identifier: %r!rr)cSsg|]}dt|dqS)r$rintr0wrrrr2szstr_to_int..rr,cSsg|]}dt|dqS)r'rr=r?rrrr2srz%016xrz)bad word count for EUI-64 identifier: %r!) r8r9r:r isinstancetuplelenr>join)r;wordsint_valrrr str_to_ints(     rGcs8dkr tt|}fdd|D}j|}|S)z :param int_val: An unsigned integer. :param dialect: (optional) a Python class defining formatting options :return: An IEEE EUI-64 identifier that is equivalent to unsigned integer. Ncsg|]}j|qSr)r)r0idialectrrr2szint_to_str..)rrrrD)rFrJrEtokensr;rrIr int_to_strs   rLcCst|}tjd|S)z :param int_val: the integer to be packed. :return: a packed string that is equivalent to value represented by an unsigned integer. >8B)rM)r_structpack)rFrErrr int_to_packedsrPcCsFttd|}d}tt|D] \}}|}|d|>}||B}q |S)a :param packed_int: a packed string containing an unsigned integer. It is assumed that string is packed in network byte order. :return: An unsigned integer equivalent to value of network address represented by packed binary string. rMrr)listrNunpack enumeratereversed) packed_intrErFrHnumwordrrr packed_to_ints  rXcCs|dkr t}t||j|jSN)DEFAULT_EUI64_DIALECT _valid_wordsrrrErJrrrrsrcCs|dkr t}t||j|jSrY)rZ _int_to_wordsrrrFrJrrrrsrcCs|dkr t}t||j|jSrY)rZ _words_to_intrrr\rrrrsrcCs|dkr t}t|t|jSrY)rZ _valid_bitsrrbitsrJrrrrsrcCs|dkr t}t|t|jSrY)rZ _bits_to_intrrrarrrrsrcCs |dkr t}t||j|j|jSrY)rZ _int_to_bitsrrrr^rrrrsrcCs|dkr t}t|tSrY)rZ _valid_binr)bin_valrJrrrr sr cCs t|tSrY) _int_to_binr)rFrrrr sr cCs t|tSrY) _bin_to_intr)rfrrrr sr )N)N)N)N)N)N)N)N)/rstructrNrer- netaddr.corernetaddr.strategyrr[rr]rr_rr`rrcrrdr rer rgr rhZAF_EUI64rfamily family_nameversionmax_intobjectrr r#r%r(rZrDr9r8r<rGrLrPrXrrrrsN ,     %