o
    7Di                     @   sJ  d Z ddlmZ ddlZddlmZmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ ed	d
 Zedd ZdefddZdedefddZdefddZdededededededee dedefddZdeded ed!efd"d#Zed$d$d%d$d%d$dd$d$ed&
dededededed!ededee deded'eegef fd(d)ZdS )*zURL.    )	lru_cacheN)CallableOptional)parse_qsunquoteurlsplit   )hostname)	validatorc                   C      t dt jS )Nz(^[\u0100-\u017F\u0180-\u024F]|[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$|^([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\011.])*$)recompile
IGNORECASE r   r   G/var/www/Datamplify/venv/lib/python3.10/site-packages/validators/url.py_username_regex   s   r   c                   C   r   )Nz^[\/a-z0-9\-\.\_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\%\U0001F300-\U0001F5FF\U0001F600-\U0001F64F\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$r   r   r   r   r   _path_regex   s   r   valuec                 C   s   | r| dv S dS )zValidate scheme.>   ftpgitircsshftpshttprtmprtspsftphttpsrtmpstelnetFr   )r   r   r   r   _validate_scheme*   s   r!   skip_ipv6_addrc                 C   s   |p|  ddk p| d S )zConfirm skip IPv6 check.:   [)count
startswith)r   r"   r   r   r   _confirm_ipv6_skipD   s   r(   c                    sp   | sdS |  d }dkrt t| S |dk rt | S | dd\} t |o7t fdddD S )z Validate authentication segment.Tr#   r   c                 3   s    | ]}| vV  qd S )Nr   ).0char_to_avoidpasswordr   r   	<genexpr>T   s    
z)_validate_auth_segment.<locals>.<genexpr>)/?#@)r&   r   matchr   rsplitall)r   colon_countusernamer   r+   r   _validate_auth_segmentI   s   r7   skip_ipv4_addrmay_have_portsimple_hostconsider_tldprivaterfc_1034rfc_2782c	                 C   s   | r	|  ddkrdS |  ddk r5tt| |sd| v r| n	| ddddt| ||||||||d	S | dd\}	}
tt|
|sGd| v rI|
n	|
ddddt|
||||||||d	oct|	S )	zValidate netloc.r1   r   Fz]:r%   ] )r"   r8   r9   maybe_simpler;   r<   r=   r>   )r&   r	   r(   lstripreplacer3   r7   )r   r"   r8   r9   r:   r;   r<   r=   r>   
basic_authhostr   r   r   _validate_netlocY   sH   rF   pathqueryfragmentstrict_queryc                 C   s   d}| r|t t | M }z|r#t||ddr#t||ddr#|dM }W n ty9   |r7t||dr7|dM }Y nw |rH|t td|tjM }|S )z"Validate path query and fragments.T&)strict_parsing	separator;)rL   z[0-9a-z?/:@\-._~%!$&'()*+,;=#]*)boolr   r2   r   	TypeErrorr   	fullmatchr   )rG   rH   rI   rJ   optional_segmentsr   r   r   _validate_optionals   s,   rS   FT)
r"   r8   r9   r:   rJ   r;   r<   r=   r>   validate_schemerT   c      
      
   C   sn   | rt d| r
dS zt| \}}}}}W n
 ty   Y dS w |
|o6t|||||||||		o6t||||S )a  Return whether or not given value is a valid URL.

    This validator was originally inspired from [URL validator of dperini][1].
    The following diagram is from [urlly][2]::


            foo://admin:hunter1@example.com:8042/over/there?name=ferret#nose
            \_/   \___/ \_____/ \_________/ \__/\_________/ \_________/ \__/
             |      |       |       |        |       |          |         |
          scheme username password hostname port    path      query    fragment

    [1]: https://gist.github.com/dperini/729294
    [2]: https://github.com/treeform/urlly

    Examples:
        >>> url('http://duck.com')
        True
        >>> url('ftp://foobar.dk')
        True
        >>> url('http://10.0.0.1')
        True
        >>> url('http://example.com/">user@example.com')
        ValidationError(func=url, args={'value': 'http://example.com/">user@example.com'})

    Args:
        value:
            URL string to validate.
        skip_ipv6_addr:
            When URL string cannot contain an IPv6 address.
        skip_ipv4_addr:
            When URL string cannot contain an IPv4 address.
        may_have_port:
            URL string may contain port number.
        simple_host:
            URL string maybe only hyphens and alpha-numerals.
        strict_query:
            Fail validation on query string parsing error.
        consider_tld:
            Restrict domain to TLDs allowed by IANA.
        private:
            Embedded IP address is public if `False`, private/local if `True`.
        rfc_1034:
            Allow trailing dot in domain/host name.
            Ref: [RFC 1034](https://www.rfc-editor.org/rfc/rfc1034).
        rfc_2782:
            Domain/Host name is of type service record.
            Ref: [RFC 2782](https://www.rfc-editor.org/rfc/rfc2782).
        validate_scheme:
            Function that validates URL scheme.

    Returns:
        (Literal[True]): If `value` is a valid url.
        (ValidationError): If `value` is an invalid url.
    z\sF)r   searchr   
ValueErrorrF   rS   )r   r"   r8   r9   r:   rJ   r;   r<   r=   r>   rT   schemenetlocrG   rH   rI   r   r   r   url   s,   FrY   )__doc__	functoolsr   r   typingr   r   urllib.parser   r   r   r	   utilsr
   r   r   strr!   rO   r(   r7   rF   rS   rY   r   r   r   r   <module>   s    

	
0	
