U
    Â@Ûfø	  ã                   @   sd   d Z ddlZddlmZ ddlZeedœdd„Zeeef edœdd	„Z	eeef edœd
d„Z
dS )zIPv4 helper functions.é    N)ÚUnion)ÚaddressÚreturnc                 C   s4   t | ƒdkrtjj‚d| d | d | d | d f S )z�Convert an IPv4 address in binary form to text form.

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

    Returns a ``str``.
    é   z%u.%u.%u.%ur   é   é   é   )ÚlenÚdnsÚ	exceptionÚSyntaxError)r   © r   úB/var/www/html/chatgpt/venv/lib/python3.8/site-packages/dns/ipv4.pyÚ	inet_ntoa   s    r   )Útextr   c                 C   s´   t | tƒs|  ¡ }n| }| d¡}t|ƒdkr6tjj‚|D ]8}| ¡ sNtjj‚t|ƒdkr:|d t	dƒkr:tjj‚q:zdd„ |D ƒ}t
jd
|žŽ W S  tk
r®   tjj‚Y nX d	S )zšConvert an IPv4 address in text form to binary form.

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

    Returns a ``bytes``.
    ó   .r   r   r   Ú0c                 S   s   g | ]}t |ƒ‘qS r   )Úint)Ú.0Úpartr   r   r   Ú
<listcomp>=   s     zinet_aton.<locals>.<listcomp>ÚBBBBN)r   )Ú
isinstanceÚbytesÚencodeÚsplitr	   r
   r   r   ÚisdigitÚordÚstructÚpackÚ	Exception)r   ZbtextÚpartsr   Úbr   r   r   Ú	inet_aton'   s     



r#   c                 C   s   t j t j | ¡¡S )zïVerify that *address* is a valid text form IPv4 address and return its
    canonical text form.

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

    Raises ``dns.exception.SyntaxError`` if the text is not valid.
    )r
   Zipv4r   r#   )r   r   r   r   ÚcanonicalizeC   s    
r$   )Ú__doc__r   Útypingr   Zdns.exceptionr
   r   Ústrr   r#   r$   r   r   r   r   Ú<module>   s   