o inh! @s\dZddlZddlZzddlmZWn eydZYnwddlm Z ddl m Z ddl m ZmZmZmZmZmZmZmZmZdZeZ dZ!dZ"d ed Z#Gd d d e$Z%Gd dde%Z&Gddde&Z'Gddde%Z(Gddde%Z)Gddde%Z*e%Z+dd,dgdddd,dgdddd,dgdddd,dgdddd,dgdddd,d gd ddd,d gd dd!d",d#gd$d%d!d",d#gd&d%f Z-d'd(e-DZ-d)d*Z.d+d,Z/dEd-d.Z0d/d0Z1d1d2Z2dEd3d4Z dEd5d6ZdEd7d8ZdEd9d:ZdEd;d<ZdEd=d>ZdEd?d@ZdAdBZdCdDZdS)Fz IEEE 48-bit EUI (MAC address) logic. Supports numerous MAC string formats including Cisco's triple hextet as well as bare MACs containing no delimiters. N)AF_LINK0)AddrFormatError)_is_str) valid_words int_to_words words_to_int valid_bits bits_to_int int_to_bits valid_bin int_to_bin bin_to_intMACc@s4eZdZdZdZeeZdedZdZdZ dZ dS) mac_eui48z%A standard IEEE EUI-48 dialect class.rr-z%.2XN) __name__ __module__ __qualname____doc__ word_sizewidth num_wordsmax_wordword_sepword_fmt word_baser!r!A/usr/local/lib/python3.10/dist-packages/netaddr/strategy/eui48.pyr1s rc@(eZdZdZdZeeZdZdZdZ dS)mac_unixz'A UNIX-style MAC address dialect class.r:z%xrN rrrrrrrrrr r!r!r!r"r$Fr$c@seZdZdZdZdS)mac_unix_expandedz;A UNIX-style MAC address dialect class with leading zeroes.%.2xN)rrrrrr!r!r!r"r(Osr(c@s(eZdZdZdZeeZdZdZdZ dS) mac_ciscoz2A Cisco 'triple hextet' MAC address dialect class.r.%.4xNr&r!r!r!r"r*Tr'r*c@r#)mac_barez1A bare (no delimiters) MAC address dialect class.rz%.12XrNr&r!r!r!r"r-]r'r-c@r#) mac_pgsqlz@A PostgreSQL style (2 x 24-bit words) MAC address dialect class.r%%.6xrNr&r!r!r!r"r/fr'r/^r%z([0-9A-F]{1,2})$rz([0-9A-F]{1,4})z\.z([0-9A-F]{5,6})z^(r.z[0-9A-F] z)$ cCsg|] }t|tjqSr!)_recompile IGNORECASE).0_r!r!r" r=c CsBtD]}z||}t|dkrWdSWqtyYqwdS)z :param addr: An IEEE EUI-48 (MAC) address in string form. :return: ``True`` if MAC address string is valid, ``False`` otherwise. rTF)RE_MAC_FORMATSfindalllen TypeError)addrregexp match_resultr!r!r" valid_strs   rFcCs4g}t|r7d}tD]"}||}t|dkr,d}t|dtr%|d}n|df}nq |s6td|fntd|fd}t|dkrUtd d d |Dd }|St|d krjtd d d |Dd }|St|dkrtd dd |Dd }|St|dkrtdt|dd d }|Std|f)z :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. FrTz!%r is not a supported MAC format!z%r is not str() or unicode()!Nr3r.cSg|] }dt|dqS)r)rintr;wr!r!r"r=r>zstr_to_int..rr5cSrG)r,rrHrJr!r!r"r=r>rcSrG)r1rrHrJr!r!r"r=r>rz%012xz(unexpected word count in MAC address %r!) rr?r@rA isinstancetuplerrBrIjoin)rCwords found_matchrDrEint_valr!r!r" str_to_ints<        rRcs8durtt|}fdd|D}j|}|S)a :param int_val: An unsigned integer. :param dialect: (optional) a Python class defining formatting options. :return: An IEEE EUI-48 (MAC) address string that is equivalent to unsigned integer formatted according to the dialect settings. Ncsg|]}j|qSr!)r)r;idialectr!r"r=szint_to_str..)rrrrN)rQrUrOtokensrCr!rTr" int_to_strs    rWcCstd|d?|d@S)z :param int_val: the integer to be packed. :return: a packed string that is equivalent to value represented by an unsigned integer. z>HI l)_structpackrQr!r!r" int_to_packedsr\cCsFttd|}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. z>6Brr)listrYunpack enumeratereversed) packed_intrOrQrSnumwordr!r!r" packed_to_ints  rdcC|durt}t||j|jSN)DEFAULT_DIALECT _valid_wordsrrrOrUr!r!r"rrcCrerf)rg _int_to_wordsrrrQrUr!r!r"rrjrcCrerf)rg _words_to_intrrrir!r!r"rrjrcC|durt}t|t|jSrf)rg _valid_bitsrrbitsrUr!r!r"r r cCrnrf)rg _bits_to_intrrrpr!r!r"r rrr cCs |durt}t||j|j|jSrf)rg _int_to_bitsrrrrlr!r!r"r s r cCs|durt}t|tSrf)rg _valid_binr)bin_valrUr!r!r"r s r cC t|tSrf) _int_to_binrr[r!r!r"r # r cCrwrf) _bin_to_intr)rvr!r!r"r'ryrrf)3rstructrYrer8socketr ImportError netaddr.corernetaddr.compatrnetaddr.strategyrrhrrkrrmr ror rsr rtr rur rxrrzrfamily family_nameversionmax_intobjectrr$r(r*r-r/rgrNr?rFrRrWr\rdr!r!r!r"s`   ,      -