B
    B|#]%                 @   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 }x(| D ] }t |rq
|t | q
W d|} td| } xr| D ]j}t |st |st 	|st 
|st |st |st |st |st |rJtd| qJW dd | D }xD|D ]<}|rtdd | D rtd|d	 r |d
 stdqW | S )N NFKCzInvalid character %rc             S   s   g | ]}t |qS  )
stringprepin_table_d1).0xr   r   (C:\Python\Python37\lib\encodings\idna.py
<listcomp>)   s    znameprep.<locals>.<listcomp>c             s   s   | ]}t |V  qd S )N)r   in_table_d2)r   r	   r   r   r
   	<genexpr>2   s    znameprep.<locals>.<genexpr>zViolation of BIDI requirement 2r   zViolation of BIDI requirement 3)r   in_table_b1appendmap_table_b2joinunicodedata	normalizein_table_c12in_table_c22in_table_c3in_table_c4in_table_c5in_table_c6in_table_c7in_table_c8in_table_c9UnicodeErrorany)labelZnewlabelcZRandALr   r   r
   nameprep   s4    













r"   c             C   s   y|  d} W n tk
r"   Y n*X dt|   k r<dk rDn n| S tdt| } y|  d} W n tk
rv   Y n*X dt|   k rdk rn n| S td| trtd|  d} t|  } dt|   k rdk rn n| S tdd S )Nasciir   @   z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,y| d} d}W n tk
r:   d}Y nX |stt| } y| d} W n tk
rr   tdY nX | tst| dS | ttd  }|	d}t
|}t| d t|dkrt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_asciilabel1resultlabel2r   r   r
   	ToUnicodei   s*    





r4   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 y|d}W n tk
r>   Y nhX |d}x6|d d D ]&}dt|  k rtdk sXn t d	qXW t|d dkrt d
|t|fS t }t|}|r|d sd}|d= nd}x(|D ] }|r|d |t| qW t	|| t|fS )Nr6   zunsupported error handling )    r   r#      .r   r   r$   zlabel empty or too longzlabel too longr7   )
r   r&   UnicodeEncodeErrorsplitr'   	bytearraydotsextendr+   r-   )selfinputerrorsr2   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|kr^y|dt|fS  tk
r\   Y nX |d}|rt|d dkrd}|d= nd	}g }x|D ]}|t	| qW d
|| t|fS )
Nr6   zUnsupported error handling )r   r   r#   r8   r   r   .r   )r   r,   r-   r*   r/   r'   UnicodeDecodeErrorr:   r   r4   r   )r>   r?   r@   rA   rB   r2   r    r   r   r
   r/      s(    


zCodec.decodeN)r6   )r6   )__name__
__module____qualname__r&   r/   r   r   r   r
   r5      s   
%r5   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}x<|D ]4}|r~|d |d7 }|t| |t|7 }qdW ||7 }|t|7 }t||fS )	Nr6   zunsupported error handling )r7   r   r7   r   r8   r      )r   r<   r:   r;   r=   r+   r'   r-   )	r>   r?   r@   finalrA   rB   r2   sizer    r   r   r
   _buffer_encode   s2    


z!IncrementalEncoder._buffer_encodeN)rE   rF   rG   rL   r   r   r   r
   rH      s   rH   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}x2|D ]*}|t| |r|d	7 }|t|7 }qW d|| }|t|7 }||fS )
Nr6   zUnsupported error handling )r   r   r#   rC   r   r   r   rI   )	r   r,   r.   r<   r:   r   r4   r'   r   )	r>   r?   r@   rJ   rA   rB   r2   rK   r    r   r   r
   _buffer_decode   s6    



z!IncrementalDecoder._buffer_decodeN)rE   rF   rG   rN   r   r   r   r
   rM      s   rM   c               @   s   e Zd ZdS )StreamWriterN)rE   rF   rG   r   r   r   r
   rO   $  s   rO   c               @   s   e Zd ZdS )StreamReaderN)rE   rF   rG   r   r   r   r
   rP   '  s   rP   c            	   C   s    t jdt jt jttttdS )Nidna)namer&   r/   incrementalencoderincrementaldecoderstreamwriterstreamreader)	codecs	CodecInfor5   r&   r/   rH   rM   rO   rP   r   r   r   r
   getregentry,  s    rY   )r   rerW   r   r   compiler<   r*   r)   r"   r+   r4   r5   BufferedIncrementalEncoderrH   BufferedIncrementalDecoderrM   rO   rP   rY   r   r   r   r
   <module>   s   
0+)H#'