o
    h                     @   s   d Z ddlZddlZddlmZmZ ddlZddlZe	dZ
dedefddZe	d	Ze	d
Ze	dZddeeef dedefddZdZdedefddZdeeef defddZdS )zIPv6 helper functions.    N)ListUnionz0+([0-9a-f]+)addressreturnc                 C   s  t | dkr
tdt| }g }d}t |}||k r@|||d   }t|}|dur3|d}|| |d7 }||k sd}d}d}	d}
t	d	D ]!}|| d
krg|
rf|}||	 }||krd|	}|}d}
qL|
sm|}	d}
qL|
r~d	}||	 }||kr~|	}|}|dkr|dkr|dks|dkr|d dkr|dkrd}nd}|t
j| dd  }|S d|d| d d||| d  }|S 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binasciihexlifydecode_leading_zeromatchgroupappendrangednsipv4	inet_ntoajoin)r   hexchunksilchunkmZ
best_startZbest_lenstartZlast_was_zeroendZcurrent_lenprefixZthex r'   ;/var/www/html/venv/lib/python3.10/site-packages/dns/ipv6.pyr      sl   	



$	
r   s   (.*):(\d+\.\d+\.\d+\.\d+)$s   ::.*s   .*::$Ftextignore_scopec              	   C   s@  t | ts
|  }n| }|r(|d}t|}|dkr |d }n|dkr(tjj|dkr0tjj|dr>|ds>tjj|	drL|	dsLtjj|dkrRd}t
|}|durtj|d}|d	  d
|d d|d	 dd
|d d|d d }t|}|dur|d	d }nt|}|dur|dd }|d}t|}|dkrtjjd}g }	|D ]=}
|
dkr|rtjjd}tdd| d	 D ]}|	d qqt|
}|dkrtjj|dkrdd|  |
 }
|	|
 q|dk r|stjjd|	}zt|W S  tjtfy   tjjw )a+  Convert an IPv6 address in text form to binary form.

    *text*, a ``str`` or ``bytes``, 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::Nr   r   02x   r	   r
   FTs   0000r      0)
isinstancebytesencodesplitr   r   	exceptionSyntaxErrorendswith
startswith
_v4_endingr   r   	inet_atonr   r   _colon_colon_start_colon_colon_endr   r   r   r   	unhexlifyError	TypeError)r)   r*   Zbtextpartsr!   r#   br   Z
seen_empty	canonicalc_lcr'   r'   r(   r;   h   st   




<



r;   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``.
    )r9   _mapped_prefix)r   r'   r'   r(   	is_mapped   s   
rH   c                 C   s   t jt j| S )a  Verify that *address* is a valid text form IPv6 address and return its
    canonical text form.  Addresses with scopes are rejected.

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

    Raises ``dns.exception.SyntaxError`` if the text is not valid.
    )r   Zipv6r   r;   )r)   r'   r'   r(   canonicalize   s   rI   )F)__doc__r   retypingr   r   Zdns.exceptionr   Zdns.ipv4compiler   r3   strr   r:   r<   r=   boolr;   rG   rH   rI   r'   r'   r'   r(   <module>   s   

E

 [