3 f,@s>ddlmZddlZddlZddlZddlZddlmZdZdZ ej dZ ej ddkr`e ZeZGd d d eZGd d d eZGd ddeZGdddeZddZddZddZddZddZddZd7ddZd d!Zd"d#Zd$d%Zd&d'Z d8d(d)Z!d*d+Z"d,d-Z#d.d/Z$d9d1d2Z%d:d3d4Z&d;d5d6Z'dS)<)idnadataN)intranges_contain sxn--u [.。.。]c@seZdZdZdS) IDNAErrorz7 Base exception for all IDNA-encoding related problems N)__name__ __module__ __qualname____doc__r r /usr/lib/python3.6/core.pyrsrc@seZdZdZdS) IDNABidiErrorz= Exception when bidirectional requirements are not satisfied N)rr r r r r r r rsrc@seZdZdZdS)InvalidCodepointz> Exception when a disallowed or unallocated codepoint is used N)rr r r r r r r rsrc@seZdZdZdS)InvalidCodepointContextzE Exception when the codepoint is not valid in the context it is used N)rr r r r r r r rsrcCstjt|S)N) unicodedataZ combiningunichr)cpr r r _combining_class$srcCstt|tj|S)N)rordrscripts)rZscriptr r r _is_script'srcCs |jdS)Npunycode)encode)sr r r _punycode*srcCs dj|S)Nz U+{0:04X})format)rr r r _unot-srcCst|dkrdSdS)N?FT)len)labelr r r valid_label_length1s r!cCst||rdndkrdSdS)NFT)r)r trailing_dotr r r valid_string_length8sr%Fc Cspd}xJt|dD]<\}}tj|}|dkr>tdjt|||dkrd}PqW| r`| r`dStj|d }|dkr|d}n |d krd}ntd jt|d}d}xt|dD]\}}tj|}|r&|dkrtdj||dkrd}n|dkrd}|dkrZ|s|}n||krZtdq|dkr>tdj||dkrNd}q|dkrd}qW|sltddS)NFrz3Unknown directionality in label {0} at position {1}RALANTrLz>First codepoint in label {0} must be directionality L, R or ALENESCSETONBNNSMzHInvalid direction for codepoint at position {0} in a right-to-left labelz2Can not mix numeral types in a right-to-left labelzHInvalid direction for codepoint at position {0} in a left-to-right labelz0Label ends with illegal codepoint directionality)r'r(r))r'r() r'r(r)r+r,r-r.r/r0r1)r'r(r+r))r)r+)r*r+r,r-r.r/r0r1)r*r+) enumeraterZ bidirectionalrrrepr) r Z check_ltrZ bidi_labelidxr directionZrtlZ valid_endingZ number_typer r r check_bidi?sR          r6cCs"tj|dddkrtddS)NrMz0Label begins with an illegal combining characterT)rcategoryr)r r r r check_initial_combiner|sr9cCs<|dddkrtd|ddks0|d dkr8tdd S) Nz--z4Label has disallowed hyphens in 3rd and 4th positionr-rz)Label must not start or end with a hyphenT)r)r r r r check_hyphen_oks r>cCstjd||krtddS)NNFCz%Label must be in Normalization Form C)r normalizer)r r r r check_nfcsrAcCsHt||}|dkr |dkr:tt||dtkr:dSd}xZt|dd d D]F}tjjt||}|tdkrxqPqP|tdtdgkrd}PqPPqPW|sdSd}x^t|dt|D]H}tjjt||}|tdkrqq|td tdgkrd}PqPqW|S|d kr@|dkr  (  "      rNcCst|ttfr|jd}t|dkr,tdt|t|t|xt |D]\}}t |}t |t j drrqNqNt |t j drt||stdjt||dt|qNt |t j drt||std jt||dt|qNtd jt||dt|qNWt|dS) Nzutf-8rz Empty LabelZPVALIDZCONTEXTJz-Joiner {0} not allowed at position {1} in {2}rZCONTEXTOz0Codepoint {0} not allowed at position {1} in {2}z0Codepoint {0} at position {1} of {2} not allowed) isinstancebytes bytearraydecoderrrAr>r9r2rrrZcodepoint_classesrKrrrr3rNrr6)r rGrrHr r r check_labels&      "rScCsyN|jd}y t|Wn"tk r:tdj|YnXt|sLtd|Stk rbYnX|sptdt|}t|t|}t |}t|std|S)Nasciiz$The label {0} is not a valid A-labelzLabel too longzNo Input) rulabelrrr!UnicodeEncodeErrorunicoderSr_alabel_prefix)r r r r alabels(  rYc Cst|ttfs:y|jd}Wntk r8t||SX|j}|jtr^|t td}nt||j dS|j d}t||S)NrTr) rOrPrQrrVrSlower startswithrXrrR)r r r r rU"s   rUTc Cs,ddlm}d}yxt|D]\}}t|}||dkr:|ntj||dfd}|d} t|dkrl|dnd} | d ks| d kr| s| d kr|r| dkr||7}q| dk r| d ks| d kr|s| d kr|r|| 7}q| d krtqWtjd|Stk r&t dj t ||dt |YnXdS)zBRe-map the characters in the string according to UTS46 processing.r) uts46datar&Zrr:NVrC3r7Ir?z0Codepoint {0} not allowed at position {1} in {2}) r\r2rbisectZ bisect_leftr IndexErrorrr@rrrr3) Zdomain std3_rules transitionalr\outputrGcharZ code_pointZuts46rowZstatusZ replacementr r r uts46_remap7s0       rhc Cst|ttfr|jd}|r(t|||}d}g}|r@|jd}n tj|}x|rb|d rb|d=qLW|sptd|d dkr|d =d}x|D]}|jt |qW|r|jd d j |}t ||std |S)NrTF.rz Empty domainrr&T.zDomain too longr=r=) rOrPrQrRrhsplit_unicode_dots_rerappendrYjoinr%) rstrictuts46rdrer$resultlabelsr r r r rSs0          rcCst|ttfr|jd}|r(t||d}d}g}|s@tj|}n |jd}x|rb|d rb|d=qLW|sptd|d s|d =d}x|D]}|jt |qW|r|jddj |S) NrTFrirz Empty domainrTr&r=r=) rOrPrQrRrhrmrlrrnrUro)rrprqrdr$rrrsr r r r rRps*       rR)F)F)TF)FFFF)FFF)(r&rrbrresysZ intrangesrrDrXcompilerm version_infostrrWchrr UnicodeErrorrrrrrrrrr!r%r6r9r>rArKrNrSrYrUrhrrRr r r r sB    = 0 )