o
    bc                      @   s   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d ZG d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                  c   sx    t  } t D ]1\}}|D ]*}|\}}t|}d||f V  d|||f V  d| V  d| V  d||f V  qqd S )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* >
                  )setMAPPINGitemsr   )bare
old_modulechangeschange
new_modulemembers rI   //usr/lib/python3.10/lib2to3/fixes/fix_urllib.pybuild_pattern0   s.   rK   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )	FixUrllibc                 C   s   d t S )N|)joinrK   )selfrI   rI   rJ   rK   I   s   zFixUrllib.build_patternc                 C   sv   | d}|j}g }t|j dd D ]}|t|d |dt g q|tt|j d 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)	getrS   rA   valueextendr   r   appendreplace)rO   noderesults
import_modprefnamesnamerI   rI   rJ   transform_importL   s   
 zFixUrllib.transform_importc                 C   s  | d}|j}| d}|rDt|tr|d }d}t|j D ]}|j|d v r.|d } nq|r<|t||d dS | |d dS g }i }	|d }
|
D ]D}|j	t
jkrc|jd	 j}|jd j}n|j}d}|d
krt|j D ] }||d v r|d |	vr||d  |	|d g | qqqNg }t|}d}dd }|D ]A}|	| }g }|dd D ]}|||| |t  q|||d | t||}|r|jj|r||_|| d}q|rg }|dd D ]
}||t g q||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?   rR   !This is an invalid module elementrH      ,Tc                 S   sX   | j tjkr$t| jd j|d| jd  | jd  g}ttj|gS t| j|dgS )Nr   rR   r?   rc   )typer
   import_as_namer   childrenrU   cloner	   )r^   rS   kidsrI   rI   rJ   handle_name   s   z/FixUrllib.transform_member.<locals>.handle_namerQ   FzAll module elements are invalid)rT   rS   
isinstancelistrA   rU   rX   r   cannot_convertre   r
   rf   rg   rW   
setdefaultr   rV   r   r   parentendswithr   )rO   rY   rZ   r`   r\   ra   new_namerF   modulesmod_dictrH   as_namemember_name	new_nodesindentationfirstrj   rP   eltsr]   eltnewnodesnew_noderI   rI   rJ   transform_member\   sl   




zFixUrllib.transform_memberc                 C   s   | d}| d}d}t|tr|d }t|j D ]}|j|d v r)|d } nq|r8|t||jd dS | |d dS )z.Transform for calls to module members in code.bare_with_attrra   Nr   r?   rR   rb   )	rT   rk   rl   rA   rU   rX   r   rS   rm   )rO   rY   rZ   
module_dotra   rq   rF   rI   rI   rJ   transform_dot   s   


zFixUrllib.transform_dotc                 C   s   | dr| || d S | dr| || d S | dr'| || d S | dr4| |d d S | drA| |d d S d S )NrP   r`   r   module_starzCannot handle star imports.	module_asz#This module is now multiple modules)rT   r_   r~   r   rm   )rO   rY   rZ   rI   rI   rJ   	transform   s   




zFixUrllib.transformN)__name__
__module____qualname__rK   r_   r~   r   r   rI   rI   rI   rJ   rL   G   s    LrL   N)__doc__lib2to3.fixes.fix_importsr   r   lib2to3.fixer_utilr   r   r   r   r   r	   r
   rA   rW   rK   rL   rI   rI   rI   rJ   <module>   s0    $!