ó
ñsºec           @   s  d  Z  d d l Z d „  Z d „  Z d „  Z d „  Z d „  Z d Z d	 „  Z d
 „  Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e e j f d „  ƒ  YZ d e e j f d „  ƒ  YZ d „  Z d S(   sX    Codec for the Punicode encoding, as specified in RFC 3492

Written by Martin v. Löwis.
iÿÿÿÿNc         C   s{   g  } i  } x: |  D]2 } t  | ƒ d k  r; | j | ƒ q d | | <q W| j ƒ  } | j ƒ  d j | ƒ j d ƒ | f S(   s    3.1 Basic code point segregationi€   i   t    t   ascii(   t   ordt   appendt   keyst   sortt   joint   encode(   t   strt   baset   extendedt   c(    (    s(   /usr/lib/python2.7/encodings/punycode.pyt	   segregate   s    
c         C   s:   d } x- |  D]% } t  | ƒ | k  r | d 7} q q W| S(   s@   Return the length of str, considering only characters below max.i    i   (   R   (   R   t   maxt   resR   (    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   selective_len   s
    c         C   sn   t  |  ƒ } x[ | d 7} | | k r) d S|  | } | | k rM | d | f S| | k  r | d 7} q q Wd S(   s  Return a pair (index, pos), indicating the next occurrence of
    char in str. index is the position of the character considering
    only ordinals up to and including char, and pos is the position in
    the full string. index/pos is the starting position in the full
    string.i   iÿÿÿÿN(   iÿÿÿÿiÿÿÿÿ(   t   len(   R   t   chart   indext   post   lR   (    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   selective_find    s    

c         C   sÁ   d } g  } d } x¨ | D]  } d } } t  | ƒ } t |  | ƒ }	 |	 d | | }
 xZ t |  | | | ƒ \ } } | d k r„ Pn  |
 | | 7}
 | j |
 d ƒ | } d }
 qY W| } q W| S(   s   3.2 Insertion unsort codingi€   iÿÿÿÿi   i    (   R   R   R   R   (   R   R
   t   oldchart   resultt   oldindexR   R   R   R   t   curlent   delta(    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   insertion_unsort2   s$    


c         C   s6   d |  d | } | d k  r" d S| d k r2 d S| S(   Ni$   i   i   (    (   t   jt   biasR   (    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   TH   s      t$   abcdefghijklmnopqrstuvwxyz0123456789c         C   s„   g  } d } xq t  | | ƒ } |  | k  r? | j t |  ƒ | S| j t | |  | d | ƒ |  | d | }  | d 7} q Wd S(   s(   3.3 Generalized variable-length integersi    i$   i   N(   R   R   t   digits(   t   NR   R   R   t   t(    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   generate_generalized_integerP   s    !c         C   sr   | r |  d }  n
 |  d }  |  |  | 7}  d } x$ |  d k rW |  d }  | d 7} q4 W| d |  |  d } | S(   Ni¼  i   i    iÇ  i#   i$   i&   (    (   R   t   firstt   numcharst	   divisionsR   (    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   adapt]   s    

c         C   sr   g  } d } xV t  | ƒ D]H \ } } t | | ƒ } | j | ƒ t | | d k |  | d ƒ } q Wd j | ƒ S(   s   3.4 Bias adaptationiH   i    i   R    (   t	   enumerateR#   t   extendR'   R   (   t   baselent   deltasR   R   t   pointsR   t   s(    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   generate_integersl   s    $c         C   s[   t  |  ƒ \ } } | j d ƒ } t |  | ƒ } t t | ƒ | ƒ } | rW | d | S| S(   NR   t   -(   R   R   R   R.   R   (   t   textR	   R
   R+   (    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   punycode_encodew   s    c   
      C   s<  d } d } d } x#y t  |  | ƒ } Wn4 t k
 r_ | d k rQ t d ‚ n  | d d f SX| d 7} d | k o d k n r“ | d } nV d | k oª d k n r¼ | d	 } n- | d k rß t d
 |  | ƒ ‚ n
 | d f St | | ƒ }	 | | | 7} | |	 k  r| | f S| d |	 } | d 7} q Wd S(   s(   3.3 Generalized variable-length integersi    i   t   stricts   incomplete punicode stringiA   iZ   i0   i9   i   s    Invalid extended code point '%s'i$   N(   R   t
   IndexErrort   UnicodeErrort   NoneR   (
   R
   t   extposR   t   errorsR   t   wR   R   t   digitR"   (    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   decode_generalized_number‚   s2    


c   	      C   s  d } d } d } d } xò | t  | ƒ k  rt | | | | ƒ \ } } | d
 k rX |  S| | d 7} | | t  |  ƒ d 7} | d k rµ | d k r¦ t d | ‚ n  t d	 ƒ } n  | t  |  ƒ d } |  |  t | ƒ |  | }  t | | d k t  |  ƒ ƒ } | } q W|  S(   s   3.2 Insertion unsort codingi€   iÿÿÿÿiH   i    i   iÿÿ R2   s   Invalid character U+%xt   ?N(   R   R:   R5   R4   R   t   unichrR'   (	   R	   R
   R7   R   R   R   R6   t   newposR   (    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   insertion_sort    s(    	
c         C   sp   |  j  d ƒ } | d k r* d } |  } n |  |  } |  | d } t | d | ƒ } | j ƒ  } t | | | ƒ S(   NR/   iÿÿÿÿR    i   R   (   t   rfindt   unicodet   upperR>   (   R0   R7   R   R	   R
   (    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   punycode_decode¹   s    	
t   Codecc           B   s    e  Z d  d „ Z d  d „ Z RS(   R2   c         C   s   t  | ƒ } | t | ƒ f S(   N(   R1   R   (   t   selft   inputR7   R   (    (    s(   /usr/lib/python2.7/encodings/punycode.pyR   É   s    c         C   s;   | d k r t  d | ‚ n  t | | ƒ } | t | ƒ f S(   NR2   t   replacet   ignores   Unsupported error handling (   R2   RF   RG   (   R4   RB   R   (   RD   RE   R7   R   (    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   decodeÍ   s    (   t   __name__t
   __module__R   RH   (    (    (    s(   /usr/lib/python2.7/encodings/punycode.pyRC   Ç   s   t   IncrementalEncoderc           B   s   e  Z e d  „ Z RS(   c         C   s
   t  | ƒ S(   N(   R1   (   RD   RE   t   final(    (    s(   /usr/lib/python2.7/encodings/punycode.pyR   Ô   s    (   RI   RJ   t   FalseR   (    (    (    s(   /usr/lib/python2.7/encodings/punycode.pyRK   Ó   s   t   IncrementalDecoderc           B   s   e  Z e d  „ Z RS(   c         C   s2   |  j  d k r" t d |  j  ‚ n  t | |  j  ƒ S(   NR2   RF   RG   s   Unsupported error handling (   R2   RF   RG   (   R7   R4   RB   (   RD   RE   RL   (    (    s(   /usr/lib/python2.7/encodings/punycode.pyRH   Ø   s    (   RI   RJ   RM   RH   (    (    (    s(   /usr/lib/python2.7/encodings/punycode.pyRN   ×   s   t   StreamWriterc           B   s   e  Z RS(    (   RI   RJ   (    (    (    s(   /usr/lib/python2.7/encodings/punycode.pyRO   Ý   s   t   StreamReaderc           B   s   e  Z RS(    (   RI   RJ   (    (    (    s(   /usr/lib/python2.7/encodings/punycode.pyRP   à   s   c           C   s@   t  j d d d t ƒ  j d t ƒ  j d t d t d t d t ƒ S(	   Nt   namet   punycodeR   RH   t   incrementalencodert   incrementaldecodert   streamwritert   streamreader(	   t   codecst	   CodecInfoRC   R   RH   RK   RN   RO   RP   (    (    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   getregentryå   s    	(   t   __doc__RW   R   R   R   R   R   R    R#   R'   R.   R1   R:   R>   RB   RC   RK   RN   RO   RP   RY   (    (    (    s(   /usr/lib/python2.7/encodings/punycode.pyt   <module>   s(   												