i f @svdZddlmZmZddlmZddlmZmZm Z m Z m Z m Z m Z iddddd d d d d gfddddddddddddddddgfddgfgd 6dd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7gfdd8d9gfgd:6Zed:jed d;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_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.errorZContentTooShortErrorZurllibZinstall_openerZ build_openerZRequestZOpenerDirectorZ BaseHandlerZHTTPDefaultErrorHandlerZHTTPRedirectHandlerZHTTPCookieProcessorZ ProxyHandlerZHTTPPasswordMgrZHTTPPasswordMgrWithDefaultRealmZAbstractBasicAuthHandlerZHTTPBasicAuthHandlerZProxyBasicAuthHandlerZAbstractDigestAuthHandlerZHTTPDigestAuthHandlerZProxyDigestAuthHandlerZ HTTPHandlerZ HTTPSHandlerZ FileHandlerZ FTPHandlerZCacheFTPHandlerZUnknownHandlerZURLErrorZ HTTPErrorZurllib2ccst}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/python34/lib64/python3.4/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|trI|d}nd}x6t|jD]'}|j|dkr]|d}Pq]q]W|r|jt|d|q|j|dn>g}i} |d} x| D]}|j t j kr|j d j} |j dj} n|j} d} | d krxlt|jD]Z}| |dkr>|d| krx|j |dn| j|dgj |q>q>WqqWg} t|}d }d d }x|D]}| |}g}x>|ddD],}|j||||j tqW|j||d|t||}| sj|jjj|rv||_n| 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}nx6t|jD]'}|j|dkrN|d}PqNqNW|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||nf|jdrf|j||nD|jdr|j|dn"|jdr|j|dndS)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 rrrrrrrrsD4