Your IP : 3.146.37.242
o
6��f� � @ s� d Z ddlmZmZ ddlmZmZmZmZm Z m
Z
mZ dg d�fdg d�fdd gfgdg d
�fdddgfgd
�Zed �
ed d � dd� ZG dd� de�ZdS )z�Fix 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�symszurllib.request) Z URLopenerZFancyURLopenerZurlretrieveZ
_urlopener�urlopenZ
urlcleanupZpathname2urlZurl2pathnameZ
getproxieszurllib.parse)ZquoteZ
quote_plusZunquoteZunquote_plusZ urlencodeZ splitattrZ splithostZ
splitnportZsplitpasswdZ splitportZ
splitqueryZsplittagZ splittypeZ splituserZ
splitvaluezurllib.errorZContentTooShortError)r Zinstall_openerZbuild_openerZRequestZOpenerDirectorZBaseHandlerZHTTPDefaultErrorHandlerZHTTPRedirectHandlerZHTTPCookieProcessorZProxyHandlerZHTTPPasswordMgrZHTTPPasswordMgrWithDefaultRealmZAbstractBasicAuthHandlerZHTTPBasicAuthHandlerZProxyBasicAuthHandlerZAbstractDigestAuthHandlerZHTTPDigestAuthHandlerZProxyDigestAuthHandlerZHTTPHandlerZHTTPSHandlerZFileHandlerZ
FTPHandlerZCacheFTPHandlerZUnknownHandlerZURLErrorZ 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 qqd S )Nz�import_name< 'import' (module=%r
| dotted_as_names< any* module=%r any* >) >
z�import_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 )ZbareZ
old_moduleZchanges�changeZ
new_module�members� r �?/opt/alt/python310/lib64/python3.10/lib2to3/fixes/fix_urllib.py�
build_pattern0 s. ��������r c @ s4 e Zd Zdd� Zdd� Zdd� Zdd� Zd d
� ZdS )� FixUrllibc C s d� t� �S )N�|)�joinr )�selfr r r r I s zFixUrllib.build_patternc C sv |� d�}|j}g }t|j dd� D ]}|�t|d |d�t� g� q|�tt|j d d |d�� |�|� dS )z�Transform for the basic import case. Replaces the old
import name with a comma separated list of its
replacements.
�moduleN���r ��prefix) �getr r �value�extendr r �append�replace)r �node�resultsZ
import_mod�pref�names�namer r r �transform_importL s
zFixUrllib.transform_importc C s |� d�}|j}|� d�}|rDt|t�r|d }d}t|j D ]}|j|d v r.|d } nq|r<|�t||d�� dS | �|d� dS g }i } |d }
|
D ]D}|j t
jkrc|jd j}|jd j}n|j}d}|d
kr�t|j D ] }||d v r�|d | vr�|�
|d � | �|d g ��
|� qqqNg }
t|�}d}dd
� }|D ]A}| | }g }|dd� D ]}|�|||�� |�
t� � q�|�||d |�� t||�}|r�|jj�|�r�||_|
�
|� d}q�|
�rg }|
dd� D ]
}|�|t� g� q�|�
|
d � |�|� dS | �|d� dS )z�Transform for imports of specific module elements. Replaces
the module to be imported from with the appropriate new
module.
�
mod_member�memberr Nr r �!This is an invalid module elementr � �,Tc S sX | j tjkr$t| jd j|d�| jd �� | jd �� g}ttj|�gS t| j|d�gS )Nr r r r- )�typer
�import_as_namer �childrenr Zcloner )r( r Zkidsr r r �handle_name� s �z/FixUrllib.transform_member.<locals>.handle_namer FzAll module elements are invalid)r r �
isinstance�listr r r# r �cannot_convertr/ r
r0 r1 r"