B
    18™\¡   ã               @   sö   d Z ddlmZmZ ddlmZmZmZmZm	Z	m
Z
mZ 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d	dd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5gfdd6d7gfgd8œZed9  ed: d; ¡ d<d=„ ZG d>d?„ d?eƒZd@S )Az¾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.
é    )Ú
alternatesÚ
FixImports)ÚNameÚCommaÚ
FromImportÚNewlineÚfind_indentationÚNodeÚsymszurllib.requestZ	URLopenerZFancyURLopenerÚurlretrieveZ
_urlopenerÚurlopenÚ
urlcleanupÚpathname2urlÚurl2pathnamezurllib.parseÚquoteÚ
quote_plusÚunquoteÚunquote_plusÚ	urlencodeZ	splitattrZ	splithostZ
splitnportZsplitpasswdZ	splitportZ
splitqueryZsplittagZ	splittypeZ	splituserZ
splitvaluezurllib.errorÚContentTooShortErrorZinstall_openerÚbuild_openerZRequestZOpenerDirectorZBaseHandlerZHTTPDefaultErrorHandlerZHTTPRedirectHandlerZHTTPCookieProcessorZProxyHandlerZHTTPPasswordMgrZHTTPPasswordMgrWithDefaultRealmZAbstractBasicAuthHandlerZHTTPBasicAuthHandlerZProxyBasicAuthHandlerZAbstractDigestAuthHandlerZHTTPDigestAuthHandlerZProxyDigestAuthHandlerÚHTTPHandlerZHTTPSHandlerÚFileHandlerZ
FTPHandlerZCacheFTPHandlerZUnknownHandlerÚURLErrorÚ	HTTPError)ÚurllibÚurllib2r   r   é   c              c   s~   t ƒ } xrt ¡ D ]f\}}x\|D ]T}|\}}t|ƒ}d||f V  d|||f V  d| V  d| V  d||f V  qW qW d S )Nzimport_name< 'import' (module=%r
                                  | dotted_as_names< any* module=%r any* >) >
                  zÆimport_from< 'from' mod_member=%r 'import'
                       ( member=%s | import_as_name< member=%s 'as' any > |
                         import_as_names< members=any*  >) >
                  zIimport_from< 'from' module_star=%r 'import' star='*' >
                  ztimport_name< 'import'
                                  dotted_as_name< module_as=%r 'as' any > >
                  zKpower< bare_with_attr=%r trailer< '.' member=%s > any* >
                  )ÚsetÚMAPPINGÚitemsr   )ZbareZ
old_moduleÚchangesÚchangeZ
new_moduleÚmembers© r$   ú\/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/lib2to3/fixes/fix_urllib.pyÚbuild_pattern0   s    


r&   c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )Ú	FixUrllibc             C   s   d  tƒ ¡S )Nú|)Újoinr&   )Úselfr$   r$   r%   r&   I   s    zFixUrllib.build_patternc             C   sz   |  d¡}|j}g }x6t|j dd… D ] }| t|d |dtƒ g¡ q(W | tt|j d d |d¡ | |¡ dS )z‘Transform for the basic import case. Replaces the old
           import name with a comma separated list of its
           replacements.
        ÚmoduleNéÿÿÿÿr   )Úprefix)	Úgetr-   r   ÚvalueÚextendr   r   ÚappendÚreplace)r*   ÚnodeÚresultsÚ
import_modÚprefÚnamesÚnamer$   r$   r%   Útransform_importL   s    
  zFixUrllib.transform_importc             C   s<  |  d¡}|j}|  d¡}|rˆt|tƒr0|d }d}x*t|j D ]}|j|d kr@|d }P q@W |rx| t||d¡ n|  |d¡ n°g }i }	|d }
x–|
D ]Ž}|j	t
jkrÈ|jd	 j}|jd j}n
|j}d}|d
kržxPt|j D ]B}||d kræ|d |	kr| |d ¡ |	 |d g ¡ |¡ qæW qžW g }t|ƒ}d}dd„ }x–|D ]Ž}|	| }g }x2|dd… D ]"}| |||ƒ¡ | tƒ ¡ qlW | ||d |ƒ¡ t||ƒ}|rÆ|jj |¡rÌ||_| |¡ d}qNW |r,g }x&|dd… D ]}| |tƒ g¡ qøW | |d ¡ | |¡ n|  |d¡ dS )zšTransform for imports of specific module elements. Replaces
           the module to be imported from with the appropriate new
           module.
        Ú
mod_memberÚmemberr   Nr   )r-   z!This is an invalid module elementr#   é   ú,Tc             S   sX   | j tjkrHt| jd j|d| jd  ¡ | jd  ¡ g}ttj|ƒgS t| j|dgS )Nr   )r-   r   r<   )Útyper
   Úimport_as_namer   Úchildrenr/   Úcloner	   )r8   r-   Zkidsr$   r$   r%   Úhandle_nameŒ   s    z/FixUrllib.transform_member.<locals>.handle_namer,   FzAll module elements are invalid)r.   r-   Ú
isinstanceÚlistr   r/   r2   r   Úcannot_convertr>   r
   r?   r@   r1   Ú
setdefaultr   r0   r   r   ÚparentÚendswithr   )r*   r3   r4   r:   r6   r;   Únew_namer"   ÚmodulesÚmod_dictr#   Zas_nameÚmember_nameZ	new_nodesZindentationÚfirstrB   r+   Zeltsr7   ÚeltÚnewÚnodesÚnew_noder$   r$   r%   Útransform_member\   sh    







zFixUrllib.transform_memberc             C   s€   |  d¡}|  d¡}d}t|tƒr*|d }x*t|j D ]}|j|d kr6|d }P q6W |rp| t||jd¡ n|  |d¡ dS )z.Transform for calls to module members in code.Úbare_with_attrr;   Nr   r   )r-   z!This is an invalid module element)	r.   rC   rD   r   r/   r2   r   r-   rE   )r*   r3   r4   Z
module_dotr;   rI   r"   r$   r$   r%   Útransform_dot¨   s    


zFixUrllib.transform_dotc             C   sz   |  d¡r|  ||¡ n^|  d¡r0|  ||¡ nF|  d¡rH|  ||¡ n.|  d¡r`|  |d¡ n|  d¡rv|  |d¡ d S )Nr+   r:   rS   Zmodule_starzCannot handle star imports.Z	module_asz#This module is now multiple modules)r.   r9   rR   rT   rE   )r*   r3   r4   r$   r$   r%   Ú	transform¹   s    




zFixUrllib.transformN)Ú__name__Ú
__module__Ú__qualname__r&   r9   rR   rT   rU   r$   r$   r$   r%   r'   G   s
   Lr'   N)Ú__doc__Zlib2to3.fixes.fix_importsr   r   Zlib2to3.fixer_utilr   r   r   r   r   r	   r
   r   r1   r&   r'   r$   r$   r$   r%   Ú<module>   s@   $
