o
    7DiW                  
   @   sz   d Z ddlmZ ddlmZ ddlZddlmZmZ ddl	m
Z
 G dd	 d	Ze
d
d
d
ddedededefddZdS )zDomain.    )environ)PathN)OptionalSet   )	validatorc                   @   sV   e Zd ZU dZdZeee  ed< h dZ	e	
d edd Zedefd	d
ZdS )_IanaTLDz*Read IANA TLDs, and optionally cache them.N_full_cache>
   BRDEFRITJPRUUKCOMNETORGONIONc                 c   sX    t tjd }t|}|D ]}| V  qW d    d S 1 s%w   Y  d S )Nz_tld.txt)r   __file__parentjoinpathopennextstrip)clstld_f_line r   J/var/www/Datamplify/venv/lib/python3.10/site-packages/validators/domain.py	_retrieve   s   "z_IanaTLD._retrievetldc                 C   sL   || j v rdS | jd u r!tddkrt|  | _n||  v S || jv S )NTPYVLD_CACHE_TLDTrue)_popular_cacher	   r   getsetr!   )r   r"   r   r   r    check   s   


z_IanaTLD.check)__name__
__module____qualname____doc__r	   r   r   str__annotations__r%   addclassmethodr!   r(   r   r   r   r    r      s   
 

r   F)consider_tldrfc_1034rfc_2782valuer1   r2   r3   c            
   C   s   | sdS |rt | dddd  sdS z9|rdnd}|r#dnd}td	|  oPtd
| dd| d d| d d d|  | d	dtj
W S  tye } ztd|  |d}~ww )a#  Return whether or not given value is a valid domain.

    Examples:
        >>> domain('example.com')
        True
        >>> domain('example.com/')
        ValidationError(func=domain, args={'value': 'example.com/'})
        >>> # Supports IDN domains as well::
        >>> domain('xn----gtbspbbmkef.xn--p1ai')
        True

    Args:
        value:
            Domain string to validate.
        consider_tld:
            Restrict domain to TLDs allowed by IANA.
        rfc_1034:
            Allows optional trailing dot in the domain name.
            Ref: [RFC 1034](https://www.rfc-editor.org/rfc/rfc1034).
        rfc_2782:
            Domain name is of type service record.
            Allows optional underscores in the domain name.
            Ref: [RFC 2782](https://www.rfc-editor.org/rfc/rfc2782).


    Returns:
        (Literal[True]): If `value` is a valid domain name.
        (ValidationError): If `value` is an invalid domain name.

    Raises:
        (UnicodeError): If `value` cannot be encoded into `idna` or decoded into `utf-8`.
    F.r   r    z\.?$$z\s|__+z^(?:[a-z0-9]z(?:[a-z0-9-z]{0,61}z[a-z0-9z])?\.)z+[a-z0-9][a-z0-9-_]{0,61}z[a-z]idnazutf-8zUnable to encode/decode N)r   r(   rstriprsplitupperresearchmatchencodedecode
IGNORECASEUnicodeError)r4   r1   r2   r3   service_recordtrailing_doterrr   r   r    domain(   s0   $$


	rH   )r,   osr   pathlibr   r>   typingr   r   utilsr   r   r-   boolrH   r   r   r   r    <module>   s$    