o
    ¹i³  ã                   @   s&   d dl Z d dlmZ G dd„ dƒZdS )é    N)Úcached_propertyc                   @   sŒ   e Zd ZdZdZdZdd„ Zdd„ Zedd	„ ƒZ	e
d
d„ ƒZedd„ ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZdd„ Zdd„ ZdS )ÚFQDNaË  
    From https://tools.ietf.org/html/rfc1035#page-9,  RFC 1035 3.1. Name space
    definitions:

        Domain names in messages are expressed in terms of a sequence of
        labels. Each label is represented as a one octet length field followed
        by that number of octets.  Since every domain name ends with the null
        label of the root, a domain name is terminated by a length byte of
        zero.  The high order two bits of every length octet must be zero, and
        the remaining six bits of the length field limit the label to 63 octets
        or less.

        To simplify implementations, the total length of a domain name (i.e.,
        label octets and label length octets) is restricted to 255 octets or
        less.


    Therefore the max length of a domain name is actually 253 ASCII bytes
    without the trailing null byte or the leading length byte, and the max
    length of a label is 63 bytes without the leading length byte.
    z@^((?![-])[-A-Z\d]{1,63}(?<!-)[.])*(?!-)[-A-Z\d]{1,63}(?<!-)[.]?$zB^((?![-])[-_A-Z\d]{1,63}(?<!-)[.])*(?!-)[-_A-Z\d]{1,63}(?<!-)[.]?$c                 O   sr   |rt dƒ‚t| ¡ ƒddh }|rt d |¡ƒ‚|r t|tƒs$t dƒ‚| ¡ | _| dd¡| _	| dd¡| _
d S )Nz*got extra positional parameter, try kwargsÚallow_underscoresÚ
min_labelszgot extra kwargs: {}zfqdn must be strFé   )Ú
ValueErrorÚsetÚkeysÚformatÚ
isinstanceÚstrÚlowerÚ_fqdnÚgetÚ_allow_underscoresÚ_min_labels)ÚselfÚfqdnÚnothingÚkwargsÚunknown_kwargs© r   úH/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/fqdn/__init__.pyÚ__init__$   s   
zFQDN.__init__c                 C   s   | j S )ú7
        The FQDN as a string in absolute form
        )Úabsolute©r   r   r   r   Ú__str__1   s   zFQDN.__str__c                 C   s    | j stjntj}t |tj¡S ©N)r   r   ÚPREFERRED_NAME_SYNTAX_REGEXSTRÚALLOW_UNDERSCORES_REGEXSTRÚreÚcompileÚ
IGNORECASE)r   Úregexstrr   r   r   Ú_regex7   s
   ÿýzFQDN._regexc                 C   sL   t | jƒ}| j d¡r|d8 }|dkrdS | j | j¡}|s dS | j| jkS )aï  
        True for a validated fully-qualified domain nam (FQDN), in full
        compliance with RFC 1035, and the "preferred form" specified in RFC
        3686 s. 2, whether relative or absolute.

        https://tools.ietf.org/html/rfc3696#section-2
        https://tools.ietf.org/html/rfc1035

        If and only if the FQDN ends with a dot (in place of the RFC1035
        trailing null byte), it may have a total length of 254 bytes, still it
        must be less than 253 bytes.
        Ú.é   éý   F)Úlenr   Úendswithr%   ÚmatchÚlabels_countr   )r   ÚlengthÚ
regex_passr   r   r   Úis_valid@   s   
zFQDN.is_validc                 C   s0   | j d dk}| j  d¡|rd }|S d }|S )Néÿÿÿÿr&   r   r'   )r   Úcount)r   Úhas_terminal_dotr1   r   r   r   r,   Y   s
   ÿzFQDN.labels_countc                 C   s   | j  d¡o| jS )z÷
        True for a fully-qualified domain name (FQDN) that is RFC
        preferred-form compliant and ends with a `.`.

        With relative FQDNS in DNS lookups, the current hosts domain name or
        search domains may be appended.
        r&   ©r   r*   r/   r   r   r   r   Úis_valid_absolute_   s   	zFQDN.is_valid_absolutec                 C   s   | j  d¡ o	| jS )z’
        True for a validated fully-qualified domain name that compiles with the
        RFC preferred-form and does not ends with a `.`.
        r&   r3   r   r   r   r   Úis_valid_relativej   s   zFQDN.is_valid_relativec                 C   s.   | j std | j¡ƒ‚| jr| jS d | j¡S )r   úinvalid FQDN `{0}`z{0}.©r/   r   r
   r   r4   r   r   r   r   r   r   s
   zFQDN.absolutec                 C   s0   | j std | j¡ƒ‚| jr| jdd… S | jS )z7
        The FQDN as a string in relative form
        r6   Nr0   r7   r   r   r   r   Úrelative   s
   zFQDN.relativec                 C   s   t |tƒr| j|jkS d S r   )r   r   r   )r   Úotherr   r   r   Ú__eq__Œ   s   
ÿzFQDN.__eq__c                 C   s   t | jƒt dƒ S )Nr   )Úhashr   r   r   r   r   Ú__hash__   s   zFQDN.__hash__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r   r   Úpropertyr%   r   r/   r,   r4   r5   r   r8   r:   r<   r   r   r   r   r      s0    ÿÿ







r   )r!   Úfqdn._compatr   r   r   r   r   r   Ú<module>   s    