o
    {,h                     @   sP   d dl Z d dlmZ d dlmZ dZefddZdedefd	d
Zdd Z	dS )    N)ValidationError)gettext_lazy'   c                 C   s0   t | |krtd|  dttt| S )NzUnable to convert z% to an IPv6 address (value too long).)len
ValueError	ipaddressIPv6Addressint)ip_str
max_length r   G/var/www/html/rh/venv/lib/python3.10/site-packages/django/utils/ipv6.py_ipv6_address_from_str	   s
   
r   Fz!This is not a valid IPv6 address.c              	   C   sd   zt | |}W n ty   t|ddtdidw |r$|jr$t|jS |jr.d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protocolIPv6)codeparamsz	::ffff:%s)r   r   r   _ipv4_mappedstr)r
   unpack_ipv4error_messager   addrr   r   r   clean_ipv6_address   s   

r   c              	   C   s8   t | tjrdS zt|  W dS  ttfy   Y dS w )zF
    Return whether the `ip_addr` object is a valid IPv6 address.
    TF)
isinstancer   r   r   	TypeErrorr   )ip_addrr   r   r   is_valid_ipv6_address6   s   
r   )
r   django.core.exceptionsr   django.utils.translationr   r   MAX_IPV6_ADDRESS_LENGTHr   r   r   r   r   r   r   <module>   s    

%