a
    sd_                     @   sn   d Z ddlZddlZddlZddlZedZdd ZedZ	edZ
edZdd
dZdZdd ZdS )zIPv6 helper functions.    Nz0+([0-9a-f]+)c                 C   s  t | dkrtdt| }g }d}t |}||k rz|||d   }t|}|durf|d}|| |d7 }q.d}d}d}	d}
t	d	D ]B}|| d
kr|
r|}||	 }||kr|	}|}d}
q|
s|}	d}
q|
rd	}||	 }||kr|	}|}|dkr|dkrZ|dks,|dkrZ|d dkrZ|dkr<d}nd}|t
j| dd  }n,d|d| d d||| d  }n
d|}|S )zConvert an IPv6 address in binary form to text form.

    *address*, a ``bytes``, the IPv6 address in binary form.

    Raises ``ValueError`` if the address isn't 16 bytes long.
    Returns a ``str``.
       z IPv6 addresses are 16 bytes longr      N   F   0T      Zffffz::z::ffff:   :)len
ValueErrorbinasciiZhexlifydecode_leading_zeromatchgroupappendrangednsipv4	inet_ntoajoin)addresshexchunksilchunkmZ
best_startZbest_lenstartZlast_was_zeroendZcurrent_lenprefix r#   */usr/lib/python3/dist-packages/dns/ipv6.pyr      sh    	









r   s   (.*):(\d+\.\d+\.\d+\.\d+)$s   ::.*s   .*::$Fc              	   C   s  t | ts|  } |rJ| d}t|}|dkr:|d } n|dkrJtjj| dkrVd} t	| }|durtj
|d}d|d |d |d |d |d	  } t	| }|dur| dd } nt	| }|dur| dd
 } | d}t|}|dkrtjjd}g }|D ]}	|	dkr^|r4tjjd}tdd| d D ]}
|d qJn>t|	}|dkrxtjj|dkrdd|  |	 }	||	 q|dk r|stjjd|} zt| W S  tjtfy   tjjY n0 dS )a  Convert an IPv6 address in text form to binary form.

    *text*, a ``str``, the IPv6 address in textual form.

    *ignore_scope*, a ``bool``.  If ``True``, a scope will be ignored.
    If ``False``, the default, it is an error for a scope to be present.

    Returns a ``bytes``.
       %   r   s   ::s   0::Nz{}:{:02x}{:02x}:{:02x}{:02x}r      r      :r   F    Ts   0000r      0)
isinstancebytesencodesplitr   r   Z	exceptionSyntaxError
_v4_endingr   r   	inet_atonr   formatr   _colon_colon_start_colon_colon_endr   r   r   r   Z	unhexlifyError	TypeError)textZignore_scopepartsr   r   br   Z
seen_emptyZ	canonicalcr   Zlcr#   r#   r$   r1   c   sd    











r1   s             c                 C   s
   |  tS )zIs the specified address a mapped IPv4 address?

    *address*, a ``bytes`` is an IPv6 address in binary form.

    Returns a ``bool``.
    )
startswith_mapped_prefix)r   r#   r#   r$   	is_mapped   s    r=   )F)__doc__rer   Zdns.exceptionr   Zdns.ipv4compiler   r   r0   r3   r4   r1   r<   r=   r#   r#   r#   r$   <module>   s   
C



R