Ñò î¡ßNc@sdZddkZddkZyddklZWnej o dZnXddkl Z ddk l Z l ZlZlZlZlZlZlZlZlZdZeZ dZ!dZ"ded Z#d e$fd „ƒYZ%d e%fd „ƒYZ&de%fd„ƒYZ'de%fd„ƒYZ(de%fd„ƒYZ)e%Z*ddi+dgdƒdddi+dgdƒdddi+dgdƒdddi+dgdƒdddi+dgdƒdddi+dgdƒdddi+dgdƒdddi+d gd!ƒd"ddi+d gd#ƒd"f Z,gZ-e,D]Z.e-ei/e.ei0ƒqB[-Z,d$„Z1d%„Z2dd&„Z4d'„Z5d(„Z6dd)„Z dd*„Zdd+„Zdd,„Zdd-„Zdd.„Zdd/„Zd0„Zd1„ZdS(2s› 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. iÿÿÿÿN(tAF_LINKi0(tAddrFormatError( t BYTES_TO_BITSt valid_wordst int_to_wordst words_to_intt valid_bitst bits_to_intt int_to_bitst valid_bint int_to_bint bin_to_inttMACiit mac_eui48cBs>eZdZdZeeZdedZdZdZdZ RS(s%A standard IEEE EUI-48 dialect class.iiit-s%.2Xi( t__name__t __module__t__doc__t word_sizetwidtht num_wordstmax_wordtword_septword_fmtt word_base(((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyR 4s tmac_unixcBs0eZdZdZeeZdZdZdZRS(s'A UNIX-style MAC address dialect class.it:s%xi( RRRRRRRRR(((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyRHs  t mac_ciscocBs0eZdZdZeeZdZdZdZRS(s2A Cisco 'triple hextet' MAC address dialect class.it.s%.4x( RRRRRRRRR(((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyRPs  tmac_barecBs0eZdZdZeeZdZdZdZRS(s1A bare (no delimiters) MAC address dialect class.i0ts%.12Xi( RRRRRRRRR(((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyRXs  t mac_pgsqlcBs0eZdZdZeeZdZdZdZRS(s@A PostgreSQL style (2 x 24-bit words) MAC address dialect class.iRs%.6xi( RRRRRRRRR(((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyR`s  t^Rs([0-9A-F]{1,2})it$Rs([0-9A-F]{1,4})is\.s([0-9A-F]{5,6})s^(Rs[0-9A-F]i s)$i cCsVxOtD]G}y+|i|ƒ}t|ƒdjotSWqtj oqXqWtS(s @param addr: An IEEE EUI-48 (MAC) address in string form. @return: C{True} if MAC address string is valid, C{False} otherwise. i(tRE_MAC_FORMATStfindalltlentTruet TypeErrortFalse(taddrtregexpt match_result((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyt valid_str„s  c Csg}t|dƒo’t}xjtD]b}|i|ƒ}t|ƒdjo:t}t|dtƒo|d}n|df}Pq#q#W|ptd|ƒ‚q¸nt d|ƒ‚d}t|ƒdjoDt di g}|D]}|dt |dƒqå~ƒdƒ}nöt|ƒd joDt di g}|D]}|d t |dƒq<~ƒdƒ}nŸt|ƒd joDt di g} |D]}| d t |dƒq“~ ƒdƒ}nHt|ƒd jo$t dt |ddƒdƒ}ntd|ƒ‚|S(sç @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. tupperis!%r is not a supported MAC format!s%r is not str() or unicode()!iRs%.2xiis%.4xis%.6xis%012xs(unexpected word count in MAC address %r!N( thasattrR'R"R#R$R%t isinstancettupleRR&tNonetinttjoin( R(twordst found_matchR)R*tint_valt_[1]twt_[2]t_[3]((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyt str_to_int•s6  DDD$ cCsd|djo t}nt||ƒ}g}|D]}||i|q1~}|ii|ƒ}|S(s @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. N(R0R RRRR2(R5tdialectR3R6tittokensR(((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyt int_to_strÃs  (cCstid|d?|d@ƒS(s• @param int_val: the integer to be packed. @return: a packed string that is equivalent to value represented by an unsigned integer. s>HIi lÿÿ(t_structtpack(R5((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyt int_to_packedÖscCscttid|ƒƒ}d}x>tt|ƒƒD]*\}}|}|d|>}||B}q1W|S(s @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. s>6Bii(tlistR?tunpackt enumeratetreversed(t packed_intR3R5R<tnumtword((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyt packed_to_intàs cCs-|djo t}nt||i|iƒS(N(R0tDEFAULT_DIALECTt _valid_wordsRR(R3R;((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyRós  cCs-|djo t}nt||i|iƒS(N(R0RJt _int_to_wordsRR(R5R;((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyRùs  cCs-|djo t}nt||i|iƒS(N(R0RJt _words_to_intRR(R3R;((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyRÿs  cCs*|djo t}nt|t|iƒS(N(R0RJt _valid_bitsRR(tbitsR;((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyRs  cCs*|djo t}nt|t|iƒS(N(R0RJt _bits_to_intRR(ROR;((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyR s  cCs3|djo t}nt||i|i|iƒS(N(R0RJt _int_to_bitsRRR(R5R;((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyRs  cCs$|djo t}nt|tƒS(N(R0RJt _valid_binR(tbin_valR;((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyR s  cCs t|tƒS(N(t _int_to_binR(R5((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyR scCs t|tƒS(N(t _bin_to_intR(RS((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyR "s(7RtstructR?tret_retsocketRt ImportErrort netaddr.coreRtnetaddr.strategyRt_BYTES_TO_BITSRRKRRLRRMRRNRRPRRQR RRR RTR RURtfamilyt family_nametversiontmax_inttobjectR RRRRRJR2R"R6t_tcompilet IGNORECASER+R:R0R>RARI(((s:/usr/lib/python2.6/site-packages/netaddr/strategy/eui48.pyt sV   F  !0  .