3 \ @sdZddlmZmZddlmZmZmZmZm Z m Z m Z dddddd d d d gfd dddddddddddddddgfddgfgdd dd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5gfdd6d7gfgd8Z e d9j e d:d;dd?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)NameComma FromImportNewlinefind_indentationNodesymszurllib.requestZ URLopenerZFancyURLopenerZ urlretrieveZ _urlopenerZurlopenZ urlcleanupZ pathname2urlZ url2pathnamez urllib.parseZquoteZ quote_plusZunquoteZ unquote_plusZ urlencodeZ splitattrZ splithostZ splitnportZ splitpasswdZ splitportZ splitqueryZsplittagZ splittypeZ splituserZ splitvaluez urllib.errorZContentTooShortErrorZinstall_openerZ build_openerZRequestZOpenerDirectorZ BaseHandlerZHTTPDefaultErrorHandlerZHTTPRedirectHandlerZHTTPCookieProcessorZ ProxyHandlerZHTTPPasswordMgrZHTTPPasswordMgrWithDefaultRealmZAbstractBasicAuthHandlerZHTTPBasicAuthHandlerZProxyBasicAuthHandlerZAbstractDigestAuthHandlerZHTTPDigestAuthHandlerZProxyDigestAuthHandlerZ HTTPHandlerZ HTTPSHandlerZ FileHandlerZ FTPHandlerZCacheFTPHandlerZUnknownHandlerZURLErrorZ HTTPError)urlliburllib2r r ccs~t}xrtjD]f\}}x\|D]T}|\}}t|}d||fVd|||fVd|Vd|Vd||fVqWqWdS)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"/usr/lib64/python3.6/fix_urllib.py build_pattern0s   rc@s4eZdZddZddZddZddZd d Zd S) FixUrllibcCs djtS)N|)joinr)selfrrrrIszFixUrllib.build_patterncCsz|jd}|j}g}x6t|jddD] }|jt|d|dtgq(W|jtt|jdd|d|j|dS)zTransform for the basic import case. Replaces the old import name with a comma separated list of its replacements. moduleNr r)prefixr) getrrvalueextendrrappendreplace)rnoderesultsZ import_modprefnamesnamerrrtransform_importLs   zFixUrllib.transform_importcCs>|jd}|j}|jd}|rt|tr0|d}d}x*t|jD]}|j|dkr@|d}Pq@W|rx|jt||dn |j|dng}i} |d} x| D]}|j t j kr|j d j} |j dj} n |j} d} | d krxPt|jD]B}| |dkr|d| kr|j |d| j|dgj |qWqWg} t|}d }d d }x|D]}| |}g}x2|ddD]"}|j||||j tqlW|j||d|t||}| s|jjj|r||_| j |d}qNW| r.g}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,TcSsX|jtjkrHt|jdj|d|jdj|jdjg}ttj|gSt|j|dgS)Nr)rr 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 setdefaultrrrrparentendswithr)rr"r#r(r$r)new_namermodulesZmod_dictrZas_name member_nameZ new_nodesZ indentationfirstr/rZeltsr%ZeltnewZnodesZnew_noderrrtransform_member\sh            zFixUrllib.transform_membercCs|jd}|jd}d}t|tr*|d}x*t|jD]}|j|dkr6|d}Pq6W|rp|jt||jdn |j|ddS)z.Transform for calls to module members in code.bare_with_attrr)Nrr )rz!This is an invalid module element) rr0r1rrr!rrr2)rr"r#Z module_dotr)r6rrrr transform_dots   zFixUrllib.transform_dotcCsz|jdr|j||n^|jdr0|j||nF|jdrH|j||n.|jdr`|j|dn|jdrv|j|ddS)Nrr(r<Z module_starzCannot handle star imports.Z module_asz#This module is now multiple modules)rr'r;r=r2)rr"r#rrr transforms     zFixUrllib.transformN)__name__ __module__ __qualname__rr'r;r=r>rrrrrGs LrN)__doc__Zlib2to3.fixes.fix_importsrrZlib2to3.fixer_utilrrrrrr r rr rrrrrrs@$