#Sc@sdZddlZddlZddlZejdZdZejdZejdZ ejdZ dZ dZ d Z dS(sIPv6 helper functions.iNs 0+([0-9a-f]+)cCs/t|dkr!tdn|jd}g}d}t|}xe||kr|||d!}tj|}|dk r|jd}n|j||d7}qKWd}d}d} t} xvt dD]h}||d kr(| r=|} | | } | |kr| }| }nt} q=q| s|} t } qqW| rud} | | } | |kru| }| }qun|dkr|dkr|d ks|d kr|d d kr|d krd } nd} | t j j |d}q+dj|| d dj|||}ndj|}|S(sConvert a network format IPv6 address into text. @param address: the binary address @type address: string @rtype: string @raises ValueError: the address isn't 16 bytes long is IPv6 addresses are 16 bytes longt hex_codeciiiiit0iitffffs::s::ffff:i t:N(tlent ValueErrortencodet _leading_zerotmatchtNonetgrouptappendtFalsetxrangetTruetdnstipv4t inet_ntoatjoin(taddressthextchunkstitltchunktmt best_starttbest_lentstartt last_was_zerotendt current_lentprefix((s./usr/lib64/python2.7/site-packages/dns/ipv6.pyRs^                 s(.*):(\d+\.\d+\.\d+\.\d+)$s::.*s.*::$c CsO|dkrd}ntj|}|dk rtjj|jd}d|jdt|dt|dt|dt|df}ntj|}|dk r|d}n(t j|}|dk r|d }n|j d }t |}|d krtj j nt}g}x|D]}|d kr|rXtj j nt}xtdd |dD]}|jd qvWq1t |} | d krtj j n| d krdd | |}n|j|q1W|d kr | r tj j nd j|}y|jdSWntk rJtj j nXdS(sConvert a text format IPv6 address into network format. @param text: the textual address @type text: string @rtype: string @raises dns.exception.SyntaxError: the text was not properly formatted s::s0::is%s:%02x%02x:%02x%02xiiiiRitt0000iRRN(t _v4_endingRR RRt inet_atonR tordt_colon_colon_startt_colon_colon_endtsplitRt exceptiont SyntaxErrorR RR R Rtdecodet TypeError( ttextRtbRRt seen_emptyt canonicaltcRtlc((s./usr/lib64/python2.7/site-packages/dns/ipv6.pyR$`sN   )$            si scCs |jtS(N(t startswitht_mapped_prefix(R((s./usr/lib64/python2.7/site-packages/dns/ipv6.pyt is_mappedss s (t__doc__tret dns.exceptionRtdns.ipv4tcompileRRR#R&R'R$R4R5(((s./usr/lib64/python2.7/site-packages/dns/ipv6.pyts    C E