ðÕYf¸ ã @ s} d Z d d l m Z d d l m Z m Z m Z m Z d d l m Z m
Z
m Z d d „ Z Gd d „ d e j
ƒ Z d
S)zÞFixer for import statements.
If spam is being imported from the local directory, this import:
from spam import eggs
Becomes:
from .spam import eggs
And this import:
import spam
Becomes:
from . import spam
é )Ú
fixer_baseé )ÚdirnameÚjoinÚexistsÚsep)Ú
FromImportÚsymsÚtokenc c sÝ | g } xÍ | rØ | j ƒ } | j t j k r; | j Vq | j t j k rn d j d d „ | j Dƒ ƒ Vq | j t j k r— | j
| j d ƒ q | j t j k rÉ | j | j d d d … ƒ q t
d ƒ ‚ q Wd S) zF
Walks over all the names imported in a dotted_as_names node.
Ú c S s g | ] } | j ‘ q S© )Úvalue)Ú.0Zchr r ú=/opt/alt/python35/lib64/python3.5/lib2to3/fixes/fix_import.pyú
s z$traverse_imports..r Nr zunknown node typeéþÿÿÿ)ÚpopÚtyper
ÚNAMEr
r Zdotted_namer ÚchildrenZdotted_as_nameÚappendZdotted_as_namesÚextendÚAssertionError)ÚnamesÚpendingÚnoder r r Útraverse_imports s ! r c sF e Z d Z d Z d Z ‡ f d d † Z d d „ Z d d „ Z ‡ S) Ú FixImportTzj
import_from< 'from' imp=any 'import' ['('] any [')'] >
|
import_name< 'import' imp=any >
c s/ t t | ƒ j | | ƒ d | j k | _ d S)NZabsolute_import)Úsuperr Ú
start_treeZfuture_featuresÚskip)ÚselfZtreeÚname)Ú __class__r r r / s zFixImport.start_treec C s | j r
d S| d } | j t j k r{ x t | d ƒ sK | j d } q, W| j | j ƒ rþ d | j | _ | j ƒ nƒ d } d } x2 t | ƒ D]$ } | j | ƒ r² d } q” d } q” W| rÜ | rØ | j
| d ƒ d St d | g ƒ } | j | _ | Sd S)NÚimpr
r Ú.FTz#absolute and local imports together)
r r r Zimport_fromÚhasattrr Úprobably_a_local_importr
Zchangedr Zwarningr Úprefix)r! r Zresultsr$ Z
have_localZ
have_absoluteZmod_nameÚnewr r r Ú transform3 s,
zFixImport.transformc C s¡ | j d ƒ r d S| j d d ƒ d } t | j ƒ } t | | ƒ } t t t | ƒ d ƒ ƒ sf d Sx4 d t d d d d
g D] } t | | ƒ r d Sq Wd S)Nr% Fé r z__init__.pyz.pyz.pycz.soz.slz.pydT)Ú
startswithÚsplitr Úfilenamer r r )r! Zimp_nameÚ base_pathZextr r r r' U s z!FixImport.probably_a_local_import)Ú__name__Ú
__module__Ú__qualname__Z
BM_compatibleZPATTERNr r* r' r r )r# r r &