U e5d/@sddlZddlZddlZddlZddlZddlZddlmZm Z ddgZ Gddde Z Gddde Z dd d Zd d d Zefd dZGdddeZd!ddZd"ddZefddZddZd#ddZedkr eejdkredejdnejd=eejddS)$N) read_code get_importer run_modulerun_pathc@s$eZdZddZddZddZdS) _TempModulecCs||_t||_g|_dSN)mod_nametypes ModuleTypemodule _saved_moduleselfrr/usr/lib64/python3.8/runpy.py__init__s z_TempModule.__init__cCsB|j}z|jtj|Wntk r0YnX|jtj|<|Sr)rr appendsysmodulesKeyErrorr r rrr __enter__ s z_TempModule.__enter__cGs.|jr|jdtj|j<n tj|j=g|_dSNr)r rrrrargsrrr__exit__)s z_TempModule.__exit__N__name__ __module__ __qualname__rrrrrrrrs rc@s$eZdZddZddZddZdS)_ModifiedArgv0cCs||_t|_|_dSr)valueobject _saved_value _sentinel)rr rrrr1sz_ModifiedArgv0.__init__cCs0|j|jk rtdtjd|_|jtjd<dS)NzAlready preserving saved valuer)r"r# RuntimeErrorrargvr )rrrrr5s  z_ModifiedArgv0.__enter__cGs|j|_|jtjd<dSr)r#r r"rr%rrrrr;sz_ModifiedArgv0.__exit__Nrrrrrr0src Csn|dk r|||dkr(d}|}d} n |j}|j}|j} |dkrH|j}|j||| d|||dt|||S)N)r__file__ __cached____doc__ __loader__ __package____spec__)updateloaderorigincachedparentexec) codeZ run_globals init_globalsrmod_specpkg_name script_namer-fnamer/rrr _run_code@s*  r8c Cs^|dkr |n|j}t|6}t|"|jj}t|||||||W5QRXW5QRX|Sr)r.rrr __dict__r8copy) r2r3rr4r5r6r7 temp_module mod_globalsrrr_run_module_codeZsr=c Cs2|dr|d|d\}}}|rz t|WnHtk rz}z*|jdksh|j|krj||jdsjW5d}~XYnXtj|}|dk rt|dsddl m }dj ||d}|t |zt j|}WnJttttfk r} z"d}|| |t| j| | W5d} ~ XYnX|dkr2|d ||jdk r|d ksT|d r\|d z|d } t| |WS|k r}z"|tjkr|d ||fW5d}~XYnX|j} | dkr|d|z| |} Wn2tk r}z|t ||W5d}~XYnX| 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 behaviour)rr5z:Error while finding module specification for {!r} ({}: {})zNo module named %s__main__z .__main__z%Cannot use package as __main__ modulez3%s; %r is a package and cannot be 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) rerrorr5_eZexistingr@msgspecZexZ pkg_main_namer-r2rrrrUhsd     ,         rUc@s eZdZdS)_ErrorN)rrrrrrrr\sr\Tc Csz0|s|dkr t|t\}}}ntt\}}}Wn:tk rj}zdtj|f}t|W5d}~XYnXtjdj}|r|jtj d<t ||dd|S)NrAz%s: %sr) rUr\_get_main_module_detailsr executableexitrr9r.r%r8)rZ alter_argvr4r2excrZZ main_globalsrrr_run_module_as_mains   raFcCs@t|\}}}|dkr|}|r,t||||St|i|||SdSr)rUr=r8)rr3run_nameZ alter_sysr4r2rrrrs c Csd}tj|}tj|=z\zt|WWNStk rn}z*|t|kr\|d|tjdf|W5d}~XYnXW5|tj|<XdS)NrAzcan't find %r module in %rr)rrrUrEstrpath)rWZ main_nameZ saved_mainr`rrrr]s   r]c Csftjt|}t|}t|}W5QRX|dkr^t|}t||d}W5QRX||fS)Nr1) osrdabspathfsdecodeio open_codercompileread)rbr7Z decoded_pathfr2rrr_get_code_from_files  rmc Cs$|dkr d}|dd}t|}d}t|jdkrFt|jdkrFd}t|tdsX|rxt||\}}t|||||dStj d|znt \}} }t|P} t|<| jj} t|| ||| |W5QRW5QRWSQRXW5QRXW5ztj |Wnt k rYnXXdS) Nz r>rFZimpZ NullImporterT)r5r6)rCrrRrr isinstancermr=rrdinsertremoverQr]rrr r9r8r:) Z path_namer3rbr5ZimporterZis_NullImporterr2r7rr4r;r<rrrrs<   8rAz!No module specified for execution)file)NNNNN)NNNNN)T)NNF)NN)rimportlib.machineryrLimportlib.utilrhr reZpkgutilrr__all__r!rrr8r=rErU Exceptionr\rarr]rmrrlenr%printstderrrrrr sL   :    1