KMa @stdZddlmZmZddlmZddlmZmZm Z m Z m Z m Z m Z ddddd d d d d dgfddddddddddddddddgfdd gfgd!dd d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8gfdd9d:gfgiZed!jedd;d<d=ZGd>d?d?eZd@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) fixer_base)NameComma FromImportNewlinefind_indentationNodesymsZurllibzurllib.requestZ URLopenerZFancyURLopenerZ urlretrieveZ _urlopenerZurlopenZ urlcleanupZ pathname2urlZ url2pathnamez urllib.parseZquoteZ quote_plusZunquoteZ unquote_plusZ urlencodeZ splitattrZ splithostZ splitnportZ splitpasswdZ splitportZ splitqueryZsplittagZ splittypeZ splituserZ splitvaluez urllib.errorZContentTooShortErrorZurllib2Zinstall_openerZ build_openerZRequestZOpenerDirectorZ BaseHandlerZHTTPDefaultErrorHandlerZHTTPRedirectHandlerZHTTPCookieProcessorZ ProxyHandlerZHTTPPasswordMgrZHTTPPasswordMgrWithDefaultRealmZAbstractBasicAuthHandlerZHTTPBasicAuthHandlerZProxyBasicAuthHandlerZAbstractDigestAuthHandlerZHTTPDigestAuthHandlerZProxyDigestAuthHandlerZ HTTPHandlerZ HTTPSHandlerZ FileHandlerZ FTPHandlerZCacheFTPHandlerZUnknownHandlerZURLErrorZ HTTPErrorccst}xtjD]w\}}xh|D]`}|\}}t|}d||fVd|||fVd|Vd|Vd||fVq)WqWdS)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* > )setMAPPINGitemsr)ZbareZ old_moduleZchangeschangeZ new_modulemembersr=/opt/alt/python35/lib64/python3.5/lib2to3/fixes/fix_urllib.py build_pattern1s      rc@sLeZdZddZddZddZddZd d Zd S) FixUrllibcCsdjtS)N|)joinr)selfrrrrJszFixUrllib.build_patterncCs|jd}|j}g}xEt|jddD],}|jt|dd|tgq6W|jtt|jddd||j|dS)zTransform for the basic import case. Replaces the old import name with a comma separated list of its replacements. moduleNr rprefixr) getrrvalueextendrrappendreplace)rnoderesultsZ import_modprefnamesnamerrrtransform_importMs *(zFixUrllib.transform_importcCs|jd}|j}|jd}|rt|trF|d}d}x3t|jD]$}|j|dkrZ|d}PqZW|r|jt|d|q|j|dn2g}i} |d} x| D]}|j t j kr|j d j} |j dj} n|j} d} | d krxct|jD]T}| |dkr8|d| kro|j |d| j|dgj |q8WqWg} t|}d }d d }x|D]}| |}g}x>|ddD],}|j||||j tqW|j||d|t||}| s[|jjj|rd||_| j |d}qW| rg}x.| ddD]}|j|tgqW|j | d|j|n|j|ddS)zTransform for imports of specific module elements. Replaces the module to be imported from with the appropriate new module. mod_membermemberrNr rz!This is an invalid module elementr,TcSsz|jtjkrdt|jdjd||jdj|jdjg}ttj|gSt|jd|gS)Nrrr r))typer import_as_namerchildrenrZcloner )r%rZkidsrrr handle_names z/FixUrllib.transform_member..handle_nameFzAll module elements are invalidrrrr)rr isinstancelistrrr rcannot_convertr+r r,r-r setdefaultr rrrparentendswithr)rr!r"r'r#r(new_namermodulesZmod_dictrZas_nameZ member_nameZ new_nodesZ indentationfirstr.rZeltsr$ZeltnewZnodesZnew_noderrrtransform_member]sh       %       zFixUrllib.transform_membercCs|jd}|jd}d}t|tr=|d}x3t|jD]$}|j|dkrK|d}PqKW|r|jt|d|jn|j|ddS)z.Transform for calls to module members in code.bare_with_attrr(Nrr rz!This is an invalid module element) rr/r0rrr rrr1)rr!r"Z module_dotr(r5rrrr transform_dots  zFixUrllib.transform_dotcCs|jdr"|j||n|jdrD|j||nc|jdrf|j||nA|jdr|j|dn|jdr|j|ddS)Nrr'r:Z module_starzCannot handle star imports.Z module_asz#This module is now multiple modules)rr&r9r;r1)rr!r"rrr transformszFixUrllib.transformN)__name__ __module__ __qualname__rr&r9r;r<rrrrrHs    L rN)__doc__Zlib2to3.fixes.fix_importsrrZlib2to3rZlib2to3.fixer_utilrrrrr r r rrrrrrrrsF4