o
    Õ­jOZ  ã                   @   sê  d dl Z d dlZd dlZd dlZd dlmZmZ ddlmZ ddl	m
Z
 dZdZe d¡Zed	d
hƒZeh d£ƒZeh d£ƒZeh d£ƒZeddhƒZeh d£ƒZeddhƒZeedƒedƒhƒZeed	ƒedƒhƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdedefdd„Z de!de!de"fd d!„Z#d"e!de$fd#d$„Z%d"ede!fd%d&„Z&d'ee$e!f de"fd(d)„Z'd*ee$e!f d+e"de"fd,d-„Z(dOd'e!d/e"de"fd0d1„Z)d'e!de"fd2d3„Z*d'e!de"fd4d5„Z+d'e!ddfd6d7„Z,d'e!d8ede"fd9d:„Z-dOd'e!d8ed;e"de"fd<d=„Z.d'ee!e$e/f ddfd>d?„Z0d'e!de$fd@dA„Z1d'ee!e$e/f de!fdBdC„Z2dPd*e!dEe"dFe"de!fdGdH„Z3	.	.	.	.dQd"ee!e$e/f dIe"dJe"dEe"dFe"de$fdKdL„Z4	.	.	.dRd"ee!e$e/f dIe"dJe"dEe"de!f
dMdN„Z5dS )Sé    N)ÚOptionalÚUnioné   )Úidnadata)Úintranges_containé	   s   xn--u   [.ã€‚ï¼Žï½¡]ÚRÚAL>   r   r	   ÚAN>
   r   r	   r
   ÚBNÚCSÚENÚESÚETÚONÚNSM>   r   r	   r
   r   r
   r   >   ÚLr   r   r   r   r   r   r   r   ÚDc                   @   ó   e Zd ZdZdS )Ú	IDNAErrorz5Base exception for all IDNA-encoding related problemsN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úF/var/www/html/CropPilot/venv/lib/python3.10/site-packages/idna/core.pyr      ó    r   c                   @   r   )ÚIDNABidiErrorz;Exception when bidirectional requirements are not satisfiedNr   r   r   r   r   r   !   r   r   c                   @   r   )ÚInvalidCodepointz<Exception when a disallowed or unallocated codepoint is usedNr   r   r   r   r   r   '   r   r   c                   @   r   )ÚInvalidCodepointContextzCException when the codepoint is not valid in the context it is usedNr   r   r   r   r   r    -   r   r    ÚcpÚreturnc                 C   s0   t  t| ƒ¡}|dkrt  t| ƒ¡stdƒ‚|S )Nr   z Unknown character in unicodedata)ÚunicodedataÚ	combiningÚchrÚnameÚ
ValueError)r!   Úvr   r   r   Ú_combining_class3   s   r)   Úscriptc                 C   s   t t| ƒtj| ƒS )N)r   Úordr   Úscripts)r!   r*   r   r   r   Ú
_is_script:   s   r-   Úsc                 C   s
   |   d¡S )NÚpunycode)Úencode©r.   r   r   r   Ú	_punycode>   s   
r2   c                 C   s   d| d›�S )NzU+Ú04Xr   r1   r   r   r   Ú_unotB   s   r4   Úlabelc                 C   s   t | ƒdkS )uÍ  Check that a label does not exceed the maximum permitted length.

    Per :rfc:`1035` (and :rfc:`5891` Â§4.2.4) a DNS label must not exceed
    63 octets. The argument may be either a :class:`str` (a U-label, where
    length is measured in characters) or :class:`bytes` (an A-label, where
    length is measured in octets).

    :param label: The label to check.
    :returns: ``True`` if the label is within the length limit, otherwise
        ``False``.
    é?   ©Úlen©r5   r   r   r   Úvalid_label_lengthF   s   r:   ÚdomainÚtrailing_dotc                 C   s   t | ƒ|rdkS dkS )a¶  Check that a full domain name does not exceed the maximum length.

    Per :rfc:`1035`, a domain name is limited to 253 octets when no trailing
    dot is present, or 254 octets when one is included.

    :param domain: The full (possibly multi-label) domain name.
    :param trailing_dot: ``True`` if ``domain`` includes a trailing ``.``.
    :returns: ``True`` if the domain is within the length limit, otherwise
        ``False``.
    éþ   éý   r7   )r;   r<   r   r   r   Úvalid_string_lengthU   s   r?   FÚ	check_ltrc           	      C   sZ  d}t | dƒD ]\}}t |¡}|dkr tdt| ƒ› d|› �ƒ‚|tv r&d}q|s-|s-dS t | d ¡}|tv r;d}n|dkrBd}n
td	t| ƒ› d
�ƒ‚d}d}t | dƒD ]O\}}t |¡}|r‹|tvrltd|› d�ƒ‚|tv rsd}n|dkryd}|t	v rŠ|s‚|}qU||krŠtdƒ‚qU|t
vr—td|› d�ƒ‚|tv ržd}qU|dkr¤d}qU|s«tdƒ‚dS )a!  Validate the Bidi Rule from :rfc:`5893` for a single label.

    The Bidi Rule constrains how bidirectional characters (Hebrew, Arabic,
    etc.) may appear within a label. By default the check is only applied
    when the label contains at least one right-to-left character (Unicode
    bidirectional categories ``R``, ``AL``, or ``AN``); set ``check_ltr``
    to ``True`` to apply it to LTR-only labels as well.

    :param label: The label to validate, as a Unicode string.
    :param check_ltr: If ``True``, apply the rules even when the label
        contains no RTL characters.
    :returns: ``True`` if the label satisfies the Bidi Rule.
    :raises IDNABidiError: If any of Bidi Rule conditions 1-6 are violated,
        or if the directional category of a codepoint cannot be determined.
    Fr   Ú z Unknown directionality in label ú at position Tr   r   zFirst codepoint in label z" must be directionality L, R or ALNz,Invalid direction for codepoint at position z in a right-to-left labelr   z2Can not mix numeral types in a right-to-left labelz in a left-to-right labelz0Label ends with illegal codepoint directionality)Ú	enumerater#   Úbidirectionalr   ÚreprÚ_bidi_rtl_categoriesÚ_bidi_rtl_firstÚ_bidi_rtl_allowedÚ_bidi_rtl_valid_endingÚ_bidi_rtl_numericÚ_bidi_ltr_allowedÚ_bidi_ltr_valid_ending)	r5   r@   Ú
bidi_labelÚidxr!   Ú	directionÚrtlÚvalid_endingÚnumber_typer   r   r   Ú
check_bidic   sV   
€
€€rS   c                 C   s"   t  | d ¡d dkrtdƒ‚dS )u^  Reject labels that begin with a combining mark.

    Per :rfc:`5891` Â§4.2.3.2 a label must not start with a character of
    Unicode general category ``M`` (Mark).

    :param label: The label to check.
    :returns: ``True`` if the first character is not a combining mark.
    :raises IDNAError: If the label begins with a combining character.
    r   ÚMz0Label begins with an illegal combining characterT)r#   Úcategoryr   r9   r   r   r   Úcheck_initial_combiner­   s   
rV   c                 C   s<   | dd… dkrt dƒ‚| d dks| d dkrt dƒ‚d	S )
u§  Validate the hyphen restrictions for a label.

    Per :rfc:`5891` Â§4.2.3.1 a label must not start or end with a hyphen
    (``U+002D``), and must not have hyphens in both the third and fourth
    positions (the prefix reserved for A-labels).

    :param label: The label to check.
    :returns: ``True`` if the hyphen restrictions are satisfied.
    :raises IDNAError: If any of the hyphen restrictions are violated.
    é   é   z--z4Label has disallowed hyphens in 3rd and 4th positionr   ú-éÿÿÿÿz)Label must not start or end with a hyphenT)r   r9   r   r   r   Úcheck_hyphen_ok¼   s
   r[   c                 C   s   t  d| ¡| krtdƒ‚dS )z¬Require that a label is in Unicode Normalization Form C.

    :param label: The label to check.
    :raises IDNAError: If ``label`` differs from its NFC normalisation.
    ÚNFCz%Label must be in Normalization Form CN)r#   Ú	normalizer   r9   r   r   r   Ú	check_nfcÎ   s   ÿr^   Úposc                 C   s  t | | ƒ}|dkrt|dkrtt | |d  ƒƒtkrdS d}t|d ddƒD ]}t ¡  t | | ƒ¡}|t dƒkr:q&|tv rBd} n |sGdS d}t|d t| ƒƒD ]}t ¡  t | | ƒ¡}|t dƒkrfqR|t	v rod} |S  |S |S |dkrˆ|dko‡tt | |d  ƒƒtkS dS )	aŸ  Validate the CONTEXTJ rules from :rfc:`5892` Appendix A.

    These rules govern the contextual use of the joiner codepoints
    ``U+200C`` (ZERO WIDTH NON-JOINER, Appendix A.1) and ``U+200D``
    (ZERO WIDTH JOINER, Appendix A.2) within a label.

    :param label: The label containing the codepoint.
    :param pos: Index of the joiner codepoint within ``label``.
    :returns: ``True`` if the codepoint at ``pos`` satisfies its CONTEXTJ
        rule, ``False`` otherwise (including when the codepoint at
        ``pos`` is not a recognised joiner).
    :raises ValueError: If an adjacent codepoint has no Unicode name when
        determining its combining class.
    i   r   r   TFrZ   ÚTi   )
r+   r)   Ú_virama_combining_classÚranger   Újoining_typesÚgetÚ_bidi_joiner_l_or_dr8   Ú_bidi_joiner_r_or_d)r5   r_   Úcp_valueÚokÚiÚjoining_typer   r   r   Úvalid_contextjØ   s:    ÿ rk   Ú	exceptionc                 C   sf  t | | ƒ}|dkr.d|  k ot| ƒd k n  o-t | |d  ƒdko-t | |d  ƒdkS |dkrK|t| ƒd k rIt| ƒdkrIt| |d  dƒS dS |dksS|d	krb|dkr`t| |d  d
ƒS dS |dkr„| D ]}|dkroqht|dƒs~t|dƒs~t|dƒr� dS qhdS d|  krŽdkršn n
tdd„ | D ƒƒ S d|  kr¤dkr±n dS tdd„ | D ƒƒ S dS )a‹  Validate the CONTEXTO rules from :rfc:`5892` Appendix A.

    Covers the contextual rules for codepoints such as MIDDLE DOT
    (``U+00B7``), Greek lower numeral sign, Hebrew punctuation, Katakana
    middle dot, and the Arabic-Indic / Extended Arabic-Indic digit ranges.

    :param label: The label containing the codepoint.
    :param pos: Index of the codepoint within ``label``.
    :param exception: Reserved for forward compatibility; currently unused.
    :returns: ``True`` if the codepoint at ``pos`` satisfies its CONTEXTO
        rule, ``False`` otherwise (including when the codepoint is not a
        recognised CONTEXTO codepoint).
    é·   r   r   él   iu  ÚGreekFió  iô  ÚHebrewiû0  u   ãƒ»ÚHiraganaÚKatakanaÚHanTé`  éi  c                 s   ó,   � | ]}d t |ƒ  kodkn  V  qdS )éð  éù  N©r+   ©Ú.0r!   r   r   r   Ú	<genexpr>4  ó   €* z!valid_contexto.<locals>.<genexpr>rw   rx   c                 s   rv   )rt   ru   Nry   rz   r   r   r   r|   7  r}   )r+   r8   r-   Úany)r5   r_   rl   rg   r!   r   r   r   Úvalid_contexto  s2   Hÿþr   c                 C   s~  t | ttfƒr|  d¡} t| ƒdkrtdƒ‚t| dd�s tdƒ‚t| ƒ t| ƒ t	| ƒ t
| ƒD ]ˆ\}}t|ƒ}t|tjd ƒrAq0t|tjd ƒr„zt| |ƒsbtd	t|ƒ› d
|d › dt| ƒ› �ƒ‚W q0 tyƒ } ztdt|ƒ› d|d › dt| ƒ› �ƒ|‚d}~ww t|tjd ƒr¥t| |ƒs¤tdt|ƒ› d
|d › dt| ƒ› �ƒ‚q0tdt|ƒ› d|d › dt| ƒ› d�ƒ‚t| ƒ dS )a8  Run the full set of IDNA 2008 validity checks on a single label.

    Applies, in order: NFC normalisation (:func:`check_nfc`), hyphen
    restrictions (:func:`check_hyphen_ok`), the no-leading-combiner rule
    (:func:`check_initial_combiner`), per-codepoint validity (PVALID,
    CONTEXTJ, CONTEXTO classes from :rfc:`5892`), and the Bidi Rule
    (:func:`check_bidi`).

    :param label: The label to validate. ``bytes`` or ``bytearray`` input
        is decoded as UTF-8 first.
    :raises IDNAError: If the label is empty or fails a structural rule.
    :raises InvalidCodepoint: If the label contains a DISALLOWED or
        UNASSIGNED codepoint.
    :raises InvalidCodepointContext: If a CONTEXTJ or CONTEXTO codepoint
        is not valid in its context.
    :raises IDNABidiError: If the Bidi Rule is violated.
    zutf-8r   zEmpty LabelT©r<   úLabel too longÚPVALIDÚCONTEXTJzJoiner ú not allowed at position r   ú in z%Unknown codepoint adjacent to joiner rB   NÚCONTEXTOú
Codepoint z of z not allowed)Ú
isinstanceÚbytesÚ	bytearrayÚdecoder8   r   r?   r^   r[   rV   rC   r+   r   r   Úcodepoint_classesrk   r    r4   rE   r'   r   r   rS   )r5   r_   r!   rg   Úerrr   r   r   Úcheck_label<  sH   

 ÿÿ ÿþ€ÿ
 ÿÿ(rŽ   c                 C   sd   z|   d¡}t|ƒ t|ƒstdƒ‚|W S  ty   Y nw t| ƒ tt| ƒ }t|ƒs0tdƒ‚|S )u  Convert a single U-label into its A-label form.

    The result is the ASCII-Compatible Encoding (ACE) form per :rfc:`5891`
    Â§4: the label is validated, Punycode-encoded, and prefixed with
    ``xn--``. Pure ASCII labels that are already valid IDNA labels are
    returned unchanged (as :class:`bytes`).

    :param label: The label to convert, as a Unicode string.
    :returns: The A-label as ASCII-encoded :class:`bytes`.
    :raises IDNAError: If the label is invalid or the resulting A-label
        exceeds 63 octets.
    Úasciir�   )r0   Úulabelr:   r   ÚUnicodeEncodeErrorrŽ   Ú_alabel_prefixr2   )r5   Úlabel_bytesr   r   r   Úalabelu  s   
ÿr”   c              
   C   sÖ   t | ttfƒsz|  d¡}W n ty   t| ƒ |  Y S w t| ƒ}| ¡ }| t¡rC|t	tƒd… }|s9t
dƒ‚| d¡rBt
dƒ‚n	t|ƒ | d¡S z| d¡} W n tyd } zt
dƒ|‚d}~ww t| ƒ | S )aÿ  Convert a single A-label into its U-label form.

    Performs the inverse of :func:`alabel`: an ``xn--``-prefixed label is
    Punycode-decoded and validated. Labels that are already Unicode (or
    plain ASCII without the ACE prefix) are validated and returned as a
    Unicode string.

    :param label: The label to convert. ``bytes`` or ``bytearray`` input
        is treated as ASCII.
    :returns: The U-label as a Unicode string.
    :raises IDNAError: If the label is malformed or fails validation.
    r�   Nz5Malformed A-label, no Punycode eligible content foundó   -z"A-label must not end with a hyphenr/   zInvalid A-label)rˆ   r‰   rŠ   r0   r‘   rŽ   ÚlowerÚ
startswithr’   r8   r   Úendswithr‹   ÚUnicodeError)r5   r“   r�   r   r   r   r�   ”  s4   þ

ÿ

€ÿr�   TÚ
std3_rulesÚtransitionalc              	   C   s&  ddl m } d}t| ƒD ]€\}}t|ƒ}||dk r|n	t ||df¡d  }|d }	d}
t|ƒdkr6|d }
|	d	kpK|	d
krA| pK|	dkoK| oK|
du }|
duo`|	dkp`|	dkr[| p`|	d
ko`|}|rh||7 }q|ru|
duspJ ‚||
7 }q|	dkrzqtdt|ƒ› d|d › dt| ƒ› �ƒ‚t	 
d|¡S )u®  Apply the UTS #46 character mapping to a domain string.

    Implements the mapping table from `UTS #46 Â§4
    <https://www.unicode.org/reports/tr46/>`_: each character is kept,
    replaced, or rejected based on its status (``V``, ``M``, ``D``, ``3``,
    ``I``). The result is returned in Normalisation Form C.

    :param domain: The full domain name to remap.
    :param std3_rules: If ``True``, apply the stricter STD3 ASCII rules
        (status ``3`` codepoints raise instead of being kept or mapped).
    :param transitional: If ``True``, use transitional processing (status
        ``D`` codepoints are mapped instead of kept). Transitional
        processing has been removed from UTS #46 and this option is
        retained only for backwards compatibility.
    :returns: The remapped domain, in Normalisation Form C.
    :raises InvalidCodepoint: If the domain contains a disallowed
        codepoint under the chosen rules.
    r   )Ú	uts46datarA   é   ÚZNé   rW   ÚVr   Ú3rT   ÚIr‡   r„   r…   r\   )rœ   rC   r+   ÚbisectÚbisect_leftr8   r   r4   rE   r#   r]   )r;   rš   r›   rœ   Úoutputr_   ÚcharÚ
code_pointÚuts46rowÚstatusÚreplacementÚ
keep_as_isÚuse_replacementr   r   r   Úuts46_remap½  s.   $*ÿ ÿ

&r­   ÚstrictÚuts46c           
   
   C   s  |r
t jdtdd� t| tƒs*zt| dƒ} W n ttfy) } ztdƒ|‚d}~ww |r2t| ||ƒ} t	| dd�s<td	ƒ‚d
}g }|rG|  
d¡nt 
| ¡}|rS|dgkrWtdƒ‚|d dkrb|d= d}|D ]}	t|	ƒ} | rr| | ¡ qdtdƒ‚|r}| d¡ d |¡} t	| |ƒs‹td	ƒ‚| S )aA  Encode a Unicode domain name into its ASCII (A-label) form.

    Splits the input on label separators (only ``U+002E`` if ``strict`` is
    set; otherwise also IDEOGRAPHIC FULL STOP ``U+3002``, FULLWIDTH FULL
    STOP ``U+FF0E``, and HALFWIDTH IDEOGRAPHIC FULL STOP ``U+FF61``),
    encodes each label with :func:`alabel`, and rejoins them with ``.``.
    Optionally pre-processes the input through :func:`uts46_remap`.

    :param s: The domain name to encode.
    :param strict: If ``True``, only ``U+002E`` is recognised as a label
        separator.
    :param uts46: If ``True``, apply UTS #46 mapping before encoding.
    :param std3_rules: Forwarded to :func:`uts46_remap` when ``uts46`` is
        ``True``.
    :param transitional: Forwarded to :func:`uts46_remap` when ``uts46``
        is ``True``. Deprecated: emits a :class:`DeprecationWarning` and
        will be removed in a future version.
    :returns: The encoded domain as ASCII :class:`bytes`.
    :raises IDNAError: If the domain is empty, contains an invalid label,
        or exceeds the maximum domain length.
    zuTransitional processing has been removed from UTS #46. The transitional argument will be removed in a future version.rW   )Ú
stacklevelr�   zGshould pass a unicode string to the function rather than a byte string.NTr€   úDomain too longFÚ.rA   úEmpty domainrZ   úEmpty labeló    ó   .)ÚwarningsÚwarnÚDeprecationWarningrˆ   ÚstrÚUnicodeDecodeErrorÚ	TypeErrorr   r­   r?   ÚsplitÚ_unicode_dots_rer”   ÚappendÚjoin)
r.   r®   r¯   rš   r›   r�   r<   ÚresultÚlabelsr5   r   r   r   r0   ô  sH   ü

€ÿ


r0   c           	   
   C   sì   t | tƒs zt| dƒ} W n ttfy } ztdƒ|‚d}~ww |r(t| |dƒ} t| dd�s2tdƒ‚d}g }|r=|  d¡nt | ¡}|rI|d	gkrMtd
ƒ‚|d sV|d= d}|D ]}t	|ƒ} | rf| 
| ¡ qXtdƒ‚|rq| 
d	¡ d |¡S )aà  Decode an A-label-encoded domain name back to Unicode.

    Splits the input on label separators (see :func:`encode` for the
    rules), decodes each label with :func:`ulabel`, and rejoins them
    with ``.``. Optionally pre-processes the input through
    :func:`uts46_remap`.

    :param s: The domain name to decode.
    :param strict: If ``True``, only ``U+002E`` is recognised as a label
        separator.
    :param uts46: If ``True``, apply UTS #46 mapping before decoding.
    :param std3_rules: Forwarded to :func:`uts46_remap` when ``uts46`` is
        ``True``.
    :returns: The decoded domain as a Unicode string.
    :raises IDNAError: If the input is not valid ASCII, contains an
        invalid label, or is empty.
    r�   zInvalid ASCII in A-labelNFTr€   r±   r²   rA   r³   rZ   r´   )rˆ   rº   r»   r¼   r   r­   r?   r½   r¾   r�   r¿   rÀ   )	r.   r®   r¯   rš   r�   r<   rÁ   rÂ   r5   r   r   r   r‹   :  s6   

€ÿ

r‹   )F)TF)FFFF)FFF)6r£   Úrer#   r·   Útypingr   r   rA   r   Ú	intrangesr   ra   r’   Úcompiler¾   Ú	frozensetrG   rF   rH   rI   rJ   rK   rL   r+   re   rf   r™   r   r   r   r    Úintr)   rº   Úboolr-   r‰   r2   r4   r:   r?   rS   rV   r[   r^   rk   r   rŠ   rŽ   r”   r�   r­   r0   r‹   r   r   r   r   Ú<module>   sŒ    
J
6.9)9ûÿþýüû
úHüÿþýüû