QfU2dZddlZddlZddlZddlZddlZddgZeeZ Gdde Z Gdde Z dd Z dd Zefd ZGd d eZddZ ddZefdZdZddZedk(rMeej4dkredej8yej4d=eej4dyy)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 run_modulerun_pathc"eZdZdZdZdZdZy) _TempModulezCTemporarily replace a module in sys.modules with an empty namespacec@||_t||_g|_yN)mod_name ModuleTypemodule _saved_moduleselfr s ,/opt/alt/python312/lib64/python3.12/runpy.py__init__z_TempModule.__init__s   * c|j} |jjtj||j tj|<|S#t $rY*wxYwr)r r appendsysmodulesKeyErrorr r s r __enter__z_TempModule.__enter__!sZ==     % %ckk(&; <!%  H    s,A A%$A%c|jr2|jdtj|j<g|_ytj|j=g|_yNr)r rrr rargss r__exit__z_TempModule.__exit__*sL   )-););A)>CKK &  DMM*rN)__name__ __module__ __qualname____doc__rrrrrrrsM  rrceZdZdZdZdZy)_ModifiedArgv0c>||_tx|_|_yr)valueobject _saved_value _sentinel)rr%s rrz_ModifiedArgv0.__init__2s -3X5DNrc|j|jur tdtjd|_|j tjd<y)NzAlready preserving saved valuer)r'r( RuntimeErrorrargvr%)rs rrz_ModifiedArgv0.__enter__6sA   DNN 2?@ @HHQKjj rc`|j|_|jtjd<yr)r(r%r'rr+rs rrz_ModifiedArgv0.__exit__<s ^^ '' rN)rrrrrrr!rrr#r#1s6! (rr#c ||j||d}|}d} n2|j}|j}|j} | |j}|j||| d|||t |||S)z)Helper to run code in nominated namespaceN)r__file__ __cached__r __loader__ __package____spec__)updateloaderorigincachedparentexec) code run_globals init_globalsr mod_specpkg_name script_namer4fnamer6s r _run_coder@As<(  H("'$*!%$*%-"* , { rc .||n |j}t|5}t|5|jj}t |||||||ddddddj S#1swY!xYw#1swYj SxYw)z5Helper to run code in new namespace with sys modifiedN)r5rr#r __dict__r@copy) r9r;r r<r=r>r? temp_module mod_globalss r_run_module_coderF[s$+KE X +~e/D!((11 $ \Hh  =0E      0E/D     s" A<(A0A<0A9 5A<<Bc |jdr|d|jd\}}}|rc t|t j j|}|6t|ds*ddl m }dj||}|t| tjj|}| |d|z|j,0|dk(s|j'dr|d |dz} t/| |S|j0} | |d|z | j3|} | |d|z||| fS#t$rE}|j-|j|k7r|j|jdzsYd}~Fd}~wwxYw#tt t"t$f$rT} d}|j'd r|d |dd d |d z }||j|t)| j*| | d} ~ wwxYw#|$r&}|t j vr||d|dd}~wwxYw#t$r}|t||d}~wwxYw)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)r r=z:Error while finding module specification for {!r} ({}: {})z.pyz . Try using 'z' instead of 'z' as the module name.zNo module named %s__main__z .__main__z%Cannot use package as __main__ modulez; z- 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__ ImportErrornamerrgethasattrwarningsrJformatRuntimeWarning importlibutil find_specAttributeError TypeError ValueErrorendswithtypersubmodule_search_locations_get_module_detailsr4get_code) r errorr=_eexistingrJmsgspecex pkg_main_namer4r9s rr`r`is39::((-NHa  x ;;??8,  *(E %#FHxFH  $ % I~~''1 |(8344 &&2 z !X%6%6{%C?@ @ G${2M&}e< < [[F ~FCKLM M&x( |5@AA T4 g vv~!&&H"4 ++AFFSL9  & J ?IK   U # mHSbM?3 z!68 9CCJJxb):):B?@bHI" Gs{{*9:HFG G G &F1IA%&s` D:F ,G;H): F:FF G8$AG33G8;H&!H!!H&) I 2II ceZdZdZy)_ErrorzBError that _run_module_as_main() should report without a tracebackN)rrrr r!rrrkrksLrrkcx |s|dk7rt|t\}}}ntt\}}}tj dj}|rjtjd<t|ddS#t$r4}tjd|}tj |Yd}~d}~wwxYw)aRuns the designated module in the __main__ namespace Note that the executed module will have full access to the __main__ namespace. If this is not desirable, the run_module() function should be used to run the module code in a fresh namespace. At the very least, these variables in __main__ will be overwritten: __name__ __file__ __cached__ __loader__ __package__ rLz: Nr) r`rk_get_main_module_detailsr executableexitrrBr5r+r@)r alter_argvr<r9excrf main_globalss r_run_module_as_mainrss Z/':8V'L $Hh'?'G $Hh;;z*33Loo T< ++ ..#.  s/A<< B9*B44B9cft|\}}}||}|rt||||St|i|||S)u"Execute a module's code without importing it. mod_name -- an absolute module name or package name. Optional arguments: init_globals -- dictionary used to pre-populate the module’s globals dictionary before the code is executed. run_name -- if not None, this will be used for setting __name__; otherwise, __name__ will be set to mod_name + '__main__' if the named module is a package and to just mod_name otherwise. alter_sys -- if True, sys.argv[0] is updated with the value of __file__ and sys.modules[__name__] is updated with a temporary module object for the module being executed. Both are restored to their original values before the function returns. Returns the resulting module globals dictionary. )r`rFr@)r r;run_name alter_sysr<r9s rrrsI* 38<HhlHhGGr<8DDrc:d}tj|}tj|= t||tj|<S#t$r3}|t |vr |d|dtj d|d}~wwxYw#|tj|<wxYw)NrLz can't find z module in r)rrr`rPstrpath)rb main_name saved_mainrqs rrmrms IY'J I,"9-", I  C (#((1+78=@ A  ", Is# A B.A==BBBcHddlm}tjj |}t j |5}||}ddd;t j |5}t|j|d}ddd|S|S#1swYHxYw#1swY|SxYw)Nr) read_coder8) pkgutilr}osryabspathio open_codecompileread)r?r} code_pathfr9s r_get_code_from_filers|!&I i A| ! | \\) $1668UF3D% K4K ! % Ks B #B BB!c \|d}|jdd}ddlm}||}tj|}t |t drt|}t|||||Stjjd| t\}}}t|5} t|5| jj } t#|| ||||j%cdddcddd tjj'|S#t($rYSwxYw#1swYnxYw dddn #1swYnxYw tjj'|y#t($rYywxYw# tjj'|w#t($rYwwxYwxYw)uExecute code located at the specified filesystem location. path_name -- filesystem location of a Python script, zipfile, or directory containing a top level __main__.py script. Optional arguments: init_globals -- dictionary used to pre-populate the module’s globals dictionary before the code is executed. run_name -- if not None, this will be used to set __name__; otherwise, '' will be used for __name__. Returns the resulting module globals dictionary. Nz rHr) get_importer)r=r>)rNr~rrfsdecode isinstancer^rrFrryinsertrmrr#r rBr@rCremover\) path_namer;rur=rimporterr9r r<rDrEs rrrs}""3'*H$I&H I&I(DJ'#9-lH)1yJ J 9% (@'A $HhX&+ *)0099  {L$,hBBF$&  I I I   *  +**'&&   *    *  s E:& D>24D(& D>/ E:9D D%$D%(D1 -D>5 E:>EE: E++ E76E7:F+<FF+ F(%F+'F((F+rLz!No module specified for execution)file)NNNNN)T)NNF)NN)r rimportlib.machineryrWimportlib.utilrr__all__r^r r&rr#r@rFrPr` Exceptionrkrsrrmrrrlenr+printstderrr!rrrs  *  #Y  & . (V ( /3&*)-4)-,0/3 )4; zMYM+8'+(-E<$/,& 0f z 388}q 1 C HHQKCHHQK( r