U
    —Ð~dD  ã                   @   sd   d Z ddlmZmZmZmZ ddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ G dd„ deƒZd	S )
a¶  
Fixer for import statements, with a __future__ import line.

Based on lib2to3/fixes/fix_import.py, but extended slightly so it also
supports Cython modules.

If spam is being imported from the local directory, this import:
    from spam import eggs
becomes:
    from __future__ import absolute_import
    from .spam import eggs

and this import:
    import spam
becomes:
    from __future__ import absolute_import
    from . import spam
é    )ÚdirnameÚjoinÚexistsÚsep)Ú	FixImport)Ú
FromImportÚsyms)Útraverse_imports)Úfuture_importc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚFixAbsoluteImporté	   c                 C   sÈ   | j r
dS |d }|jtjkr`t|dƒs4|jd }q|  |j¡rÄd|j |_| ¡  t	d|ƒ ndd}d}t
|ƒD ]}|  |¡r„d}qpd}qp|r¢|rž|  |d	¡ dS td|gƒ}|j|_t	d|ƒ |S dS )
zÅ
        Copied from FixImport.transform(), but with this line added in
        any modules that had implicit relative imports changed:

            from __future__ import absolute_import"
        NÚimpÚvaluer   Ú.Úabsolute_importFTz#absolute and local imports together)ÚskipÚtyper   Zimport_fromÚhasattrÚchildrenÚprobably_a_local_importr   Úchangedr
   r	   Úwarningr   Úprefix)ÚselfÚnodeÚresultsr   Z
have_localZhave_absoluteÚmod_nameÚnew© r   úb/var/www/html/myproject/myenv/lib/python3.8/site-packages/libfuturize/fixes/fix_absolute_import.pyÚ	transform   s0    


zFixAbsoluteImport.transformc                 C   sv   |  d¡rdS | dd¡d }t| jƒ}t||ƒ}ttt|ƒdƒƒsHdS dtddd	d
dfD ]}t|| ƒrZ dS qZdS )zq
        Like the corresponding method in the base class, but this also
        supports Cython modules.
        r   Fé   r   z__init__.pyz.pyz.pycz.soz.slz.pydz.pyxT)Ú
startswithÚsplitr   Úfilenamer   r   r   )r   Zimp_nameÚ	base_pathÚextr   r   r   r   I   s    


z)FixAbsoluteImport.probably_a_local_importN)Ú__name__Ú
__module__Ú__qualname__Z	run_orderr    r   r   r   r   r   r      s   *r   N)Ú__doc__Úos.pathr   r   r   r   Zlib2to3.fixes.fix_importr   Zlib2to3.fixer_utilr   r   r	   Zlibfuturize.fixer_utilr
   r   r   r   r   r   Ú<module>   s   