mò
­fIc           @   sß   d  Z  d k 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 i f d „  ƒ  YZ d e e i f d „  ƒ  YZ d e e i f d „  ƒ  YZ d „  Z d S(   sX    Codec for the Punicode encoding, as specified in RFC 3492

Written by Martin v. Löwis.
Nc         C   s}   g  } h  } x< |  D]4 } t | ƒ d j  o | i | ƒ q d | | <q W| i ƒ  } | i ƒ  d i | ƒ i	 d ƒ | f S(   s    3.1 Basic code point segregationi€   i   t    t   asciiN(
   t   baset   extendedt   strt   ct   ordt   appendt   keyst   sortt   joint   encode(   R   R   R   R   (    (    t/   /mit/python/lib/python2.4/encodings/punycode.pyt	   segregate   s      
c         C   s<   d } x/ |  D]' } t | ƒ | j  o | d 7} q q W| S(   s@   Return the length of str, considering only characters below max.i    i   N(   t   resR   R   R   t   max(   R   R   R   R   (    (    R   t   selective_len   s      c         C   s{   t  |  ƒ } xh | d 7} | | j o d Sn |  | } | | j o | d | f Sq | | j  o | 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   lenR   t   lt   posR   t   chart   index(   R   R   R   R   R   R   (    (    R   t   selective_find    s       

c         C   sÄ   d } g  } d } x« | D]£ } d } } t | ƒ } t	 |  | ƒ }
 |
 d | | }	 x] t |  | | | ƒ \ } } | d j o Pn |	 | | 7}	 | i |	 d ƒ | } d }	 qY W| } q W| S(   s   3.2 Insertion unsort codingi€   iÿÿÿÿi   i    N(   t   oldchart   resultt   oldindexR   R   R   R   R   R   R   R   t   curlent   deltaR   R   (   R   R   R   R   R   R   R   R   R   R   R   (    (    R   t   insertion_unsort2   s*      
  
c         C   s@   d |  d | } | d j  o d Sn | d j o d Sn | S(   Ni$   i   i   (   t   jt   biasR   (   R   R   R   (    (    R   t   TH   s      t$   abcdefghijklmnopqrstuvwxyz0123456789c         C   sŠ   g  } d } xw t | | ƒ } |  | j  o | i t |  ƒ | Sn | i t | |  | d | ƒ |  | d | }  | d 7} q Wd S(   s(   3.3 Generalized variable-length integersi    i   i$   N(   R   R   R   R   t   tt   NR   t   digits(   R"   R   R   R!   R   (    (    R   t   generate_generalized_integerP   s       !c         C   sv   | o |  d }  n |  d }  |  |  | 7}  d } x& |  d j o |  d }  | d 7} q6 W| d |  |  d } | S(   Ni¼  i   i    iÇ  i#   i$   i&   (   t   firstR   t   numcharst	   divisionsR   (   R   R%   R&   R   R'   (    (    R   t   adapt]   s    
 
c         C   sr   g  } d } xV t | ƒ D]H \ } } t | | ƒ } | i | ƒ t	 | | d j |  | d ƒ } q Wd i | ƒ S(   s   3.4 Bias adaptationiH   i    i   R    N(   R   R   t	   enumeratet   deltast   pointsR   R$   t   st   extendR(   t   baselenR
   (   R.   R*   R   R,   R   R   R+   (    (    R   t   generate_integersl   s      $c         C   s`   t  |  ƒ \ } } | i d ƒ } t |  | ƒ } t t | ƒ | ƒ } | o | d | Sn | S(   NR   t   -(	   R   t   textR   R   R   R   R*   R/   R   (   R1   R*   R   R   (    (    R   t   punycode_encodew   s    c   
      C   sQ  d } d }	 d } x8y t |  | ƒ } Wn; t j
 o/ | d j o t	 d ‚ n | d d f Sn X| d 7} d | j o
 d j n o | d } n\ d | j o
 d j n o | d	 } n0 | d j o t	 d
 |  | ƒ ‚ n | d f St | | ƒ } | | |	 7} | | j  o | | f Sn |	 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   wR   R   R   t   extposR   t
   IndexErrort   errorst   UnicodeErrort   Nonet   digitR   R   R!   (
   R   R5   R   R7   R   R:   R!   R   R   R4   (    (    R   t   decode_generalized_number‚   s4       

c   	      C   s  d } d } d } d } xý | t | ƒ j  oé t | | | | ƒ \ } } | d
 j o |  Sn | | d 7} | | t |  ƒ d 7} | d j o. | d j o t d | ‚ n t d	 ƒ } n | t |  ƒ d } |  |  t | ƒ |  | }  t | | d j t |  ƒ ƒ } | } q W|  S(   s   3.2 Insertion unsort codingi€   iÿÿÿÿiH   i    i   iÿÿ R3   s   Invalid character U+%xt   ?N(   R   R   R   R5   R   R   R;   R7   t   newposR   R9   R   R8   R   t   unichrR(   (	   R   R   R7   R5   R=   R   R   R   R   (    (    R   t   insertion_sort    s,      	c         C   sr   |  i d ƒ } | d j o d } |  } n |  |  } |  | d } t | d | ƒ } | i ƒ  } t | | | ƒ S(   NR0   iÿÿÿÿR    i   R   (	   R1   t   rfindR   R   R   t   unicodeR7   t   upperR?   (   R1   R7   R   R   R   (    (    R   t   punycode_decode¹   s    

t   Codecc           B   s    t  Z d d „ Z d d „ Z RS(   NR3   c         C   s   t  | ƒ } | t | ƒ f S(   N(   R2   t   inputR   R   (   t   selfRE   R7   R   (    (    R   R   È   s    c         C   s=   | d j o t d | ‚ n t | | ƒ } | t | ƒ f S(   NR3   t   replacet   ignores   Unsupported error handling (   s   stricts   replaces   ignore(   R7   R8   RC   RE   R   R   (   RF   RE   R7   R   (    (    R   t   decodeÍ   s    (   t   __name__t
   __module__R   RI   (    (    (    R   RD   Ç   s   t   StreamWriterc           B   s   t  Z RS(   N(   RJ   RK   (    (    (    R   RL   Ô   s   t   StreamReaderc           B   s   t  Z RS(   N(   RJ   RK   (    (    (    R   RM   ×   s   c           C   s   t  ƒ  i t  ƒ  i t t f S(   N(   RD   R   RI   RM   RL   (    (    (    R   t   getregentryÜ   s    (   t   __doc__t   codecsR   R   R   R   R   R#   R$   R(   R/   R2   R;   R?   RC   RD   RL   RM   RN   (   R#   RL   RC   RN   R   R2   R   R   RD   R   RP   R/   R$   R   R?   RM   R;   R(   (    (    R   R<      s$   													