o
    7D©iX  ã                   @   sÀ   d Z ddlmZ ddlZddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ed	d
„ ƒZedd„ ƒZdefdd„Zedddddddddœdededededededee dedefdd„ƒZdS )z	Hostname.é    )Ú	lru_cacheN)ÚOptionalé   )Údomain)Úipv4Úipv6)Ú	validatorc                   C   s
   t  d¡S )zPort validation regex.zZ^\:(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3})$)ÚreÚcompile© r   r   úL/var/www/Datamplify/venv/lib/python3.10/site-packages/validators/hostname.pyÚ_port_regex   s   ÿr   c                   C   s   t  dt j¡S )z!Simple hostname validation regex.z1^(?!-)[a-z0-9](?:[a-z0-9-]{0,59}[a-z0-9])?(?<!-)$)r	   r
   Ú
IGNORECASEr   r   r   r   Ú_simple_hostname_regex   s   r   Úvaluec                 C   sx   |   d¡dkr |  dd¡\}}tƒ  d|› ¡r | d¡ d¡S |   d¡dkr:|  dd¡\}}tƒ  d|› ¡r:|S dS )z&Returns host segment if port is valid.z]:r   ú:ú[ú]N)ÚcountÚrsplitr   ÚmatchÚlstripÚrstrip)r   Úhost_segÚport_segr   r   r   Ú_port_validator    s   r   FT)Úskip_ipv6_addrÚskip_ipv4_addrÚmay_have_portÚmaybe_simpleÚconsider_tldÚprivateÚrfc_1034Úrfc_2782r   r   r   r   r    r!   r"   r#   c         
      C   s´   | sdS |r3t | ƒ }	r3|rtƒ  |	¡ndp2t|	|||dp2|r"dnt|	d|dp2|r-dS t|	ddS |r;tƒ  | ¡ndpYt| |||dpY|rIdnt| d|dpY|rTdS t| ddS )a  Return whether or not given value is a valid hostname.

    Examples:
        >>> hostname("ubuntu-pc:443")
        True
        >>> hostname("this-pc")
        True
        >>> hostname("xn----gtbspbbmkef.xn--p1ai:65535")
        True
        >>> hostname("_example.com")
        ValidationError(func=hostname, args={'value': '_example.com'})
        >>> hostname("123.5.77.88:31000")
        True
        >>> hostname("12.12.12.12")
        True
        >>> hostname("[::1]:22")
        True
        >>> hostname("dead:beef:0:0:0:0000:42:1")
        True
        >>> hostname("[0:0:0:0:0:ffff:1.2.3.4]:-65538")
        ValidationError(func=hostname, args={'value': '[0:0:0:0:0:ffff:1.2.3.4]:-65538'})
        >>> hostname("[0:&:b:c:@:e:f::]:9999")
        ValidationError(func=hostname, args={'value': '[0:&:b:c:@:e:f::]:9999'})

    Args:
        value:
            Hostname string to validate.
        skip_ipv6_addr:
            When hostname string cannot be an IPv6 address.
        skip_ipv4_addr:
            When hostname string cannot be an IPv4 address.
        may_have_port:
            Hostname string may contain port number.
        maybe_simple:
            Hostname string maybe only hyphens and alpha-numerals.
        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).

    Returns:
        (Literal[True]): If `value` is a valid hostname.
        (ValidationError): If `value` is an invalid hostname.
    F)r    r"   r#   )Úcidrr!   )r$   )r   r   r   r   r   r   )
r   r   r   r   r   r    r!   r"   r#   r   r   r   r   Úhostname1   s*   @ÿþü
üÿþü
ür%   )Ú__doc__Ú	functoolsr   r	   Útypingr   r   Ú
ip_addressr   r   Úutilsr   r   r   Ústrr   Úboolr%   r   r   r   r   Ú<module>   sP    

õÿüûúùø	÷
öõ