o bc @sdZddlmZmZddlmZmZmZmZm Z m Z m Z dgdfdgdfdd gfgdgd fdd d gfgd Z e d e ddddZGdddeZdS)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=ccsxt}tD]1\}}|D]*}|\}}t|}d||fVd|||fVd|Vd|Vd||fVqqdS)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)bare old_modulechangeschange new_modulemembersrI//usr/lib/python3.10/lib2to3/fixes/fix_urllib.py build_pattern0s.rKc@s4eZdZddZddZddZddZd d Zd S) FixUrllibcCs dtS)N|)joinrK)selfrIrIrJrKIs zFixUrllib.build_patterncCsv|d}|j}g}t|jddD]}|t|d|dtgq|tt|jdd|d||dS)zTransform for the basic import case. Replaces the old import name with a comma separated list of its replacements. moduleNrprefix) getrSrAvalueextendrrappendreplace)rOnoderesults import_modprefnamesnamerIrIrJtransform_importLs  zFixUrllib.transform_importcCs|d}|j}|d}|rDt|tr|d}d}t|jD]}|j|dvr.|d}nq|r<|t||ddS||ddSg}i} |d} | D]D}|j t j krc|j d j} |j dj} n|j} d} | d krt|jD] }| |dvr|d| vr| |d| |dg |qqqNg} t|}d }d d }|D]A}| |}g}|ddD]}||||| tq|||d|t||}|r|jj|r||_| |d}q| rg}| ddD] }||tgq| | d||dS||ddS)zTransform for imports of specific module elements. Replaces the module to be imported from with the appropriate new module. mod_membermemberrNr?rR!This is an invalid module elementrH,TcSsX|jtjkr$t|jdj|d|jd|jdg}ttj|gSt|j|dgS)NrrRr?rc)typer import_as_namerchildrenrUcloner )r^rSkidsrIrIrJ handle_names   z/FixUrllib.transform_member..handle_namerQFzAll module elements are invalid)rTrS isinstancelistrArUrXrcannot_convertrer rfrgrW setdefaultrrVrrparentendswithr)rOrYrZr`r\ranew_namerFmodulesmod_dictrHas_name member_name new_nodes indentationfirstrjrPeltsr]eltnewnodesnew_noderIrIrJtransform_member\sl         zFixUrllib.transform_membercCs|d}|d}d}t|tr|d}t|jD]}|j|dvr)|d}nq|r8|t||jddS||ddS)z.Transform for calls to module members in code.bare_with_attrraNrr?rRrb) rTrkrlrArUrXrrSrm)rOrYrZ module_dotrarqrFrIrIrJ transform_dots    zFixUrllib.transform_dotcCs|dr |||dS|dr|||dS|dr'|||dS|dr4||ddS|drA||ddSdS)NrPr`r module_starzCannot handle star imports. module_asz#This module is now multiple modules)rTr_r~rrm)rOrYrZrIrIrJ transforms     zFixUrllib.transformN)__name__ __module__ __qualname__rKr_r~rrrIrIrIrJrLGs L rLN)__doc__lib2to3.fixes.fix_importsrrlib2to3.fixer_utilrrrrrr r rArWrKrLrIrIrIrJs0$ !