
    ZQd                          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                             ed         d                    d Z G d de          ZdS )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                                          D ]P\  }}|D ]H}|\  }}t          |          }d|d|dV  d|d|d|dV  d|z  V  d	|z  V  d
|d|dV  IQd S )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         //usr/lib/python3.11/lib2to3/fixes/fix_urllib.pybuild_patternrL   0   s     55D&}} . .
G 	. 	.F"(J ))GG $ZZZ1 1 1 1 1 $WWWggg7 7 7 7"# # # #"# # # # #
 $WWW. . . . .!	.. .    c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )	FixUrllibc                 D    d                     t                                S )N|)joinrL   )selfs    rK   rL   zFixUrllib.build_patternI   s    xx(((rM   c                    |                     d          }|j        }g }t          |j                 dd         D ]:}|                    t          |d         |          t                      g           ;|                    t          t          |j                 d         d         |                     |                    |           dS )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)rS   noderesults
import_modprefnamesnames          rK   transform_importzFixUrllib.transform_importL   s    
 [[**
  J,-crc2 	@ 	@DLL$tAwt444egg>????T'*"23B7:4HHHIII5!!!!!rM   c                    |                     d          }|j        }|                     d          }|rt          |t                    r|d         }d}t          |j                 D ]}|j        |d         v r
|d         } n|r&|                    t          ||                     dS |                     |d           dS g }i }	|d         }
|
D ]}|j	        t          j        k    r%|j        d	         j        }|j        d         j        }n	|j        }d}|d
k    rst          |j                 D ]`}||d         v rT|d         |	vr|                    |d                    |	                    |d         g                               |           ag }t          |          }d}d }|D ]}|	|         }g }|dd         D ]B}|                     |||                     |                    t#                                 C|                     ||d         |                     t%          ||          }|r|j        j                            |          r||_        |                    |           d}|rdg }|dd         D ]%}|                    |t+                      g           &|                    |d                    |                    |           dS |                     |d           dS )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                 L   | j         t          j        k    ryt          | j        d         j        |          | j        d                                         | j        d                                         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    9 333 q!1!7GGG M!,2244 M!,22446D !!4d;;<<TZ77788rM   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   )rS   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&&  @	M&$'' #H!*"23  <6!9,,%ayHE -  O""4#>#>#>?????##D*MNNNNN
 GHi(G! N N;$"555$oa06G"(/!"4":KK"(,K"G#%%")**:"; N N&&)33%ay88 'vay 9 9 9$//q	2>>EEfMMMI*400KE9 9 9 "  '9 * *CLLS$!7!7888LL))))[[b488999 // - 2 ; ;K H H -!,CJ  %%% M )#2# 8 8HLL(GII!67777Yr]+++U#######D*KLLLLLrM   c                 z   |                     d          }|                     d          }d}t          |t                    r|d         }t          |j                 D ]}|j        |d         v r
|d         } n|r+|                    t          ||j                             dS |                     |d           dS )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   )rS   r^   r_   
module_dotrg   rx   rH   s          rK   transform_dotzFixUrllib.transform_dot   s    [[!122
X&&fd## 	AYFj./ 	 	F|vay((!!9 )  	KtH+5+< >  >  > ? ? ? ? ? &IJJJJJrM   c                    |                     d          r|                     ||           d S |                     d          r|                     ||           d S |                     d          r|                     ||           d S |                     d          r|                     |d           d S |                     d          r|                     |d           d S d S )NrU   rf   r   module_starzCannot handle star imports.	module_asz#This module is now multiple modules)rY   rd   r   r   rt   )rS   r^   r_   s      rK   	transformzFixUrllib.transform   s   ;;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 	MrM   N)__name__
__module____qualname__rL   rd   r   r   r    rM   rK   rO   rO   G   sn        ) ) )" " " JM JM JMXK K K"M M M M MrM   rO   N)__doc__lib2to3.fixes.fix_importsr   r   lib2to3.fixer_utilr   r   r   r   r	   r
   r   rC   r\   rL   rO   r   rM   rK   <module>r      s    = < < < < < < <> > > > > > > > > > > > > > > > > > "C C CD  ? ? ?@
  +,./ "' ' '(  -/ B 	   '(+A. / / /. . ..}M }M }M }M }M
 }M }M }M }M }MrM   