f _ @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 1/usr/lib64/python3.10/lib2to3/fixes/fix_import.py z$traverse_imports..rNzunknown node type)poptyper NAMEr r Z dotted_namerchildrenZdotted_as_nameappendZdotted_as_namesextendAssertionError)namespendingnoder r rtraverse_importss     rcs4eZdZdZdZfddZddZddZZS) FixImportTzj import_from< 'from' imp=any 'import' ['('] any [')'] > | import_name< 'import' imp=any > cs"tt|||d|jv|_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) r!rr Z import_fromhasattrrprobably_a_local_importr changedrwarningrprefix)r"rresultsr&Z have_localZ have_absolutemod_namenewr r r transform3s,          zFixImport.transformcCsr|drdS|ddd}t|j}t||}ttt|dsHdSdtddd d fD]}t||rXd SdS) Nr'Frz __init__.pyz.pyz.pycz.soz.slz.pydT) startswithsplitrfilenamerrr)r"Zimp_name base_pathextr r rr)Us    z!FixImport.probably_a_local_import) __name__ __module__ __qualname__Z BM_compatibleZPATTERNr r0r) __classcell__r r r$rr&s  "rN)__doc__r rZos.pathrrrrZ fixer_utilrr r rZBaseFixrr r r rs