U .Ѫ_@sdZddlZdZz>ddlZejs(edejej ddlmZ m Z m Z dZWn(ek rvddl mZ m Z m Z YnXddlmZddlmZmZmZmZmZmZmZmZ m!Z"d Z#d Z$d Z%e Z&d Z'd Z(d Z)de#dZ*e#e$Z+de$dZ,e-dde.de#dDZ/e-dde.de#dDZ0e-dde.de#dDZ1e-dde.de#dDZ2Gddde3Z4Gddde4Z5Gddde4Z6d9ddZ7d:ddZ8d;dd Z9d!d"Z:d#d$Z;d%d&Zz IPv6 address logic. NFz IPv6 disabled) inet_pton inet_ntopAF_INET6T)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:ZIPv6cCs$g|]}|tdt|dAfqSrrmax_intwidth.0irDsrcCs$g|]}tdt|dA|fqSrrrrrrrHscCs g|]}|dt|dfqSrrrrrrrLscCs g|]}dt|d|fqSrrrrrrrPsc@seZdZdZdZdZdS) ipv6_compactz%An IPv6 dialect class - compact form.z%xTN__name__ __module__ __qualname____doc__word_fmtcompactrrrrr Vsr c@seZdZdZdZdS) ipv6_fullz*An IPv6 dialect class - 'all zeroes' form.FN)r"r#r$r%r'rrrrr(^sr(c@seZdZdZdZdZdS) ipv6_verbosez5An IPv6 dialect class - extra wide 'all zeroes' form.z%.4xFNr!rrrrr)dsr)cCs2|dkrtdztt|WnYdSXdS)a :param addr: An IPv6 address in presentation (string) format. :param flags: decides which rules are applied to the interpretation of the addr value. Future use - currently has no effect. :return: ``True`` if IPv6 address is valid, ``False`` otherwise. z Empty strings are not supported!FT)r _inet_ptonr)addrflagsrrr valid_strns r.cCs<ztt|}t|WStk r6td|fYnXdS)a :param addr: An IPv6 address in string form. :param flags: decides which rules are applied to the interpretation of the addr value. Future use - currently has no effect. :return: The equivalent unsigned integer for a given IPv6 address. z&%r is not a valid IPv6 address string!N)r+r packed_to_int Exceptionr)r,r- packed_intrrr str_to_ints   r2csdkr td}zJt|}jr,tt|}n,ttd|}fdd|D}t |}Wn"t k r|t d|fYnX|S)z :param int_val: An unsigned integer. :param dialect: (optional) a Python class defining formatting options. :return: The IPv6 presentation (string) format address equivalent to the unsigned integer provided. Nz>8Hcsg|]}j|qSr)r&)rworddialectrrrszint_to_str..z+%r is not a valid 128-bit unsigned integer!) r int_to_packedr' _inet_ntoprlist_structunpackword_sepjoinr0 ValueError)int_valr5r,r1wordstokensrr4r int_to_strs  rAcCs:t|t}t|dd}||dddg}d|S)z :param int_val: An unsigned integer. :return: The reverse DNS lookup for an IPv6 address in network byte order integer form. rr*Zip6arpa.)rAr)r8replacereverser<)r>r,r@rrr int_to_arpas  rFcCst|dd}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.  >4I)rI)rr9pack)r>r?rrrr6s r6cCsFttd|}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. rIrrH)r8r9r: enumeratereversed)r1r?r>rnumr3rrrr/s  r/cCs t|ttSN) _valid_words word_size num_wordsr?rrrrsrcCs0|dkrtd}|dkr$td}t|||S)NrQrP)globals _int_to_words)r>rQrPrrrrs   rcCs t|ttSrN) _words_to_intrPrQrRrrrrsrcCs t|ttSrN) _valid_bitsrr;bitsrrrr sr cCs t|ttSrN) _bits_to_intrr;rWrrrr sr cCs |dkrtd}t|tt|S)Nr;)rS _int_to_bitsrPrQ)r>r;rrrr s r cCs t|tSrN) _valid_binrbin_valrrrr sr cCs t|tSrN) _int_to_binr)r>rrrr sr cCs t|tSrN) _bin_to_intrr\rrrrsr)r)r)N)NN)N)=r%structr9Z OPT_IMPORTSsocket_sockethas_ipv6r0rrr+rr7Znetaddr.fbsocket netaddr.corernetaddr.strategyrrOrrTrrUr rVr rYr rZr r[r r^rr_rrPr;family family_nameversion word_baserrQmax_worddictrangeprefix_to_netmasknetmask_to_prefixprefix_to_hostmaskhostmask_to_prefixobjectr r(r)r.r2rArFr6r/rrrrsl ,