�`^c@ssdZddlmZmZddlmZddlmZmZm Z m
Z
mZmZm
Z
iddddd d
ddd
gfddddddddddddddddgfddgfgd 6dd
d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7gfdd8d9gfgd:6Zed:jed d;�d<�Zd=efd>��YZd?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(tNametCommat
FromImporttNewlinetfind_indentationtNodetsymssurllib.requestt URLopenertFancyURLopenerturlretrievet
_urlopenerturlopent
urlcleanuptpathname2urlturl2pathnamesurllib.parsetquotet
quote_plustunquotetunquote_plust urlencodet splitattrt splithostt
splitnporttsplitpasswdt splitportt
splitquerytsplittagt splittypet splitusert
splitvaluesurllib.errortContentTooShortErrorturllibtinstall_openertbuild_openertRequesttOpenerDirectortBaseHandlertHTTPDefaultErrorHandlertHTTPRedirectHandlertHTTPCookieProcessortProxyHandlertHTTPPasswordMgrtHTTPPasswordMgrWithDefaultRealmtAbstractBasicAuthHandlertHTTPBasicAuthHandlertProxyBasicAuthHandlertAbstractDigestAuthHandlertHTTPDigestAuthHandlertProxyDigestAuthHandlertHTTPHandlertHTTPSHandlertFileHandlert
FTPHandlertCacheFTPHandlertUnknownHandlertURLErrort HTTPErrorturllib2iccs�t�}x�tj�D]w\}}xh|D]`}|\}}t|�}d||fVd|||fVd|Vd|Vd||fVq)WqWdS(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* >) >
sIimport_from< 'from' module_star=%r 'import' star='*' >
stimport_name< 'import'
dotted_as_name< module_as=%r 'as' any > >
sKpower< bare_with_attr=%r trailer< '.' member=%s > any* >
(tsettMAPPINGtitemsR(tbaret
old_moduletchangestchanget
new_moduletmembers((s./sys/lib/python2.7/lib2to3/fixes/fix_urllib.pyt
build_pattern1s
t FixUrllibcBs5eZd�Zd�Zd�Zd�Zd�ZRS(cCsdjt��S(Nt|(tjoinRF(tself((s./sys/lib/python2.7/lib2to3/fixes/fix_urllib.pyRFJscCs�|jd�}|j}g}x?t|jd D],}|jt|dd|�t�g�q0W|jtt|jddd|��|j|�dS(s�Transform for the basic import case. Replaces the old
import name with a comma separated list of its
replacements.
tmodulei�itprefixN( tgetRLR>tvaluetextendRRtappendtreplace(RJtnodetresultst
import_modtpreftnamestname((s./sys/lib/python2.7/lib2to3/fixes/fix_urllib.pyttransform_importMs *(cCs�|jd�}|j}|jd�}|r�t|t�rI|d}nd
}x6t|jD]'}|j|dkr]|d}Pq]q]W|r�|jt|d|��q�j |d�n/g}i} |d}
x�|
D]�}|j
tjkr|j
dj}|j
dj}n|j}d
}|d kr�xlt|jD]Z}||dkr>|d| krx|j|d�n| j|dg�j|�q>q>Wq�q�Wg}
t|�}t}d
�}x�|D]�}| |}g}x8|d D],}|j|||��|jt��q�|j||d|��t||�}|sa|jjj|�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_membertmemberiiRLs!This is an invalid module elementREiu,cSsz|jtjkrdt|jdjd|�|jdj�|jdj�g}ttj|�gSt|jd|�gS(NiRLii(ttypeR timport_as_nameRtchildrenRNtcloneR(RWRLtkids((s./sys/lib/python2.7/lib2to3/fixes/fix_urllib.pythandle_name�si�sAll module elements are invalidN(RMRLt
isinstancetlisttNoneR>RNRQRtcannot_convertR[R R\R]RPt
setdefaultRtTrueRORRtparenttendswithtFalseR(RJRRRSRYRURZtnew_nameRCtmodulestmod_dictREtas_nametmember_namet new_nodestindentationtfirstR`RKteltsRVtelttnewtnodestnew_node((s./sys/lib/python2.7/lib2to3/fixes/fix_urllib.pyttransform_member]sh
+
cCs�|jd�}|jd�}d}t|t�r@|d}nx6t|jD]'}|j|dkrN|d}PqNqNW|r�|jt|d|j��n|j |d�dS(s.Transform for calls to module members in code.tbare_with_attrRZiiRLs!This is an invalid module elementN(
RMRcRaRbR>RNRQRRLRd(RJRRRSt
module_dotRZRjRC((s./sys/lib/python2.7/lib2to3/fixes/fix_urllib.pyt
transform_dot�s
cCs�|jd�r"|j||�n�|jd�rD|j||�nf|jd�rf|j||�nD|jd�r�|j|d�n"|jd�r�|j|d�ndS(NRKRYRxtmodule_starsCannot handle star imports.t module_ass#This module is now multiple modules(RMRXRwRzRd(RJRRRS((s./sys/lib/python2.7/lib2to3/fixes/fix_urllib.pyt transform�s(t__name__t
__module__RFRXRwRzR}(((s./sys/lib/python2.7/lib2to3/fixes/fix_urllib.pyRGHs
L N(t__doc__tlib2to3.fixes.fix_importsRRtlib2to3Rtlib2to3.fixer_utilRRRRRRR R>RPRFRG(((s./sys/lib/python2.7/lib2to3/fixes/fix_urllib.pyt<module>sD4
|