3 bW@sdZddlZddlZddlZddlZddlmZmZm Z ej dZ ddZ ej dZ ej d Zej d Zd d ZdZddZdS)zIPv6 helper functions.N)xrange binary_type maybe_decodes 0+([0-9a-f]+)cCst|dkrtdtj|}g}d}t|}xJ||krx|||d}tj|}|dk rd|jd}|j||d7}q0Wd}d}d} d} xNtdD]B}||d kr| r|} | | } | |kr| }| }d} q| s|} d } qW| rd} | | } | |kr| }| }|dkr|dkrb|d ks4|d krb|d d krb|d krDd} nd} | t j j |dd}n,dj |d|ddj |||d}n dj |}t |S)zConvert 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 z IPv6 addresses are 16 bytes longrNrF0Tsffffs::s::ffff: :)len ValueErrorbinasciiZhexlify _leading_zeromatchgroupappendrdnsipv4 inet_ntoajoinr)addresshexchunksilchunkmZ best_startZbest_lenstartZ last_was_zeroendZ current_lenprefixr$/usr/lib/python3.6/ipv6.pyrs^              rs(.*):(\d+\.\d+\.\d+\.\d+)$s::.*s.*::$c Cst|ts|j}|dkrd}tj|}|dk rvttjj|j d}d|j dj |d|d|d|dfj}t j|}|dk r|dd}nt j|}|dk r|dd}|j d }t|}|d krtjjd }g}x|D]}|d kr.|rtjjd }xftdd |dD]}|jdqWqt|} | dkrHtjj| dkrbdd| |}|j|qW|d kr| rtjjd j|}y tj|Stjtfk rtjjYnXdS)zConvert 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::Nz%s:%02x%02x:%02x%02xrrr rFTs0000rr r) isinstancerencode _v4_endingr bytearrayrr inet_atonrdecode_colon_colon_start_colon_colon_endsplitrZ exception SyntaxErrorrrrrZ unhexlifyError TypeError) textr brrZ seen_emptyZ canonicalcrZlcr$r$r%r-bsR            r- scCs |jtS)N) startswith_mapped_prefix)rr$r$r% is_mappedsr<s s )__doc__rerZ dns.exceptionrZdns.ipv4Z_compatrrrcompilerrr+r/r0r-r;r<r$r$r$r%s C   G