î
ëTÒ#  ã               @   s  d  d l  Z  d  d l Z d  d l Z d  d l m Z e j d ƒ Z d Z d Z d d „  Z	 d d	 „  Z
 d
 d „  Z Gd d „  d e j ƒ Z Gd d „  d e j ƒ Z Gd d „  d e j ƒ Z Gd d „  d e e j ƒ Z Gd d „  d e e j ƒ Z d d „  Z d S)é    N)Ú	ucd_3_2_0u   [.ã€‚ï¼Žï½¡]s   xn--zxn--c             C   sŒ  g  } x9 |  D]1 } t  j | ƒ r( q n  | j t  j | ƒ ƒ q Wd j | ƒ }  t j d |  ƒ }  x¨ |  D]  } t  j | ƒ s÷ t  j | ƒ s÷ t  j	 | ƒ s÷ t  j
 | ƒ s÷ t  j | ƒ s÷ t  j | ƒ s÷ t  j | ƒ s÷ t  j | ƒ s÷ t  j | ƒ rj t d | ƒ ‚ qj qj Wd d „  |  Dƒ } xd | D]\ } | r(t d d „  |  Dƒ ƒ r\t d ƒ ‚ n  | d	 sr| d r„t d ƒ ‚ q„q(q(W|  S)NÚ ZNFKCzInvalid character %rc             S   s   g  |  ] } t  j | ƒ ‘ q S© )Ú
stringprepZin_table_d1)Ú.0Úxr   r   úQ/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/encodings/idna.pyú
<listcomp>)   s   	 znameprep.<locals>.<listcomp>c             s   s   |  ] } t  j | ƒ 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 |  j  d ƒ }  Wn t k
 r' Yn3 Xd t |  ƒ k  oE d k  n rN |  St d ƒ ‚ t |  ƒ }  y |  j  d ƒ }  Wn t k
 r� Yn3 Xd t |  ƒ k  o« d k  n r´ |  St d ƒ ‚ |  j t ƒ rÞ t d ƒ ‚ n  |  j  d ƒ }  t |  }  d t |  ƒ k  od k  n r|  St 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 } n4 y |  j d ƒ }  d } Wn t k
 rK d } Yn X| s• t |  ƒ }  y |  j d ƒ }  Wq• t k
 r‘ t d ƒ ‚ Yq• Xn  |  j t ƒ s± t |  d ƒ S|  t t ƒ d  … } | j	 d ƒ } t
 | ƒ } t |  d ƒ j ƒ  t | d ƒ k rt d |  | ƒ ‚ n  | 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   st  | d k r t  d | ƒ ‚ n  | s) d Sy | j d ƒ } Wn t k
 rP Yn‘ X| j d ƒ } xI | d  d … D]7 } d t | ƒ k  o” d k  n sq t  d	 ƒ ‚ qq qq Wt | d ƒ d k rÑ t  d
 ƒ ‚ n  | t | ƒ f St ƒ  } t j | ƒ } | r| d rd } | d =n d } x7 | D]/ } | rC| j d ƒ n  | j t | ƒ ƒ q'Wt	 | | ƒ t | ƒ f S)Nr'   zunsupported error handling ó    r   r   ó   .r   r   zlabel empty or too longzlabel too long)r(   r   r   r   r   r   )
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 | ƒ ‚ n  | s) d	 St | t ƒ sG t | ƒ } n  t | k rˆ y | j d ƒ t | ƒ f SWqˆ t k
 r„ Yqˆ Xn  | j d ƒ } | rÃ t | d
 ƒ d k rÃ d } | d =n d } g  } x! | D] } | j t	 | ƒ ƒ qÖ Wd j
 | ƒ | t | ƒ f S)Nr'   zUnsupported error handling r   r   r   r)   r   Ú.)r   r   r   r   )r   r   r    r   r"   r   ÚUnicodeDecodeErrorr+   r   r%   r   )r/   r0   r1   r2   r3   r$   r   r   r   r   r"   ¸   s(    
zCodec.decodeN)Ú__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 | ƒ ‚ n  | s) d St j | ƒ } d } | r€ | d s^ d } | d	 =q€ | s€ | d
 =| r} d } q} q€ n  t ƒ  } d } xQ | D]I } | r¼ | j d ƒ | d 7} n  | j t | ƒ ƒ | t | ƒ 7} q– W| | 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    )	r/   r0   r1   Úfinalr2   r3   r$   Úsizer   r   r   r   Ú_buffer_encodeÛ   s2    

	
z!IncrementalEncoder._buffer_encodeN)r6   r7   r8   r<   r   r   r   r   r9   Ú   s   r9   c               @   s   e  Z d  Z d d „  Z d S)ÚIncrementalDecoderc       	      C   s0  | d k r t  d | ƒ ‚ n  | s) d St | t ƒ rJ t j | ƒ } n t | d ƒ } | j d ƒ } d } | r° | d	 sŽ d } | d
 =q° | s° | d =| r­ d } q­ q° n  g  } d } xD | D]< } | j t | ƒ ƒ | rï | d 7} n  | t | ƒ 7} qÃ Wd j | ƒ | } | t | ƒ 7} | | f S)Nr'   zUnsupported error handling r   r   r   r4   r   )r   r   r   r   r   )	r   r   r!   r-   r+   r   r%   r   r   )	r/   r0   r1   r:   r2   r3   r$   r;   r   r   r   r   Ú_buffer_decodeþ   s6    

z!IncrementalDecoder._buffer_decodeN)r6   r7   r8   r>   r   r   r   r   r=   ý   s   r=   c               @   s   e  Z d  Z d S)ÚStreamWriterN)r6   r7   r8   r   r   r   r   r?   $  s   r?   c               @   s   e  Z d  Z d S)ÚStreamReaderN)r6   r7   r8   r   r   r   r   r@   '  s   r@   c               C   s@   t  j d d d t ƒ  j d t ƒ  j d t d t d t d t ƒ S)	NÚnameZidnar   r"   ÚincrementalencoderÚincrementaldecoderÚstreamwriterÚstreamreader)	ÚcodecsÚ	CodecInfor&   r   r"   r9   r=   r?   r@   r   r   r   r   Úgetregentry,  s    	rH   )r   ÚrerF   r   r   Úcompiler-   r   r   r   r   r%   r&   ÚBufferedIncrementalEncoderr9   ÚBufferedIncrementalDecoderr=   r?   r@   rH   r   r   r   r   Ú<module>   s   $0+)H#'