???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................3

  \                  @   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 jed: d;  d<d= ZG d>d? d?eZd@S )AzFix 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FancyURLopenerZurlretrieveZ
_urlopenerZurlopenZ
urlcleanupZpathname2urlZurl2pathnamezurllib.parseZquoteZ
quote_plusZunquoteZunquote_plusZ	urlencodeZ	splitattrZ	splithostZ
splitnportZsplitpasswdZ	splitportZ
splitqueryZsplittagZ	splittypeZ	splituserZ
splitvaluezurllib.errorZContentTooShortErrorZinstall_openerZbuild_openerZRequestZOpenerDirectorZBaseHandlerZHTTPDefaultErrorHandlerZHTTPRedirectHandlerZHTTPCookieProcessorZProxyHandlerZHTTPPasswordMgrZHTTPPasswordMgrWithDefaultRealmZAbstractBasicAuthHandlerZHTTPBasicAuthHandlerZProxyBasicAuthHandlerZAbstractDigestAuthHandlerZHTTPDigestAuthHandlerZProxyDigestAuthHandlerZHTTPHandlerZHTTPSHandlerZFileHandlerZ
FTPHandlerZCacheFTPHandlerZUnknownHandlerZURLErrorZ	HTTPError)urlliburllib2r   r      c              c   s~   t  } xrtj 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* >) >
                  zimport_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_moduleZchangeschangeZ
new_modulemembers r   0/usr/lib64/python3.6/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j t S )N|)joinr   )selfr   r   r   r   I   s    zFixUrllib.build_patternc             C   sz   |j d}|j}g }x6t|j dd D ] }|jt|d |dt g q(W |jtt|j d d |d |j| dS )zTransform for the basic import case. Replaces the old
           import name with a comma separated list of its
           replacements.
        moduleNr   r   )prefixr   )	getr   r   valueextendr   r   appendreplace)r   noderesultsZ
import_modprefnamesnamer   r   r   transform_importL   s    
  zFixUrllib.transform_importc             C   s>  |j d}|j}|j d}|rt|tr0|d }d}x*t|j D ]}|j|d kr@|d }P q@W |rx|jt||d n| j|d ng }i }	|d }
x|
D ]}|j	t
jkr|jd	 j}|jd j}n
|j}d}|d
krxPt|j D ]B}||d kr|d |	kr|j|d  |	j|d g j| qW qW g }t|}d}dd }x|D ]}|	| }g }x2|dd D ]"}|j||| |jt  qlW |j||d | t||}| s|jjj|r||_|j| d}qNW |r.g }x&|dd D ]}|j|t g qW |j|d  |j| n| j|d dS )zTransform 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 | jd j g}ttj|gS t| j|dgS )Nr   )r   r   r*   )typer
   import_as_namer   childrenr   Zcloner	   )r&   r   Zkidsr   r   r   handle_name   s    z/FixUrllib.transform_member.<locals>.handle_nameFzAll module elements are invalidr   r   r   r   )r   r   
isinstancelistr   r   r!   r   cannot_convertr,   r
   r-   r.   r    
setdefaultr   r   r   r   parentendswithr   )r   r"   r#   r(   r$   r)   new_namer   modulesZmod_dictr   Zas_namemember_nameZ	new_nodesZindentationfirstr/   r   Zeltsr%   ZeltnewZnodesZnew_noder   r   r   transform_member\   sh    







zFixUrllib.transform_memberc             C   s   |j d}|j d}d}t|tr*|d }x*t|j D ]}|j|d kr6|d }P q6W |rp|jt||jd n| j|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   r0   r1   r   r   r!   r   r   r2   )r   r"   r#   Z
module_dotr)   r6   r   r   r   r   transform_dot   s    


zFixUrllib.transform_dotc             C   sz   |j dr| j|| n^|j dr0| j|| nF|j drH| j|| n.|j dr`| j|d n|j drv| j|d d S )Nr   r(   r<   Zmodule_starzCannot handle star imports.Z	module_asz#This module is now multiple modules)r   r'   r;   r=   r2   )r   r"   r#   r   r   r   	transform   s    




zFixUrllib.transformN)__name__
__module____qualname__r   r'   r;   r=   r>   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   r    r   r   r   r   r   r   <module>   s@   $
