3
‡ŒðiD  ã               @   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rdxt|dƒs6|jd }q W | j|jƒrÌd|j |_|jƒ  t	d|ƒ nhd}d}x$t
|ƒD ]}| j|ƒrŠd}qvd}qvW |rª|r¦| j|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   úG/tmp/pip-build-6m2fasei/future/libfuturize/fixes/fix_absolute_import.pyÚ	transform   s0    

zFixAbsoluteImport.transformc             C   sx   |j dƒrdS |jddƒd }t| jƒ}t||ƒ}ttt|ƒdƒƒsHdS x*dtddd	d
dgD ]}t|| ƒr\dS q\W d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   