
    Mh                     4    d dl Z d dlmZ  G d d          ZdS )    N)cached_propertyc                       e Zd ZdZdZdZd Zd Zed             Z	e
d             Zed             Ze
d	             Ze
d
             Ze
d             Ze
d             Zd Z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                    |rt          d          t          |                                          ddhz
  }|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_kwargss        M/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/fqdn/__init__.py__init__zFQDN.__init__$   s     	KIJJJV[[]]++/BL.QQ 	L3::>JJKKK 	1D#.. 	1/000ZZ\\
"(**-@%"H"H!::lA66    c                     | j         S )7
        The FQDN as a string in absolute form
        )absoluter   s    r   __str__zFQDN.__str__1   s     }r   c                 ~    | j         st          j        nt          j        }t	          j        |t          j                  S N)r   r   PREFERRED_NAME_SYNTAX_REGEXSTRALLOW_UNDERSCORES_REGEXSTRrecompile
IGNORECASE)r   regexstrs     r   _regexzFQDN._regex7   s8     *1D//0 	
 z(BM222r   c                     t          | j                  }| j                            d          r|dz  }|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_passs      r   is_validzFQDN.is_valid@   su     TZ:s## 	aKFC<<5[&&tz22
 	5 D$444r   c                 j    | j         d         dk    }| j                             d          |rdndz   }|S )Nr,   r   r-   )r   count)r   has_terminal_dotr8   s      r   r2   zFQDN.labels_countY   s<    :b>S0
  %%.>)EAFr   c                 D    | 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   r0   r5   r    s    r   is_valid_absolutezFQDN.is_valid_absolute_   s!     z""3''9DM9r   c                 F    | 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,   r;   r    s    r   is_valid_relativezFQDN.is_valid_relativej   s$     :&&s+++==r   c                     | j         s't          d                    | j                            | j        r| j        S d                    | j                  S )r   invalid FQDN `{0}`z{0}.r5   r
   r   r   r<   r    s    r   r   zFQDN.absoluter   sU    
 } 	F188DDEEE! 	:}}TZ(((r   c                     | j         s't          d                    | j                            | j        r| j        dd         S | j        S )z7
        The FQDN as a string in relative form
        r@   Nr7   rA   r    s    r   relativezFQDN.relative   sQ    
 } 	F188DDEEE! 	#:crc?"zr   c                 P    t          |t                    r| j        |j        k    S d S r#   )r   r   r   )r   others     r   __eq__zFQDN.__eq__   s-    eT"" 	3=EN22	3 	3r   c                 J    t          | j                  t          d          z   S )Nr   )hashr   r    s    r   __hash__zFQDN.__hash__   s    DM""T&\\11r   N)__name__
__module____qualname____doc__r$   r%   r   r!   propertyr*   r   r5   r2   r<   r>   r   rC   rF   rI    r   r   r   r      s-        . 	L # 	N 7 7 7   3 3 X3 5 5 _50   X
 : : _: > > _> 
) 
) _
) 
 
 _
3 3 32 2 2 2 2r   r   )r&   fqdn._compatr   r   rO   r   r   <module>rQ      s\    				 ( ( ( ( ( (K2 K2 K2 K2 K2 K2 K2 K2 K2 K2r   