U if @sZdZddlmZddlmZmZmZmZddlm Z m Z m Z ddZ Gdd d ej Zd S) zFixer 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)dirnamejoinexistssep) FromImportsymstokenccs|g}|r|}|jtjkr(|jVq|jtjkrNddd|jDVq|jtj krl| |jdq|jtj kr| |jdddqt dqdS)zF Walks over all the names imported in a dotted_as_names node. cSsg|] }|jqS)value).0Zchr r =/opt/alt/python38/lib64/python3.8/lib2to3/fixes/fix_import.py sz$traverse_imports..rNzunknown node type)poptyper NAMEr r Z dotted_namerchildrenZdotted_as_nameappendZdotted_as_namesextendAssertionError)namesZpendingnoder r rtraverse_importss     rcs4eZdZdZdZfddZddZddZZS) FixImportTzj import_from< 'from' imp=any 'import' ['('] any [')'] > | import_name< 'import' imp=any > cs"tt|||d|jk|_dS)NZabsolute_import)superr start_treeZfuture_featuresskip)selfZtreename __class__r rr/szFixImport.start_treecCs|jr dS|d}|jtjkrVt|ds4|jd}q||jrd|j|_|nZd}d}t |D]}||rzd}qfd}qf|r|r| |ddSt d|g}|j |_ |SdS)Nimpr r.FTz#absolute and local imports together) rrr Z import_fromhasattrrprobably_a_local_importr ZchangedrZwarningrprefix)r rZresultsr$Z have_localZ have_absoluteZmod_namenewr r r transform3s,          zFixImport.transformcCst|drdS|ddd}t|j}t||}ttt|dsHdSdtddd d fD]}t||rXd SqXdS) Nr%Frz __init__.pyz.pyz.pycz.soz.slz.pydT) startswithsplitrfilenamerrr)r Zimp_name base_pathZextr r rr'Us    z!FixImport.probably_a_local_import) __name__ __module__ __qualname__Z BM_compatibleZPATTERNrr*r' __classcell__r r r"rr&s  "rN)__doc__r rZos.pathrrrrZ fixer_utilrr r rZBaseFixrr r r rs