
    o-j]                        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dZ ej        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ddh          Z ed
dh          Zdedee         fdZ G d de          Z G d de          Z G d de          Z  G d de          Z!dedefdZ"ded ede#fd!Z$d"ede%fd#Z&d"edefd$Z'd%ee%ef         de#fd&Z(d'ee%ef         d(e#de#fd)Z)d?d%ed+e#de#fd,Z*d%ede#fd-Z+d%ede#fd.Z,d%eddfd/Z-d%ed0ede#fd1Z.d?d%ed0ed2e#de#fd3Z/d%eee%e0f         ddfd4Z1d%ede%fd5Z2d%eee%e0f         defd6Z3d@d'ed8e#d9e#defd:Z4	 	 	 	 dAd"eee%e0f         d;e#d<e#d8e#d9e#de%fd=Z5	 	 	 dBd"eee%e0f         d;e#d<e#d8e#def
d>Z6dS )C    N)OptionalUnion   )idnadata)intranges_contain	   s   xn--i   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   Dcpreturnc                 v    t           j                                        D ]\  }}t          | |          r|c S d S N)r   joining_typesitemsr   )r   jtrangess      I/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/idna/core.py_joining_typer      sI    ,2244  
FR(( 	III	4    c                       e Zd ZdZdS )	IDNAErrorz5Base exception for all IDNA-encoding related problemsN__name__
__module____qualname____doc__ r   r   r!   r!   #   s        ????r   r!   c                       e Zd ZdZdS )IDNABidiErrorz;Exception when bidirectional requirements are not satisfiedNr"   r'   r   r   r)   r)   '   s        EEEEr   r)   c                       e Zd ZdZdS )InvalidCodepointz<Exception when a disallowed or unallocated codepoint is usedNr"   r'   r   r   r+   r+   +   s        FFFFr   r+   c                       e Zd ZdZdS )InvalidCodepointContextzCException when the codepoint is not valid in the context it is usedNr"   r'   r   r   r-   r-   /   s        MMMMr   r-   c                     t          j        t          |                     }|dk    r0t          j        t          |                     st	          d          |S )Nr   z Unknown character in unicodedata)unicodedata	combiningchrname
ValueError)r   vs     r   _combining_classr5   3   sJ    c"gg&&AAvvk&s2ww//v;<<<Hr   scriptc                 \    t          t          |           t          j        |                   S r   )r   ordr   scripts)r   r6   s     r   
_is_scriptr:   :   s     SWWh&6v&>???r   sc                 ,    |                      d          S )Npunycode)encoder;   s    r   	_punycoder@   >   s    88Jr   c                     d| dS )NzU+04Xr'   r?   s    r   _unotrC   B   s    <<<r   labelc                 (    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rD   s    r   valid_label_lengthrJ   F   s     u::r   domaintrailing_dotc                 0    t          |           |rdn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``.
          rG   )rK   rL   s     r   valid_string_lengthrP   U   s     v;;,733C88r   F	check_ltrc                    t          |           t          k    rt          d          d}t          | d          D ]?\  }}t	          j        |          }|dk    rt          d| d|           |t          v rd}@|s|sdS t	          j        | d                   }|t          v rd}n|d	k    rd}nt          d
| d          d}d}t          | d          D ]\  }}t	          j        |          }|rT|t          vrt          d| d          |t          v rd}n|dk    rd}|t          v r|s|}Y||k    rt          d          o|t          vrt          d| d          |t          v rd}|dk    rd}|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.
    Label too longFr    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)rH   _max_input_lengthr!   	enumerater/   bidirectionalr)   _bidi_rtl_categories_bidi_rtl_first_bidi_rtl_allowed_bidi_rtl_valid_ending_bidi_rtl_numeric_bidi_ltr_allowed_bidi_ltr_valid_ending)	rD   rQ   
bidi_labelidxr   	directionrtlvalid_endingnumber_types	            r   
check_bidirf   c   s$     5zz%%%()))JUA&&  R-b11	?? ^5 ^ ^Y\ ^ ^___,,,J i t )%(33IO##	c		ccccdddL!%KUA&& % %R-b11	 	% 111#$qSV$q$q$qrrr222#e##$---" ^"+KK I--'(\]]]  111#$qSV$q$q$qrrr222#e##$ PNOOO4r   c                 l    t          j        | 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!   rI   s    r   check_initial_combinerrj      s7     E!H%%a(C//JKKK4r   c                     | 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!   rI   s    r   check_hyphen_okrp      sU     QqSzTNOOOQx3%)s**CDDD4r   c                     t          |           t          k    rt          d          t          j        d|           | k    rt          d          dS )zRequire that a label is in Unicode Normalization Form C.

    :param label: The label to check.
    :raises IDNAError: If ``label`` differs from its NFC normalisation.
    rS   NFCz%Label must be in Normalization Form CN)rH   rV   r!   r/   	normalizerI   s    r   	check_nfcrt      sT     5zz%%%()))UE**e33?@@@ 43r   posc                    t          |           t          k    rt          d          t          | |                   }|dk    r|dk    r0t	          t          | |dz
                               t
          k    rdS d}t          |dz
  dd          D ]8}t          t          | |                             }|dk    r+|t          v rd} n |sdS d}t          |dz   t          |                     D ]8}t          t          | |                             }|dk    r+|t          v rd} n |S |d	k    r4|dk    o-t	          t          | |dz
                               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.
    :raises IDNAError: If ``label`` exceeds the defensive input length limit.
    rS   i   r   r   TFro   Ti   )
rH   rV   r!   r8   r5   _virama_combining_classranger   _bidi_joiner_l_or_d_bidi_joiner_r_or_d)rD   ru   cp_valueokijoining_types         r   valid_contextjr      s     5zz%%%()))5:H677'E#'N(;(;<<@WWW4sQwB'' 	 	A(U1X77Ls""222 	5sQwE

++ 	 	A(U1X77Ls""222	6Qw[+CcAg,?,?@@D[[[5r   	exceptionc                 N   t          |           t          k    rt          d          t          | |                   }|dk    rXd|cxk     ot          |           dz
  k     nc o7t          | |dz
                     dk    ot          | |dz                      dk    S |dk    rD|t          |           dz
  k     r,t          |           dk    rt	          | |dz            d          S dS |d	v r!|dk    rt	          | |dz
           d
          S dS |dk    rA| D ]<}|dk    r	t	          |d          s t	          |d          st	          |d          r dS =dS d|cxk    rdk    rn nt          d | D                        S d|cxk    rdk    rn nt          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).
    :raises IDNAError: If ``label`` exceeds the defensive input length limit.
    rS      r   r   l   iu  GreekF>       Hebrewi0  u   ・HiraganaKatakanaHanT`  i  c              3   P   K   | ]!}d t          |          cxk    odk    nc V  "dS )    Nr8   .0r   s     r   	<genexpr>z!valid_contexto.<locals>.<genexpr>:  D      BBbuB111161111BBBBBBr   r   r   c              3   P   K   | ]!}d t          |          cxk    odk    nc V  "dS )r   r   Nr   r   s     r   r   z!valid_contexto.<locals>.<genexpr>=  r   r   )rH   rV   r!   r8   r:   any)rD   ru   r   r|   r   s        r   valid_contextor     s    5zz%%%()))5:H63''''Ua''''kCcAg,?,?6,IkcRWX[^_X_R`NaNaekNkk6UaCJJNNeC!Gng666u###77eC!Gnh777u6 	 	BX~~"j)) ZJ-G-G :VXZ_K`K` ttu!!!!E!!!!!BBEBBBBBBB!!!!E!!!!!BBEBBBBBBB5r   c           
      l   t          |           t          k    rt          d          t          | t          t
          f          r|                     d          } t          |           dk    rt          d          t          | d          st          d          t          |            t          |            t          |            t          |           D ]L\  }}t          |          }t          |t          j        d                   r6t          |t          j        d                   ru	 t!          | |          s(t#          d	t%          |           d
|dz    d|           # t&          $ r.}t          dt%          |           d|dz    d|           |d}~ww xY wt          |t          j        d                   r:t)          | |          s(t#          dt%          |           d
|dz    d|           %t+          dt%          |           d|dz    d| 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.
    rS   zutf-8r   zEmpty LabelTrL   PVALIDCONTEXTJzJoiner  not allowed at position r    in z%Unknown codepoint adjacent to joiner rU   NCONTEXTO
Codepoint z of z not allowed)rH   rV   r!   
isinstancebytes	bytearraydecoderP   rt   rp   rj   rW   r8   r   r   codepoint_classesr   r-   rC   r3   r   r+   rf   )rD   ru   r   r|   errs        r   check_labelr   B  s   $ 5zz%%%()))%%+,, &W%%
5zzQ&&& u4888 *()))eE5!!!U## r rRr77Xx'A('KLL 	Xx'A*'MNN 	r%eS11 ~12|E(OO2|2|filmfm2|2|sx2|2|}}}~   pE(OOppZ]`aZappglpp  x)CJ)OPP 	r!%-- }-.{5??.{.{ehklel.{.{rw.{.{|||} ##ph#p#pcTUg#p#p[`#p#p#pqqqus   .8E''
F1)FFc                    t          |           t          k    rt          d          	 |                     d          }t	          |           t          |          st          d          |S # t          $ r Y nw xY wt          |            t          t          |           z   }t          |          st          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.
    rS   ascii)
rH   rV   r!   r>   ulabelrJ   UnicodeEncodeErrorr   _alabel_prefixr@   )rD   label_bytess     r   alabelr   y  s     5zz%%%()))ll7++ 	{!+.. 	.,---      9U#3#33Kk** *()))s   A- -
A:9A:c                    t          |           t          k    rt          d          t          | t          t
          f          s8	 |                     d          }n0# t          $ r t          |            | cY S w xY wt	          |           }|	                                }|
                    t                    rR|t          t                    d         }|st          d          |                    d          rt          d          n$t          |           |                    d          S 	 |                    d          } n"# t          $ r}t          d          |d}~ww xY 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.
    rS   r   Nz5Malformed A-label, no Punycode eligible content found   -z"A-label must not end with a hyphenr=   zInvalid A-label)rH   rV   r!   r   r   r   r>   r   r   lower
startswithr   endswithr   UnicodeError)rD   r   r   s      r   r   r     s    5zz%%%()))eeY/00 #	,,w//KK! 	 	 	LLL	 Ell##%%Kn-- +!#n"5"5"7"78 	USTTT%% 	B@AAA	B 	K   !!'***4"":.. 4 4 4)**34Ls*   A A98A90E 
E%E  E%T
std3_rulestransitionalc           	      F   t          |           t          k    rt          d          ddlm}m}m} d}t          |           D ]\  }}t          |          }	|	dk     r|	nt          j
        ||	          dz
  }
t          ||
                   }||
         }|dk    p|dk    r| p|dk    o| o|d	u }|d	uo|d
k    p|dk    r| p|dk    o|}|r||z  }|r
|J ||z  }|dk    rt          dt          |	           d|dz    d|           t          j        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.
    :raises IDNAError: If ``domain`` exceeds the defensive input length limit.
    Domain too longr   )uts46_replacementsuts46_startsuts46_statusesrT      Vr   3Nrh   Ir   r   r   rr   )rH   rV   r!   	uts46datar   r   r   rW   r8   bisectbisect_rightr1   r+   rC   r/   rs   )rK   r   r   r   r   r   outputru   char
code_pointr~   statusreplacement
keep_as_isuse_replacements                  r   uts46_remapr     s   ( 6{{&&&)***KKKKKKKKKKFv&& u u	TYY
$s**JJ0CLR\0]0]`a0a^A&''%7%:
 cMfm@L0@fPSmF~\fXfF~kvz~k~ 	
 &T1 
cMcfm>JcFcMDbVb 	  	udNFF 	u***k!FFs]]"#sj0A0A#s#s\_bc\c#s#sio#s#sttt ///r   strictuts46c                 \   |rt          j        dt          d           t          | t                    s;	 t	          | d          } n)# t
          t          f$ r}t          d          |d}~ww xY wt          |           t          k    rt          d          |rt          | ||          } t          | d	          st          d          d
}g }|r|                     d          nt                              |           }|r|dgk    rt          d          |d         dk    r|d= d}|D ]7}	t          |	          } | r|                    |            )t          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.rl   )
stacklevelr   zGshould pass a unicode string to the function rather than a byte string.Nr   Tr   F.rT   Empty domainro   Empty labelr      .)warningswarnDeprecationWarningr   strUnicodeDecodeError	TypeErrorr!   rH   rV   r   rP   split_unicode_dots_rer   appendjoin)
r;   r   r   r   r   r   rL   resultlabelsrD   s
             r   r>   r>     s   8  
M		
 	
 	
 	
 a p	pAwAA"I. 	p 	p 	peffloo	p
1vv!!!)*** 5:|44 qt444 +)***LF#BQWWS\\\)9)?)?)B)BF (Vt^^'''bzR2J + +5MM 	+MM!M*** c		&Aq,// +)***Hs   A A,A''A,c                    t          | t                    s;	 t          | d          } n)# t          t          f$ r}t	          d          |d}~ww xY wt          |           t          k    rt	          d          |rt          | |d          } t          | d          st	          d          d}g }|r| 	                    d          nt          	                    |           }|r|d	gk    rt	          d
          |d         s|d= d}|D ]7}t          |          } | r|                    |            )t	          d          |r|                    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-labelNr   FTr   r   rT   r   ro   r   )r   r   r   r   r!   rH   rV   r   rP   r   r   r   r   r   )	r;   r   r   r   r   rL   r   r   rD   s	            r   r   r   F  s   . a A	AAwAA"I. 	A 	A 	A677S@	A
1vv!!!)*** .:u-- qt444 +)***LF#BQWWS\\\)9)?)?)B)BF (Vt^^'''": 2J + +5MM 	+MM!M*** b88Fs   ( AA		A)F)TF)FFFF)FFF)7r   rer/   r   typingr   r   rT   r   	intrangesr   rx   r   rV   compiler   	frozensetrZ   rY   r[   r\   r]   r^   r_   rz   r{   intr   r   r   r!   r)   r+   r-   r5   boolr:   r   r@   rC   rJ   rP   rf   rj   rp   rt   r   r   r   r   r   r   r   r>   r   r'   r   r   <module>r      s    				      " " " " " " " "       ( ( ( ( ( (  2::;;  )S$K(( y!2!2!233 IZZZ[[ "#:#:#:;; ItTl++ INNNOO "C;// ic
++ ic
++ c hsm    @ @ @ @ @ @ @ @F F F F FI F F FG G G G Gy G G GN N N N Ni N N N     @3 @ @ @ @ @ @           S S    eE3J/ D    9eSj 1 9 9$ 9 9 9 9H Hc Hd Ht H H H HV# $    3 4    $	AS 	AT 	A 	A 	A 	A3# 3C 3D 3 3 3 3l. .# .C .D .T . . . .b4uS%23 4 4 4 4 4n# %    D(%UI-. (3 ( ( ( (V50 50 50 50D 50UX 50 50 50 50t E ES%"#EE E 	E
 E E E E ET 	4 4S%"#44 4 	4
 	4 4 4 4 4 4r   