Ñò î¡ßNc@s’dZddkZddklZd„ZeƒZd„Zd„Zd„Z dd „Z dd „Z dd „Z d „Z d „Zd„ZdS(s) Shared logic for various address types. iÿÿÿÿN(t_rangecCsƒg}tdddƒ}xdtdƒD]V}ddg}x*|D]"}d|d@||<|dL}q?W|idi|ƒƒq%W|S( s @return: A 256 element list containing 8-bit binary digit strings. The list index value is equivalent to its bit string value. iiÿÿÿÿiit01itN(RtrangetNonetappendtjoin(tlookupt bits_per_bytetnumtbitsti((s=/usr/lib/python2.6/site-packages/netaddr/strategy/__init__.pyt bytes_to_bitss  cCsst|dƒptSt|ƒ|jotSd|d}x1|D])}d|jo |jnptSqBWtS(s4 @param words: A sequence of unsigned integer word values. @param word_size: Width (in bits) of each unsigned integer word value. @param num_words: Number of unsigned integer words expected. @return: C{True} if word sequence is valid for this address type, C{False} otherwise. t__iter__iii(thasattrtFalsetlentTrue(twordst word_sizet num_wordstmax_wordR ((s=/usr/lib/python2.6/site-packages/netaddr/strategy/__init__.pyt valid_words!s  cCs¬d||d}d|jo |jnptdt|ƒƒ‚nd|d}g}x;t|ƒD]-}||@}|it|ƒƒ||L}qkWtt|ƒƒS(sJ @param int_val: Unsigned integer to be divided into words of equal size. @param word_size: Width (in bits) of each unsigned integer word value. @param num_words: Number of unsigned integer words expected. @return: A tuple contain unsigned integer word values split according to provided arguments. iiisinteger out of bounds: %r!(t IndexErrorthexRRtintttupletreversed(tint_valRRtmax_intRRt_tword((s=/usr/lib/python2.6/site-packages/netaddr/strategy/__init__.pyt int_to_words;s   cCsrt|||ƒptd|ƒ‚nd}x>tt|ƒƒD]*\}}|}|||>}||B}q@W|S(s5 @param words: A sequence of unsigned integer word values. @param word_size: Width (in bits) of each unsigned integer word value. @param num_words: Number of unsigned integer words expected. @return: An unsigned integer that is equivalent to value represented by word sequence. s"invalid integer word sequence: %r!i(Rt ValueErrort enumerateR(RRRRR R R((s=/usr/lib/python2.6/site-packages/netaddr/strategy/__init__.pyt words_to_intVs  RcCs¨t|dƒptS|djo|i|dƒ}nt|ƒ|jotSd|d}y0dt|dƒjo |jnotSWntj onXtS(sj @param bits: A network address in a delimited binary string format. @param width: Maximum width (in bits) of a network address (excluding delimiters). @param word_sep: (optional) character or string used to delimit word groups (default: '', no separator). @return: C{True} if network address is valid, C{False} otherwise. treplaceRiii(RRR$RRRR!(R twidthtword_sepR((s=/usr/lib/python2.6/site-packages/netaddr/strategy/__init__.pyt valid_bitsms  ' cCsWt|||ƒptd|ƒ‚n|djo|i|dƒ}nt|dƒS(s¡ @param bits: A network address in a delimited binary string format. @param width: Maximum width (in bits) of a network address (excluding delimiters). @param word_sep: (optional) character or string used to delimit word groups (default: '', no separator). @return: An unsigned integer that is equivalent to value represented by network address in readable binary form. s#invalid readable binary string: %r!Ri(R'R!R$R(R R%R&((s=/usr/lib/python2.6/site-packages/netaddr/strategy/__init__.pyt bits_to_ints  cCsÝg}x’t|||ƒD]~}g}x+|o#|it|d@ƒ|dL}q(W|iƒdi|ƒpd|}d||| }|i|ƒqW|dj o(t|dƒptd|ƒ‚qÐn|i|ƒS(s¯ @param int_val: An unsigned integer. @param word_size: Width (in bits) of each unsigned integer word value. @param num_words: Number of unsigned integer words expected. @param word_sep: (optional) character or string used to delimit word groups (default: '', no separator). @return: A network address in a delimited binary string format that is equivalent in value to unsigned integer. iÿiRt0Rs#word separator is not a string: %r!(R Rt BYTES_TO_BITStreverseRRR!(RRRR&t bit_wordsRR tbit_str((s=/usr/lib/python2.6/site-packages/netaddr/strategy/__init__.pyt int_to_bits£s   cCs¬t|dƒptS|idƒptS|iddƒ}t|ƒ|jotSd|d}y0dt|dƒjo |jnotSWntj onXtS(s @param bin_val: A network address in Python's binary representation format ('0bxxx'). @param width: Maximum width (in bits) of a network address (excluding delimiters). @return: C{True} if network address is valid, C{False} otherwise. t startswitht0bRiii(RRR/R$RRRR!(tbin_valR%R((s=/usr/lib/python2.6/site-packages/netaddr/strategy/__init__.pyt valid_binÅs ' cCsÇg}yt|ƒ}Wntj os|}x7|djo)|d@}|it|ƒ|dL}q0W|iƒdtidddi|ƒƒ}nXt|dƒ|jot d |ƒ‚n|S( sÚ @param int_val: An unsigned integer. @param width: Maximum allowed width (in bits) of a unsigned integer. @return: Equivalent string value in Python's binary representation format ('0bxxx'). iiÿiR0s ^[0]+([01]+)$s\1Ris binary string out of bounds: %s!( tbint NameErrorRR*R+t_retsubRRR(RR%t bin_tokensR1R R((s=/usr/lib/python2.6/site-packages/netaddr/strategy/__init__.pyt int_to_binås    'cCs=t||ƒptd|ƒ‚nt|iddƒdƒS(s9 @param bin_val: A string containing an unsigned integer in Python's binary representation format ('0bxxx'). @param width: Maximum allowed width (in bits) of a unsigned integer. @return: An unsigned integer that is equivalent to value represented by Python binary string format. s%not a valid Python binary string: %r!R0Ri(R2R!RR$(R1R%((s=/usr/lib/python2.6/site-packages/netaddr/strategy/__init__.pyt bin_to_ints (t__doc__treR5tnetaddr.compatRR R*RR R#R'R(R.R2R8R9(((s=/usr/lib/python2.6/site-packages/netaddr/strategy/__init__.pyts        "