
    daf                          d Z ddlmZmZ ddlmZmZmZmZm	Z	m
Z
mZ dg dfdg dfdd	gfgdg d
fdddgfgdZed   j                  ed   d          d Z G d de      Zy)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)NameComma
FromImportNewlinefind_indentationNodesymszurllib.request)		URLopenerFancyURLopenerurlretrieve
_urlopenerurlopen
urlcleanuppathname2urlurl2pathname
getproxieszurllib.parse)quote
quote_plusunquoteunquote_plus	urlencode	splitattr	splithost
splitnportsplitpasswd	splitport
splitquerysplittag	splittype	splituser
splitvaluezurllib.errorContentTooShortError)r   install_openerbuild_openerRequestOpenerDirectorBaseHandlerHTTPDefaultErrorHandlerHTTPRedirectHandlerHTTPCookieProcessorProxyHandlerHTTPPasswordMgrHTTPPasswordMgrWithDefaultRealmAbstractBasicAuthHandlerHTTPBasicAuthHandlerProxyBasicAuthHandlerAbstractDigestAuthHandlerHTTPDigestAuthHandlerProxyDigestAuthHandlerHTTPHandlerHTTPSHandlerFileHandler
FTPHandlerCacheFTPHandlerUnknownHandlerURLError	HTTPError)urlliburllib2r?   r>      c            	   #      K   t               } t        j                         D ]N  \  }}|D ]D  }|\  }}t        |      }d|d|d d|d|d|d d|z   d	|z   d
|d|d F P y w)Nzimport_name< 'import' (module=zB
                                  | dotted_as_names< any* module=z any* >) >
                  zimport_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 > >
                  zpower< bare_with_attr=z trailer< '.' member=z > any* >
                  )setMAPPINGitemsr   )bare
old_modulechangeschange
new_modulememberss         3/root/Python-3.12.4/Lib/lib2to3/fixes/fix_urllib.pybuild_patternrL   0   s     5D&}} .
G 	.F"(J )G $Z1 1 $Wg7 7"# #"# #
 $W. .!	..s   A1A3c                   *    e Zd Zd Zd Zd Zd Zd Zy)	FixUrllibc                 4    dj                  t                     S )N|)joinrL   )selfs    rK   rL   zFixUrllib.build_patternI   s    xx((    c                 R   |j                  d      }|j                  }g }t        |j                     dd D ]+  }|j	                  t        |d   |      t               g       - |j                  t        t        |j                     d   d   |             |j                  |       y)zTransform for the basic import case. Replaces the old
           import name with a comma separated list of its
           replacements.
        moduleNr   prefix)	getrX   rC   valueextendr   r   appendreplace)rR   noderesults
import_modprefnamesnames          rK   transform_importzFixUrllib.transform_importL   s    
 [[*
   J,,-cr2 	@DLL$tAwt4eg>?	@T'*"2"23B7:4HI5!rS   c                 D   |j                  d      }|j                  }|j                  d      }|ryt        |t              r|d   }d}t        |j
                     D ]  }|j
                  |d   v s|d   } n |r|j                  t        ||             y| j                  |d       yg }i }	|d   }
|
D ]  }|j                  t        j                  k(  r3|j                  d	   j
                  }|j                  d   j
                  }n|j
                  }d}|d
k7  sgt        |j
                     D ]I  }||d   v s|d   |	vr|j                  |d          |	j                  |d   g       j                  |       K  g }t        |      }d}d }|D ]  }|	|   }g }|dd D ]3  }|j!                   |||             |j                  t#                      5 |j!                   ||d   |             t%        ||      }|r%|j&                  j                  j)                  |      r||_        |j                  |       d} |rMg }|dd D ]  }|j!                  |t+               g        |j                  |d          |j                  |       y| j                  |d       y)zTransform for imports of specific module elements. Replaces
           the module to be imported from with the appropriate new
           module.
        
mod_membermemberr   Nr@   rW   !This is an invalid module elementrJ      ,Tc                 \   | j                   t        j                  k(  rxt        | j                  d   j
                  |      | j                  d   j                         | j                  d   j                         g}t        t        j                  |      gS t        | j
                  |      gS )Nr   rW   r@   ri   )typer   import_as_namer   childrenrZ   cloner
   )rc   rX   kidss      rK   handle_namez/FixUrllib.transform_member.<locals>.handle_name   s    99 3 33 q!1!7!7G MM!,224 MM!,2246D !!4!4d;<<TZZ788rS   rV   FzAll module elements are invalid)rY   rX   
isinstancelistrC   rZ   r]   r   cannot_convertrl   r   rm   rn   r\   
setdefaultr	   r[   r   r   parentendswithr   )rR   r^   r_   rf   ra   rg   new_namerH   modulesmod_dictrJ   as_namemember_name	new_nodesindentationfirstrq   rU   eltsrb   eltnewnodesnew_nodes                           rK   transform_memberzFixUrllib.transform_member\   s   
 [[.
  X& &$'H!*"2"23 <<6!9,%ayH ""4#>?##D*MN
 GHi(G! N;;$"5"55$ooa066G"(//!"4":":K"(,,K"G#%")**:*:"; N&&)3%ay8 'vay 9$//q	2>EEfM	NN I*40KE9 " '9 *CLLS$!78LL)* [b489 / 2 2 ; ;K H!,CJ  %  )#2 8HLL(GI!678Yr]+U###D*KLrS   c                 L   |j                  d      }|j                  d      }d}t        |t              r|d   }t        |j                     D ]  }|j                  |d   v s|d   } n |r'|j                  t        ||j                               y| j                  |d       y)z.Transform for calls to module members in code.bare_with_attrrg   Nr   r@   rW   rh   )	rY   rr   rs   rC   rZ   r]   r   rX   rt   )rR   r^   r_   
module_dotrg   rx   rH   s          rK   transform_dotzFixUrllib.transform_dot   s    [[!12
X&fd#AYFj../ 	F||vay(!!9	 tH+5+<+< > ? &IJrS   c                 l   |j                  d      r| j                  ||       y |j                  d      r| j                  ||       y |j                  d      r| j                  ||       y |j                  d      r| j	                  |d       y |j                  d      r| j	                  |d       y y )NrU   rf   r   module_starzCannot handle star imports.	module_asz#This module is now multiple modules)rY   rd   r   r   rt   )rR   r^   r_   s      rK   	transformzFixUrllib.transform   s    ;;x !!$0[[&!!$0[[)*tW-[['&CD[[%&KL &rS   N)__name__
__module____qualname__rL   rd   r   r   r    rS   rK   rN   rN   G   s     )" JMXK"MrS   rN   N)__doc__lib2to3.fixes.fix_importsr   r   lib2to3.fixer_utilr   r   r   r   r	   r
   r   rC   r\   rL   rN   r   rS   rK   <module>r      s    => > > "CD  ?@
  +,./ "'(  -/B 	   '(+A. /..}M
 }MrS   