a
    åzeŠ#  ã                   @   s¸   d dl Z d dlZd dlZd dlmZ e d¡ZdZdZdd„ Z	dd	„ Z
d
d„ ZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ deejƒZG dd„ deejƒZdd„ ZdS )é    N)Ú	ucd_3_2_0u   [.ã€‚ï¼Žï½¡]s   xn--zxn--c                 C   sü   g }| D ] }t  |¡rq| t  |¡¡ qd |¡} t d| ¡} | D ]j}t  |¡s¢t  |¡s¢t  	|¡s¢t  
|¡s¢t  |¡s¢t  |¡s¢t  |¡s¢t  |¡s¢t  |¡rDtd| ƒ‚qDdd„ | D ƒ}t|ƒrøtdd„ | D ƒƒràtdƒ‚|d	 rð|d
 søtdƒ‚| S )NÚ ÚNFKCzInvalid character %rc                 S   s   g | ]}t  |¡‘qS © )Ú
stringprepZin_table_d1©Ú.0Úxr   r   ú$/usr/lib/python3.9/encodings/idna.pyÚ
<listcomp>)   ó    znameprep.<locals>.<listcomp>c                 s   s   | ]}t  |¡V  qd S )N)r   Zin_table_d2r   r   r   r
   Ú	<genexpr>1   r   znameprep.<locals>.<genexpr>zViolation of BIDI requirement 2r   éÿÿÿÿzViolation of BIDI requirement 3)r   Zin_table_b1ÚappendZmap_table_b2ÚjoinÚunicodedataÚ	normalizeZin_table_c12Zin_table_c22Zin_table_c3Zin_table_c4Zin_table_c5Zin_table_c6Zin_table_c7Zin_table_c8Zin_table_c9ÚUnicodeErrorÚany)ÚlabelZnewlabelÚcZRandALr   r   r
   Únameprep   sB    


ÿþýüûúùø	r   c                 C   sì   z|   d¡} W n ty    Y n*0 dt| ƒ  k r:dk rBn n| S tdƒ‚t| ƒ} z|   d¡} W n tyr   Y n*0 dt| ƒ  k rŒdk r”n n| S tdƒ‚|  t¡r®tdƒ‚|   d¡} t|  } dt| ƒ  k rØdk ràn n| S tdƒ‚d S )NÚasciir   é@   úlabel empty or too longzLabel starts with ACE prefixÚpunycode)Úencoder   Úlenr   Ú
startswithÚsace_prefixÚ
ace_prefix)r   r   r   r
   ÚToASCII<   s,    

r!   c                 C   sÎ   t | tƒrd}n*z|  d¡} d}W n ty8   d}Y n0 |spt| ƒ} z|  d¡} W n tyn   tdƒ‚Y n0 |  t¡s„t| dƒS | ttƒd … }| 	d¡}t
|ƒ}t| dƒ ¡ t|dƒkrÊtd| |ƒ‚|S )NTr   FzInvalid character in IDN labelr   zIDNA does not round-trip)Ú
isinstanceÚbytesr   r   r   r   r    Ústrr   Údecoder!   Úlower)r   Z
pure_asciiZlabel1ÚresultZlabel2r   r   r
   Ú	ToUnicodeg   s*    





r(   c                   @   s    e Zd Zddd„Zddd„ZdS )	ÚCodecÚstrictc                 C   s  |dkrt d| ƒ‚|sdS z| d¡}W n ty<   Y nd0 | d¡}|d d… D ]&}dt|ƒ  k rpdk sTn t d	ƒ‚qTt|d ƒdkr”t d
ƒ‚|t|ƒfS tƒ }t |¡}|rÈ|d sÈd}|d= nd}|D ] }|râ| d¡ | t|ƒ¡ qÐt	|| ƒt|ƒfS )Nr*   úunsupported error handling ©r   r   r   ó   .r   r   r   r   zlabel too longr   )
r   r   ÚUnicodeEncodeErrorÚsplitr   Ú	bytearrayÚdotsÚextendr!   r#   )ÚselfÚinputÚerrorsr'   Úlabelsr   Útrailing_dotr   r   r
   r   ‘   s4    



zCodec.encodec                 C   s¾   |dkrt d| ƒ‚|sdS t|tƒs.t|ƒ}t|vr^z| d¡t|ƒfW S  ty\   Y n0 | d¡}|rˆt|d ƒdkrˆd}|d= nd	}g }|D ]}| t	|ƒ¡ q”d 
|¡| t|ƒfS )
Nr*   úUnsupported error handling ©r   r   r   r-   r   r   Ú.r   )r   r"   r#   r    r%   r   ÚUnicodeDecodeErrorr/   r   r(   r   )r3   r4   r5   r6   r7   r'   r   r   r   r
   r%   ¶   s(    

zCodec.decodeN)r*   )r*   )Ú__name__Ú
__module__Ú__qualname__r   r%   r   r   r   r
   r)      s   
%r)   c                   @   s   e Zd Zdd„ ZdS )ÚIncrementalEncoderc           	      C   s¸   |dkrt d| ƒ‚|sdS t |¡}d}|rT|d sBd}|d= n|sT|d= |rTd}tƒ }d}|D ]4}|r|| d¡ |d7 }| t|ƒ¡ |t|ƒ7 }qb||7 }|t|ƒ7 }t|ƒ|fS )	Nr*   r+   r,   r   r   r-   r   é   )r   r1   r/   r0   r2   r!   r   r#   ©	r3   r4   r5   Úfinalr6   r7   r'   Úsizer   r   r   r
   Ú_buffer_encodeÙ   s2    

z!IncrementalEncoder._buffer_encodeN)r<   r=   r>   rD   r   r   r   r
   r?   Ø   s   r?   c                   @   s   e Zd Zdd„ ZdS )ÚIncrementalDecoderc           	      C   sÎ   |dkrt d| ƒ‚|sdS t|tƒr2t |¡}nt|dƒ}| d¡}d}|rt|d sbd}|d= n|st|d= |rtd}g }d}|D ]*}| t|ƒ¡ |rž|d	7 }|t|ƒ7 }q€d |¡| }|t|ƒ7 }||fS )
Nr*   r8   r9   r   r:   r   r   r   r@   )	r   r"   r$   r1   r/   r   r(   r   r   rA   r   r   r
   Ú_buffer_decodeü   s6    


z!IncrementalDecoder._buffer_decodeN)r<   r=   r>   rF   r   r   r   r
   rE   û   s   rE   c                   @   s   e Zd ZdS )ÚStreamWriterN©r<   r=   r>   r   r   r   r
   rG   "  s   rG   c                   @   s   e Zd ZdS )ÚStreamReaderNrH   r   r   r   r
   rI   %  s   rI   c                	   C   s    t jdtƒ jtƒ jttttdS )NZidna)Únamer   r%   ÚincrementalencoderÚincrementaldecoderÚstreamwriterÚstreamreader)	ÚcodecsÚ	CodecInfor)   r   r%   r?   rE   rG   rI   r   r   r   r
   Úgetregentry*  s    ùrQ   )r   ÚrerO   r   r   Úcompiler1   r    r   r   r!   r(   r)   ÚBufferedIncrementalEncoderr?   ÚBufferedIncrementalDecoderrE   rG   rI   rQ   r   r   r   r
   Ú<module>   s   
.+)H#'