o inh@sdZddlZdZzddlZejsedejej ddlmZ m Z m Z dZWney:ddl mZ m Z m Z YnwddlmZddlmZmZmZmZmZmZmZmZ 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#dDZ2Gddde3Z4Gddde4Z5Gddde4Z6d9ddZ7d9ddZ8d:dd Z9d!d"Z:d#d$Z;d%d&ZD$rcCs$g|]}tdt|dA|fqSrrrrrrrHr cCs g|] }|dt|dfqSrrrrrrrL cCs g|] }dt|d|fqSrr!rrrrrPr"c@eZdZdZdZdZdS) 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@r#) ipv6_verbosez5An IPv6 dialect class - extra wide 'all zeroes' form.z%.4xFNr%rrrrr-dsr-cCs.|dkrtdztt|WdSYdS)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  r2cCs2z tt|}t|WStytd|fw)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!)r/r packed_to_int Exceptionr)r0r1 packed_intrrr str_to_ints    r6cs~durtd}z(t|}jrtt|}W|Sttd|}fdd|D}t |}W|St y>t d|fw)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_sepjoinr4 ValueError)int_valr9r0r5wordstokensrr8r int_to_strs     rEcCs8t|t}t|dd}||gd}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.)ip6arpar..)rEr-r<replacereverser@)rBr0rDrrr int_to_arpas   rKcCst|dd}tjdg|RS)z :param int_val: the integer to be packed. :return: a packed string that is equivalent to value represented by an unsigned integer.  >4I)rr=pack)rBrCrrrr:s r: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. rNrrM)r<r=r> enumeratereversed)r5rCrBrnumr7rrrr3s  r3cC t|ttSN) _valid_words word_size num_wordsrCrrrr rcCs0|dur td}|durtd}t|||S)NrWrV)globals _int_to_words)rBrWrVrrrrs    rcCrSrT) _words_to_intrVrWrXrrrrrYrcCrSrT) _valid_bitsrr?bitsrrrr rYr cCrSrT) _bits_to_intrr?r^rrrr rYr cCs |dur td}t|tt|S)Nr?)rZ _int_to_bitsrVrW)rBr?rrrr s r cC t|tSrT) _valid_binrbin_valrrrr  r cCrbrT) _int_to_binr)rBrrrr rfr cCrbrT) _bin_to_intrrdrrrrrfr)rrT)NN)=r)structr= OPT_IMPORTSsocket_sockethas_ipv6r4rrr/rr;netaddr.fbsocket netaddr.corernetaddr.strategyrrUrr[rr\r r]r r`r rar rcr rgrrhrrVr?family family_nameversion word_baserrWmax_worddictrangeprefix_to_netmasknetmask_to_prefixprefix_to_hostmaskhostmask_to_prefixobjectr$r,r-r2r6rErKr:r3rrrrsp  ,