ó
č¾bc           @   ss  d  Z  d d l m Z m Z d d l m Z d d l m Z m Z m	 Z	 m
 Z
 m Z m Z m Z i d d d d d	 d
 d d d g f d d d d d d d d d d d d d d d d g f d d g f g d  6d d
 d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 g f d d8 d9 g f g d: 6Z e d: j e d  d;  d<   Z d= e f d>     YZ d? S(@   s¾   Fix changes imports of urllib which are now incompatible.
   This is rather similar to fix_imports, but because of the more
   complex nature of the fixing for urllib, it has its own fixer.
i’’’’(   t
   alternatest
   FixImports(   t
   fixer_base(   t   Namet   Commat
   FromImportt   Newlinet   find_indentationt   Nodet   symss   urllib.requestt	   URLopenert   FancyURLopenert   urlretrievet
   _urlopenert   urlopent
   urlcleanupt   pathname2urlt   url2pathnames   urllib.parset   quotet
   quote_plust   unquotet   unquote_plust	   urlencodet	   splitattrt	   splithostt
   splitnportt   splitpasswdt	   splitportt
   splitqueryt   splittagt	   splittypet	   splitusert
   splitvalues   urllib.errort   ContentTooShortErrort   urllibt   install_openert   build_openert   Requestt   OpenerDirectort   BaseHandlert   HTTPDefaultErrorHandlert   HTTPRedirectHandlert   HTTPCookieProcessort   ProxyHandlert   HTTPPasswordMgrt   HTTPPasswordMgrWithDefaultRealmt   AbstractBasicAuthHandlert   HTTPBasicAuthHandlert   ProxyBasicAuthHandlert   AbstractDigestAuthHandlert   HTTPDigestAuthHandlert   ProxyDigestAuthHandlert   HTTPHandlert   HTTPSHandlert   FileHandlert
   FTPHandlert   CacheFTPHandlert   UnknownHandlert   URLErrort	   HTTPErrort   urllib2i   c          c   s   t    }  x t j   D]w \ } } xh | D]` } | \ } } t |  } d | | f Vd | | | f Vd | Vd | Vd | | f Vq) Wq Wd  S(   Ns   import_name< 'import' (module=%r
                                  | dotted_as_names< any* module=%r any* >) >
                  sĘ   import_from< 'from' mod_member=%r 'import'
                       ( member=%s | import_as_name< member=%s 'as' any > |
                         import_as_names< members=any*  >) >
                  sI   import_from< 'from' module_star=%r 'import' star='*' >
                  st   import_name< 'import'
                                  dotted_as_name< module_as=%r 'as' any > >
                  sK   power< bare_with_attr=%r trailer< '.' member=%s > any* >
                  (   t   sett   MAPPINGt   itemsR    (   t   baret
   old_modulet   changest   changet
   new_modulet   members(    (    s.   /usr/lib/python2.7/lib2to3/fixes/fix_urllib.pyt   build_pattern1   s    			t	   FixUrllibc           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   s   d j  t    S(   Nt   |(   t   joinRF   (   t   self(    (    s.   /usr/lib/python2.7/lib2to3/fixes/fix_urllib.pyRF   J   s    c         C   s   | j  d  } | j } g  } x? t | j d  D], } | j t | d d | t   g  q0 W| j t t | j d d d |  | j |  d S(   s   Transform for the basic import case. Replaces the old
           import name with a comma separated list of its
           replacements.
        t   modulei’’’’i    t   prefixN(	   t   getRL   R>   t   valuet   extendR   R   t   appendt   replace(   RJ   t   nodet   resultst
   import_modt   preft   namest   name(    (    s.   /usr/lib/python2.7/lib2to3/fixes/fix_urllib.pyt   transform_importM   s    	*(c         C   sš  | j  d  } | j } | j  d  } | r½ t | t  rI | d } n  d } x6 t | j D]' } | j | d k r] | d } Pq] q] W| rŖ | j t | d |  qģ|  j	 | d  n/g  } i  }	 | d }
 xĶ |
 D]Å } | j
 t j k r| j d j } | j d j } n | j } d } | d	 k rŚ xl t | j D]Z } | | d k r>| d |	 k rx| j | d  n  |	 j | d g   j |  q>q>WqŚ qŚ Wg  } t |  } t } d
   } x½ | D]µ } |	 | } g  } x8 | d  D], } | j | | |   | j t    qģW| j | | d |   t | |  } | sa| j j j |  rm| | _ n  | j |  t } qĖW| rÜg  } x( | d  D] } | j | t   g  qW| j | d  | j |  n |  j	 | d  d S(   s   Transform for imports of specific module elements. Replaces
           the module to be imported from with the appropriate new
           module.
        t
   mod_membert   memberi    i   RL   s!   This is an invalid module elementRE   i   u   ,c         S   sz   |  j  t j k rd t |  j d j d | |  j d j   |  j d j   g } t t j |  g St |  j d | g S(   Ni    RL   i   i   (   t   typeR	   t   import_as_nameR   t   childrenRN   t   cloneR   (   RW   RL   t   kids(    (    s.   /usr/lib/python2.7/lib2to3/fixes/fix_urllib.pyt   handle_name   s    i’’’’s   All module elements are invalidN(   RM   RL   t
   isinstancet   listt   NoneR>   RN   RQ   R   t   cannot_convertR[   R	   R\   R]   RP   t
   setdefaultR   t   TrueRO   R   R   t   parentt   endswitht   FalseR   (   RJ   RR   RS   RY   RU   RZ   t   new_nameRC   t   modulest   mod_dictRE   t   as_namet   member_namet	   new_nodest   indentationt   firstR`   RK   t   eltsRV   t   eltt   newt   nodest   new_node(    (    s.   /usr/lib/python2.7/lib2to3/fixes/fix_urllib.pyt   transform_member]   sh    	

	+	

c         C   s²   | j  d  } | j  d  } d } t | t  r@ | d } n  x6 t | j D]' } | j | d k rN | d } PqN qN W| r | j t | d | j  n |  j	 | d  d S(   s.   Transform for calls to module members in code.t   bare_with_attrRZ   i    i   RL   s!   This is an invalid module elementN(
   RM   Rc   Ra   Rb   R>   RN   RQ   R   RL   Rd   (   RJ   RR   RS   t
   module_dotRZ   Rj   RC   (    (    s.   /usr/lib/python2.7/lib2to3/fixes/fix_urllib.pyt   transform_dot©   s    
c         C   s®   | j  d  r" |  j | |  n | j  d  rD |  j | |  nf | j  d  rf |  j | |  nD | j  d  r |  j | d  n" | j  d  rŖ |  j | d  n  d  S(   NRK   RY   Rx   t   module_stars   Cannot handle star imports.t	   module_ass#   This module is now multiple modules(   RM   RX   Rw   Rz   Rd   (   RJ   RR   RS   (    (    s.   /usr/lib/python2.7/lib2to3/fixes/fix_urllib.pyt	   transformŗ   s    (   t   __name__t
   __module__RF   RX   Rw   Rz   R}   (    (    (    s.   /usr/lib/python2.7/lib2to3/fixes/fix_urllib.pyRG   H   s
   			L	N(   t   __doc__t   lib2to3.fixes.fix_importsR    R   t   lib2to3R   t   lib2to3.fixer_utilR   R   R   R   R   R   R	   R>   RP   RF   RG   (    (    (    s.   /usr/lib/python2.7/lib2to3/fixes/fix_urllib.pyt   <module>   sD   4							