f _ c@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 i) 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)Z.0Zchr r 1/usr/lib64/python3.10/lib2to3/fixes/fix_import.pyZ sz$traverse_imports..rNizunknown node type)ZpoptyperZNAMEr rZ dotted_namerchildrenZdotted_as_nameZappendZdotted_as_namesZextendZAssertionError)ZnamesZpendingnoder r r traverse_importss     rcs4eZdZdZdZfddZddZddZZS) FixImportTzj import_from< 'from' imp=any 'import' ['('] any [')'] > | import_name< 'import' imp=any > cs"tt|||d|jv|_dS)NZabsolute_import)Zsuperr start_treeZfuture_featuresskip)selfZtreeZnameZ __class__r r r/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) rr rZ import_fromZhasattrrprobably_a_local_importr ZchangedrZwarningrZprefix)rrZresultsrZ have_localZ have_absoluteZmod_nameZnewr r r transform3s,          zFixImport.transformcCsr|drdS|ddd}t|j}t||}ttt|dsHdSdtddd d fD]}t||rXd SdS) NrFirz __init__.pyz.pyz.pycz.soz.slz.pydT)Z startswithZsplitrZfilenamerrr)rZimp_nameZ base_pathZextr r r rUs    z!FixImport.probably_a_local_import) Z__name__Z __module__Z __qualname__Z BM_compatibleZPATTERNrrrZ __classcell__r r rr r&s  "rN)Z__doc__r rZos.pathrrrrZ fixer_utilrrrrZBaseFixrr r r r Zs