ó
KaZUc           @   s  d  d l  m Z d d l Z d d l Z d d l Z d d l Z d Z d Z e j d  Z	 e j
 d d k r} e Z e Z n  d	 e f d
     YZ d e f d     YZ d e f d     YZ d e f d     YZ d   Z d   Z d   Z d   Z d   Z d   Z e d  Z d   Z d   Z d   Z d   Z e d  Z  d   Z! d   Z" d   Z# e$ e d   Z% e e e e d!  Z& e e e d"  Z' d S(#   i   (   t   idnadatai˙˙˙˙Ni	   s   xn--u   [.ăďźď˝Ą]i    i   t	   IDNAErrorc           B   s   e  Z d  Z RS(   s7    Base exception for all IDNA-encoding related problems (   t   __name__t
   __module__t   __doc__(    (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyR      s   t   IDNABidiErrorc           B   s   e  Z d  Z RS(   s=    Exception when bidirectional requirements are not satisfied (   R   R   R   (    (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyR      s   t   InvalidCodepointc           B   s   e  Z d  Z RS(   s>    Exception when a disallowed or unallocated codepoint is used (   R   R   R   (    (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyR      s   t   InvalidCodepointContextc           B   s   e  Z d  Z RS(   sE    Exception when the codepoint is not valid in the context it is used (   R   R   R   (    (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyR      s   c         C   s   t  j t |    S(   N(   t   unicodedatat	   combiningt   unichr(   t   cp(    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt   _combining_class#   s    c         C   s   t  |   t j | k S(   N(   t   ordR    t   scripts(   R   t   script(    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt
   _is_script&   s    c         C   s   |  j  d  S(   Nt   punycode(   t   encode(   t   s(    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt	   _punycode)   s    c         C   s   d j  |   S(   Ns	   U+{0:04X}(   t   format(   R   (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt   _unot,   s    c         C   s   t  |   d k r t St S(   Ni?   (   t   lent   Falset   True(   t   label(    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt   valid_label_length0   s    c         C   s&   t  |   | r d n d k r" t St S(   Niţ   iý   (   R   R   R   (   R   t   trailing_dot(    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt   valid_string_length7   s    c   	      C   s  t  } xo t |  d  D]^ \ } } t j |  } | d k r^ t d j t |   |    n  | d k r t } Pq q W| r | r t St j |  d  } | d k r˛ t } n0 | d k rÇ t  } n t d	 j t |      t  } t  } x
t |  d  D]ů \ } } t j |  } | rŠ| d k rCt d j |    n  | d k rXt } n | d k rmt  } n  | d k r÷| s| } qŚ| | k rŚt d   qŚq÷qţ | d k rÍt d j |    n  | d k rât } qţ | d k rţ t  } qţ qţ W| st d   n  t S(   Ni   t    s3   Unknown directionality in label {0} at position {1}t   Rt   ALt   ANi    t   Ls>   First codepoint in label {0} must be directionality L, R or ALt   ENt   ESt   CSt   ETt   ONt   BNt   NSMsH   Invalid direction for codepoint at position {0} in a right-to-left labels2   Can not mix numeral types in a right-to-left labelsH   Invalid direction for codepoint at position {0} in a left-to-right labels0   Label ends with illegal codepoint directionality(   R   R    R!   (   R   R    (
   R   R    R!   R#   R$   R%   R&   R'   R(   R)   (   R   R    R#   R!   (   R!   R#   (   R"   R#   R$   R%   R&   R'   R(   R)   (   R"   R#   (   R   t	   enumerateR   t   bidirectionalR   R   t   reprR   (	   R   t	   check_ltrt
   bidi_labelt   idxR   t	   directiont   rtlt   valid_endingt   number_type(    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt
   check_bidi>   sR    !						c         C   s0   t  j |  d  d d k r, t d   n  t S(   Ni    t   Ms0   Label begins with an illegal combining character(   R   t   categoryR   R   (   R   (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt   check_initial_combiner{   s    c         C   sU   |  d d !d k r" t  d   n  |  d d k sB |  d d k rQ t  d   n  t S(	   Ni   i   s   --s4   Label has disallowed hyphens in 3rd and 4th positioni    t   -i˙˙˙˙s)   Label must not start or end with a hyphen(   R   R   (   R   (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt   check_hyphen_ok   s
     c         C   s+   t  j d |   |  k r' t d   n  d  S(   Nt   NFCs%   Label must be in Normalization Form C(   R   t	   normalizeR   (   R   (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt	   check_nfc   s    c         C   s  t  |  |  } | d k r6| d k rO t t  |  | d   t k rO t Sn  t } xb t | d d d  D]J } t j j t  |  |   } | d k r  ql n  | d
 k rl t } Pql ql W| sÄ t St } xe t | d t	 |    D]J } t j j t  |  |   } | d k rqä n  | d k rä t } Pqä qä W| S| d	 k ry| d k rut t  |  | d   t k rut Sn  t St Sd  S(   Ni   i    i   i˙˙˙˙t   TR"   t   DR   i   (   R"   R>   (   R   R>   (
   R   R   t   _virama_combining_classR   R   t   rangeR    t   joining_typest   getR   (   R   t   post   cp_valuet   okt   it   joining_type(    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt   valid_contextj   s<       c         C   s$  t  |  |  } | d k r d | k  o= t |   d k  n r} t  |  | d  d k r} t  |  | d  d k r} t Sn  t S| d k rÎ | t |   d k  rĘ t |   d k rĘ t |  | d d  St S| d k sć | d k r| d k rt |  | d d	  St S| d
 k rrxT |  D]L } | d k r6qn  t | d  rt | d  rt | d  rt SqWt Sd | k od k n rÉx4 |  D], } d t  |  k o¸d k n rt SqWt Sd | k oŕd k n r x4 |  D], } d t  |  k od k n rět SqěWt Sd  S(   Niˇ   i    i   il   iu  t   Greekió  iô  t   Hebrewiű0  u   ăťt   Hiraganat   Katakanat   Hani`  ii  iđ  iů  (   R   R   R   R   R   (   R   RC   t	   exceptionRD   R   (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt   valid_contexto˝   s>    &4(0""c         C   s  t  |  t t f  r' |  j d  }  n  t |   d k rH t d   n  t |   t |   t |   xt	 |   D]\ } } t
 |  } | t j d k r¤ qs qs | t j d k r÷ t |  |  sut d j t |  | d t |      quqs | t j d k rJt |  |  sut d	 j t |  | d t |      quqs t d
 j t |  | d t |      qs Wt |   d  S(   Ns   utf-8i    s   Empty Labelt   PVALIDt   CONTEXTJs-   Joiner {0} not allowed at position {1} in {2}i   t   CONTEXTOs0   Codepoint {0} not allowed at position {1} in {2}s0   Codepoint {0} at position {1} of {2} not allowed(   t
   isinstancet   bytest	   bytearrayt   decodeR   R   R<   R9   R7   R*   R   R    t   codepoint_classesRH   R   R   R   R,   RO   R   R4   (   R   RC   R   RD   (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt   check_labelć   s&    


11/c         C   sÓ   y_ |  j  d  }  y t |   Wn t d j |     n Xt |   sZ t d   n  |  SWn t k
 rr n X|  s t d   n  t |   }  t |   t |   }  t	 |  }  t |   sĎ t d   n  |  S(   Nt   asciis$   The label {0} is not a valid A-labels   Label too longs   No Input(
   R   t   ulabelR   R   R   t   UnicodeErrort   unicodeRX   R   t   _alabel_prefix(   R   (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt   alabel  s(    

c         C   sŹ   t  |  t t f  sJ y |  j d  }  WqJ t k
 rF t |   |  SXn  |  j   }  |  j t  rx |  t	 t  }  n t |   |  j
 d  S|  j
 d  }  t |   |  S(   NRY   R   (   RS   RT   RU   R   R[   RX   t   lowert
   startswithR]   R   RV   (   R   (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyRZ     s    


c         C   s  d d l  m  } d } yFx/t |   D]!\ } } t |  } | | d k  rS | n t j | | d f  d } | d }	 t |  d k r | d n d }
 |	 d k sŮ |	 d	 k rť | sŮ |	 d
 k rć | rć |
 d k rć | | 7} q& |
 d k	 r/|	 d k s"|	 d
 k r| s"|	 d	 k r/| r/| |
 7} q& |	 d k r& t    q& q& Wt j	 d |  SWn< t k
 rt
 d j t |  | d t |      n Xd S(   sB   Re-map the characters in the string according to UTS46 processing.i   (   t	   uts46datau    i   t   Zi   i   t   VR>   t   3R5   t   IR:   s0   Codepoint {0} not allowed at position {1} in {2}N(   Ra   R*   R   t   bisectt   bisect_leftR   t   Nonet
   IndexErrorR   R;   R   R   R   R,   (   t   domaint
   std3_rulest   transitionalRa   t   outputRC   t   chart
   code_pointt   uts46rowt   statust   replacement(    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt   uts46_remap2  s0    
"c   	      C   s4  t  |  t t f  r' |  j d  }  n  | rB t |  | |  }  n  t } g  } | rf |  j d  } n t j |   } x | r | d r | d =qx W| sŠ t d   n  | d d k rÉ | d =t	 } n  x! | D] } | j
 t |   qĐ W| r| j
 d  n  d j |  }  t |  |  s0t d   n  |  S(   NRY   t   .i    s   Empty domaini˙˙˙˙R   s   Domain too long(   RS   RT   RU   RV   Rs   R   t   splitt   _unicode_dots_reR   R   t   appendR^   t   joinR   (	   R   t   strictt   uts46Rk   Rl   R   t   resultt   labelsR   (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyR   N  s0    	c         C   s
  t  |  t t f  r' |  j d  }  n  | rB t |  | t  }  n  t } g  } | sf t j |   } n |  j d  } x | r | d r | d =qx W| sŠ t d   n  | d sĂ | d =t	 } n  x! | D] } | j
 t |   qĘ W| rý | j
 d  n  d j |  S(   NRY   u   .i    s   Empty domaini˙˙˙˙u    (   RS   RT   RU   RV   Rs   R   Rv   Ru   R   R   Rw   RZ   Rx   (   R   Ry   Rz   Rk   R   R{   R|   R   (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyRV   k  s*    
	((   R   R    Rf   R   t   ret   sysR?   R]   t   compileRv   t   version_infot   strR\   t   chrR
   R[   R   R   R   R   R   R   R   R   R   R   R   R4   R7   R9   R<   RH   RO   RX   R^   RZ   R   Rs   R   RV   (    (    (    s-   /usr/lib/python2.7/dist-packages/idna/core.pyt   <module>   s@   							=					,)			