B
    ¦�2[%  ã               @   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  |¡s¨t  |¡s¨t  	|¡s¨t  
|¡s¨t  |¡s¨t  |¡s¨t  |¡s¨t  |¡s¨t  |¡rJtd| ƒ‚qJW dd„ | D ƒ}xD|D ]<}|rÌtdd„ | D ƒƒrîtdƒ‚|d	 �r |d
 sÌtdƒ‚qÌW | S )NÚ ZNFKCzInvalid character %rc             S   s   g | ]}t  |¡‘qS © )Ú
stringprepZin_table_d1)Ú.0Úxr   r   úXC:\Users\hironori_takatsuka\AppData\Local\Programs\Python\Python37\lib\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>2   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Ú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   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 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   é@   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¡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   Ú	ToUnicodei   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ršt d
ƒ‚|t|ƒfS tƒ }t |¡}|rÎ|d sÎd}|d= nd}x(|D ] }|rê| d¡ | t|ƒ¡ qØW 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¡}|rˆt|d ƒdkrˆd}|d= nd	}g }x|D ]}| t	|ƒ¡ q–W 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/   r0   r1   r2   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/   r0   Úfinalr1   r2   r#   Úsizer   r   r   r   Ú_buffer_encodeÛ   s2    


z!IncrementalEncoder._buffer_encodeN)r5   r6   r7   r<   r   r   r   r   r8   Ú   s   r8   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 }q‚W d |¡| }|t|ƒ7 }||fS )
Nr&   zUnsupported error handling )r   r   r   r3   r   r   r   r9   )	r   r   r    r,   r*   r   r$   r   r   )	r.   r/   r0   r:   r1   r2   r#   r;   r   r   r   r   Ú_buffer_decodeþ   s6    



z!IncrementalDecoder._buffer_decodeN)r5   r6   r7   r>   r   r   r   r   r=   ý   s   r=   c               @   s   e Zd ZdS )ÚStreamWriterN)r5   r6   r7   r   r   r   r   r?   $  s   r?   c               @   s   e Zd ZdS )ÚStreamReaderN)r5   r6   r7   r   r   r   r   r@   '  s   r@   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Ú	CodecInfor%   r   r!   r8   r=   r?   r@   r   r   r   r   Úgetregentry,  s    rI   )r   ÚrerG   r   r   Úcompiler,   r   r   r   r   r$   r%   ÚBufferedIncrementalEncoderr8   ÚBufferedIncrementalDecoderr=   r?   r@   rI   r   r   r   r   Ú<module>   s   
0+)H#'