U é üeZã@sšdZddlZddlZddlZddlmZddlmZmZm Z m Z e  e ¡Z z ejjZWnek rrdd„ZYnXGdd„deƒZd d d „Zd d „ZdS)a:Implements an importer that looks only in specific path (ignoring sys.path), and uses a per-path cache in addition to sys.modules. This is necessary because test modules in different directories frequently have the same names, which means that the first loaded would mask the rest when using the builtin importer. éN)ÚConfig)Ú find_moduleÚ load_moduleÚ acquire_lockÚ release_lockcCs(tj tj |¡¡tj tj |¡¡kS©N)ÚosÚpathÚnormcaseÚrealpath)ÚsrcÚdst©rú;/opt/hc_python/lib/python3.8/site-packages/nose/importer.pyÚ _samefilesÿrc@s:eZdZdZd dd„Zdd„Zdd„Zd d „Zd d „ZdS)ÚImporterz³An importer class that does only path-specific imports. That is, the given module is not searched for on sys.path, but only at the path or in the directory specified. NcCs|dkrtƒ}||_dSr)rÚconfig)ÚselfrrrrÚ__init__szImporter.__init__cCsdtj tj |¡¡ tj¡}| d¡}|ddkr:| ¡|dt|ƒ …}tj |¡}|  ||¡S)zÌImport a dotted-name package whose tail is at path. In other words, given foo.bar and path/to/foo/bar.py, import foo from path/to/foo then bar from path/to/foo/bar, returning bar. Ú.éÿÿÿÿú __init__.pyN) rr ÚnormpathÚabspathÚsplitÚsepÚpopÚlenÚjoinÚ importFromDir)rr ÚfqnameÚ path_partsZ name_partsZdir_pathrrrÚimportFromPath"s   zImporter.importFromPathc Csjtj tj |¡¡}t d||¡|dkr4tj|S|jj rHt ||jƒ|g}|  d¡}d}d}}}|D]ø} |dkr~| }n d|| f}zštƒt d| ||¡t| |ƒ\}} } tj |¡} | dk rt d|| ¡| | | ¡sö|jjrüt| d dƒrü| }ntj|=t||| | ƒ}nt||| | ƒ}W5|r4|  ¡t ƒX|rNt|| |ƒt|d ƒr`|j}|}ql|S) zˆImport a module *only* from path, ignoring sys.path and reloading if the version in sys.modules is not the one we want. zImport %s from %sÚ__main__rÚNz%s.%szfind module part %s (%s) in %szsys.modules has %s as %sÚ__path__)rr rrÚlogÚdebugÚsysÚmodulesrZaddPathsÚadd_pathrÚcloserrrÚgetÚ sameModuleZfirstPackageWinsÚgetattrrÚsetattrÚhasattrr%) rÚdirr r ÚpartsZ part_fqnameÚmodÚparentÚfhÚpartÚfilenameÚdescÚoldrrrr1sV     ÿ   ÿ þ  zImporter.importFromDircCs tj |¡r|Stj |¡SdSr)rr ÚisdirÚdirname)rr7rrrÚ_dirname_if_filejs zImporter._dirname_if_filecCs„g}t|dƒr,|jD]}| | |¡¡qn"t|dƒrJ| | |j¡¡ndS| |¡}|D]"}t d||¡t||ƒr\dSq\dS)Nr%Ú__file__Fz&module already loaded? mod: %s new: %sT)r0r%Úappendr<r=r&r'r)rr3r7Z mod_pathsr Únew_pathZmod_pathrrrr-ss"    þ zImporter.sameModule)N) Ú__name__Ú __module__Ú __qualname__Ú__doc__rr"rr<r-rrrrrs  9 rcCsÌt d|¡|sgSg}tj |¡}|rRtj tj |d¡¡rR| t||ƒ¡n.|t jkr€t d|¡t j  d|¡|  |¡|rÈ|j rÈ|j D]6}tj ||¡}tj  |¡rt j  d|¡|  |¡q|S)zlEnsure that the path, or the root of the current package (if path is in a package), is in sys.path. z Add path %srzinsert %s into sys.pathr)r&r'rr r;ÚexistsrÚextendr*r(Úinsertr>ZsrcDirsr:)r rÚaddedr4r;Údirpathrrrr*ˆs( ÿ       r*cCs(t d|¡|tjkr$tj |¡dS)NzRemove path %s)r&r'r(r Úremove)r rrrÚ remove_path¤s rJ)N)rCÚloggingrr(Z nose.configrÚimprrrrÚ getLoggerr@r&r ÚsamefilerÚAttributeErrorÚobjectrr*rJrrrrÚs   p