\d dZddlmZmZddlmZmZmZmZm Z m Z m Z dgdfdgdfdd gfgdgd fdd d gfgd Z e d e dddZGddeZdS)zFix 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.request) URLopenerFancyURLopener urlretrieve _urlopenerurlopen urlcleanup pathname2url url2pathname getproxiesz urllib.parse)quote quote_plusunquote unquote_plus urlencode splitattr splithost splitnport splitpasswd splitport splitquerysplittag splittype splituser splitvaluez urllib.errorContentTooShortError)rinstall_opener build_openerRequestOpenerDirector BaseHandlerHTTPDefaultErrorHandlerHTTPRedirectHandlerHTTPCookieProcessor ProxyHandlerHTTPPasswordMgrHTTPPasswordMgrWithDefaultRealmAbstractBasicAuthHandlerHTTPBasicAuthHandlerProxyBasicAuthHandlerAbstractDigestAuthHandlerHTTPDigestAuthHandlerProxyDigestAuthHandler HTTPHandler HTTPSHandler FileHandler FTPHandlerCacheFTPHandlerUnknownHandlerURLError HTTPError)urlliburllib2r?r>c #Kt}tD]P\}}|D]H}|\}}t|}d|d|dVd|d|d|dVd|zVd |zVd |d |d VIQdS) Nzimport_name< 'import' (module=zB | dotted_as_names< any* module=z any* >) > zimport_from< 'from' mod_member=z* 'import' ( member=z | import_as_name< member=z] '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 > > zpower< bare_with_attr=z trailer< '.' member=z > any* > )setMAPPINGitemsr)bare old_modulechangeschange new_modulememberss )..\python\lib\lib2to3\fixes\fix_urllib.py build_patternrL0s 55D&}}.. G . .F"( J ))GG$ZZZ1 1 1 1 1 $WWWggg7 7 7 7"# # # #"# # # # # $WWW. . . . .! ...c,eZdZdZdZdZdZdZdS) FixUrllibcDdtS)N|)joinrL)selfs rKrLzFixUrllib.build_patternIsxx (((rMc|d}|j}g}t|jddD]:}|t |d|t g;|t t|jdd|||dS)zTransform for the basic import case. Replaces the old import name with a comma separated list of its replacements. moduleNrprefix) getrXrCvalueextendrrappendreplace)rSnoderesults import_modprefnamesnames rKtransform_importzFixUrllib.transform_importLs [[**  J,-crc2 @ @D LL$tAwt444egg> ? ? ? ? T'*"23B7:4HHHIII5!!!!!rMc|d}|j}|d}|rt|tr|d}d}t|jD]}|j|dvr |d}n|r&|t||dS||ddSg}i} |d} | D]}|j tj kr%|j d j} |j dj} n |j} d} | d krst|jD]`}| |dvrT|d| vr| |d| |dg |ag} t|}d }d }|D]}| |}g}|dd D]B}||||| t#C|||d |t%||}|r|jj|r||_| |d}| rdg}| dd D]%}||t+g&| | d ||dS||ddS)zTransform for imports of specific module elements. Replaces the module to be imported from with the appropriate new module. mod_membermemberrNr@rW!This is an invalid module elementrJ,TcL|jtjkryt|jdj||jd|jdg}ttj|gSt|j|gS)NrrWr@ri)typer import_as_namerchildrenrZcloner )rcrXkidss rK handle_namez/FixUrllib.transform_member..handle_names9 333 q!1!7GGG M!,2244 M!,22446D!!4d;;<<TZ77788rMrVFzAll module elements are invalid)rYrX isinstancelistrCrZr]rcannot_convertrlr rmrnr\ setdefaultr r[rrparentendswithr)rSr^r_rfrargnew_namerHmodulesmod_dictrJas_name member_name new_nodes indentationfirstrqrUeltsrbeltnewnodesnew_nodes rKtransform_memberzFixUrllib.transform_member\s` [[..  X&& @ M&$'' #H!*"23  <6!9,,%ayHE- O""4#>#>#>?????##D*MNNNNN GHi(G! N N;$"555$oa06G"(/!"4":KK"(,K"G#%%")**:";NN&&)33%ay88 'vay 9 9 9$//q 2>>EEfMMMI*400KE 9 9 9"  '9**CLLS$!7!7888LL)))) [[b488999 //- 2 ; ;K H H-!,CJ  %%% M )#2#88HLL(GII!67777 Yr]+++ U#######D*KLLLLLrMcz|d}|d}d}t|tr|d}t|jD]}|j|dvr |d}n|r+|t ||jdS||ddS)z.Transform for calls to module members in code.bare_with_attrrgNrr@rWrh) rYrrrsrCrZr]rrXrt)rSr^r_ module_dotrgrxrHs rK transform_dotzFixUrllib.transform_dots[[!122 X&& fd # # AYFj./  F|vay((!!9)  K   tH+5+< > > > ? ? ? ? ?   &I J J J J JrMc|dr|||dS|dr|||dS|dr|||dS|dr||ddS|dr||ddSdS)NrUrfr module_starzCannot handle star imports. module_asz#This module is now multiple modules)rYrdrrrt)rSr^r_s rK transformzFixUrllib.transforms ;;x M  ! !$ 0 0 0 0 0 [[ & & M  ! !$ 0 0 0 0 0 [[) * * M   tW - - - - - [[ ' ' M   &C D D D D D [[ % % M   &K L L L L L M MrMN)__name__ __module__ __qualname__rLrdrrrrMrKrOrOGsn)))""" JMJMJMXKKK" M M M M MrMrON)__doc__lib2to3.fixes.fix_importsrrlib2to3.fixer_utilrrrrr r r rCr\rLrOrrMrKrs=<<<<<<<>>>>>>>>>>>>>>>>>>"CCCD ???@  +,. /" ' ' ' ( -/   B '(+A.///....}M}M}M}M}M }M}M}M}M}MrM