Yf.@sdZddlZddlZddlZddlZddlmZmZddgZ Gddde Z Gdd d e Z dddddd d Z dddddd d ZeddZGdddeZdddZdddddZeddZddZddddZedkreejdkrgeddejnejd=eejddS) aZrunpy.py - locating and running Python code using the module namespace Provides support for locating and running Python scripts using the Python module namespace instead of the native filesystem. This allows Python code to play nicely with non-filesystem based PEP 302 importers when locating support scripts as well as when importing modules. N) read_code get_importer run_modulerun_pathc@s:eZdZdZddZddZddZdS) _TempModulezCTemporarily replace a module in sys.modules with an empty namespacecCs(||_tj||_g|_dS)N)mod_nametypes ModuleTypemodule _saved_module)selfrr */opt/alt/python35/lib64/python3.5/runpy.py__init__s z_TempModule.__init__c CsM|j}y|jjtj|Wntk r8YnX|jtj|<|S)N)rr appendsysmodulesKeyErrorr )r rr r r __enter__s  z_TempModule.__enter__cGs=|jr#|jdtj|js(          r3c Csw|dkr|n|j}t|C}t|-|jj}t|||||||WdQRXWdQRX|jS)z5Helper to run code in new namespace with sys modifiedN)r)rrr __dict__r3copy) r-r.rr/r0r1r2 temp_module mod_globalsr r r_run_module_codeXs   r8c ;Cs|jdr|d|jd\}}}|r yt|Wn]tk r}z=|jdks|j|kr|j|jd rWYdd}~XnXtjj|}|dk r t|d r ddl m }dj d|d|}|t |yt jj|}Wn^ttttfk r} z2d }||j |t| j| | WYdd} ~ XnX|dkr|d ||jdk rE|d ks|jd r|d y|d } t| |SWnQ|k rD}z1|tjkr|dd||fWYdd}~XnX|j} | dkrj|d|y| j|} Wn:tk r}z|t ||WYdd}~XnX| dkr|d|||| fS)N.z#Relative module names not supported__path__r)warnz{mod_name!r} found in sys.modules after import of package {pkg_name!r}, but prior to execution of {mod_name!r}; this may result in unpredictable behaviourrr0z:Error while finding module specification for {!r} ({}: {})zNo module named %s__main__z .__main__z%Cannot use package as __main__ modulez%s; %r is a package and cannot zbe directly executedz0%r is a namespace package and cannot be executedzNo code object available for %s) startswith rpartition __import__ ImportErrornamerrgethasattrwarningsr;formatRuntimeWarning importlibutil find_specAttributeError TypeError ValueErrortypersubmodule_search_locationsendswith_get_module_detailsr(get_code) rerrorr0_eZexistingr;msgspecZexZ pkg_main_namer(r-r r rrPfsZ  :   '   ( rPc@seZdZdZdS)_ErrorzBError that _run_module_as_main() should report without a tracebackN)rrrrr r r rrWs rWTcCsyF|s|dkr0t|t\}}}ntt\}}}WnEtk r}z%dtj|f}tj|WYdd}~XnXtjdj}|r|jtj dr9rFZimpZ NullImporterTr0r1)r>rrMrr isinstancerer8rr_insertrXrrr r4r3r5removerL) Z path_namer.r]r0ZimporterZis_NullImporterr-r2rr/r6r7r r rrs0      % r<z!No module specified for executionfile)rrimportlib.machineryrGimportlib.utilrZpkgutilrr__all__rrrr3r8r@rP ExceptionrWr\rrXrerrlenr!printstderrr r r rs6      : 1