U
    8ÄT_F  ã                   @   s>   d dl Z d dlmZ d dlmZ dedƒfdd„Zdd	„ ZdS )
é    N)ÚValidationError)Úgettext_lazyFz!This is not a valid IPv6 address.c                 C   sj   zt  tt  | ¡ƒ¡}W n  tk
r8   t|dd�‚Y nX |rN|jrNt|jƒS |jrbdt|jƒ S t|ƒS )aý  
    Clean an IPv6 address string.

    Raise ValidationError if the address is invalid.

    Replace the longest continuous zero-sequence with "::", remove leading
    zeroes, and make sure all hextets are lowercase.

    Args:
        ip_str: A valid IPv6 address.
        unpack_ipv4: if an IPv4-mapped address is found,
        return the plain IPv4 address (default=False).
        error_message: An error message used in the ValidationError.

    Return a compressed IPv6 address or the same value.
    Úinvalid)Úcodez	::ffff:%s)Ú	ipaddressÚIPv6AddressÚintÚ
ValueErrorr   Úipv4_mappedÚstr)Úip_strZunpack_ipv4Úerror_messageÚaddr© r   ú5/tmp/pip-unpacked-wheel-dv63caxw/django/utils/ipv6.pyÚclean_ipv6_address   s    

r   c                 C   s*   zt  | ¡ W n tk
r$   Y dS X dS )zL
    Return whether or not the `ip_str` string is a valid IPv6 address.
    FT)r   r   r	   )r   r   r   r   Úis_valid_ipv6_address&   s
    r   )r   Zdjango.core.exceptionsr   Zdjango.utils.translationr   Ú_r   r   r   r   r   r   Ú<module>   s   ÿ
