B
    ^ c#                 @   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 }t|rtdd | D rtd|d	 r|d
 std| S )N ZNFKCzInvalid character %rc             S   s   g | ]}t |qS  )
stringprepZin_table_d1).0xr   r   lib/python3.7/encodings/idna.py
<listcomp>)   s    znameprep.<locals>.<listcomp>c             s   s   | ]}t |V  qd S )N)r   Zin_table_d2)r   r   r   r   r   	<genexpr>1   s    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unicodedataZ	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   s2    













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_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 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 )Nr%   zunsupported error handling )    r   r      .r   r   r   zlabel empty or too longz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|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 )
Nr%   zUnsupported error handling )r   r   r   r'   r   r   .r   )r   r   r   r   r    r   UnicodeDecodeErrorr)   r   r#   r   )r-   r.   r/   r0   r1   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}x<|D ]4}|r~|d |d7 }|t| |t|7 }qdW ||7 }|t|7 }t||fS )	Nr%   zunsupported error handling )r&   r   r&   r   r'   r      )r   r+   r)   r*   r,   r   r   r   )	r-   r.   r/   finalr0   r1   r"   sizer   r   r   r   _buffer_encode   s2    


z!IncrementalEncoder._buffer_encodeN)r4   r5   r6   r;   r   r   r   r   r7      s   r7   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 )
Nr%   zUnsupported error handling )r   r   r   r2   r   r   r   r8   )	r   r   r   r+   r)   r   r#   r   r   )	r-   r.   r/   r9   r0   r1   r"   r:   r   r   r   r   _buffer_decode   s6    



z!IncrementalDecoder._buffer_decodeN)r4   r5   r6   r=   r   r   r   r   r<      s   r<   c               @   s   e Zd ZdS )StreamWriterN)r4   r5   r6   r   r   r   r   r>   "  s   r>   c               @   s   e Zd ZdS )StreamReaderN)r4   r5   r6   r   r   r   r   r?   %  s   r?   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    r7   r<   r>   r?   r   r   r   r   getregentry*  s    rG   )r   rerE   r   r   compiler+   r   r   r   r   r#   r$   BufferedIncrementalEncoderr7   BufferedIncrementalDecoderr<   r>   r?   rG   r   r   r   r   <module>   s   
.+)H#'