U
    ËZj   ã                   @   sP   d Z ddlmZ ddlmZmZ ddlmZmZm	Z	 ddiZ
G dd„ de	ƒZd	S )
zCFix UserDict.

Incomplete!

TODO: base this on fix_urllib perhaps?
é    )Ú
fixer_base)ÚNameÚ
attr_chain)Ú
alternatesÚbuild_patternÚ
FixImportsÚUserDictÚcollectionsc                       sT   e Zd ZdZdZeZdZdd„ Z‡ fdd„Z	‡ fdd„Z
‡ fd	d
„Zdd„ Z‡  ZS )ÚFixUserdictTé   c                 C   s   d  t| jƒ¡S )Nú|)Újoinr   Úmapping©Úself© r   úa/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/libfuturize/fixes/fix_UserDict.pyr   5   s    zFixUserdict.build_patternc                    s   |   ¡ | _tt| ƒ ¡  d S ©N)r   ZPATTERNÚsuperr   Úcompile_patternr   ©Ú	__class__r   r   r   8   s    
zFixUserdict.compile_patternc                    sH   t t| ƒj‰ ˆ |ƒ}|rDd|kr@t‡ fdd„t|dƒD ƒƒr@dS |S dS )NÚbare_with_attrc                 3   s   | ]}ˆ |ƒV  qd S r   r   )Ú.0Úobj©Úmatchr   r   Ú	<genexpr>F   s     z$FixUserdict.match.<locals>.<genexpr>ÚparentF)r   r   r   Úanyr   )r   ÚnodeÚresultsr   r   r   r   ?   s    ÿzFixUserdict.matchc                    s   t t| ƒ ||¡ i | _d S r   )r   r   Ú
start_treeÚreplace)r   ÚtreeÚfilenamer   r   r   r"   K   s    zFixUserdict.start_treec                 C   s¢   |  d¡}|rl|j}t| j| ƒ}| t||jd�¡ d|krH|| j|< d|krž|  |¡}|rž|  ||¡ n2|d d }| j  |j¡}|rž| t||jd�¡ d S )NÚmodule_name)ÚprefixZname_importZmultiple_importsr   r   )	ÚgetÚvalueÚunicoder   r#   r   r'   r   Ú	transform)r   r    r!   Z
import_modÚmod_nameÚnew_nameZ	bare_namer   r   r   r+   O   s    


zFixUserdict.transform)Ú__name__Ú
__module__Ú__qualname__ZBM_compatibleZkeep_line_orderÚMAPPINGr   Z	run_orderr   r   r   r"   r+   Ú__classcell__r   r   r   r   r
   *   s   r
   N)Ú__doc__Zlib2to3r   Zlib2to3.fixer_utilr   r   Zlib2to3.fixes.fix_importsr   r   r   r1   r
   r   r   r   r   Ú<module>   s
   	