grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|j73ã@sdZddlZddlZddlZddlZddlZddlZddgZGdd„de ƒZ Gdd„de ƒZ   dd d „Z   dd d „Z efd d„ZGdd„deƒZd dd„Z  d!dd„Zefdd„Zdd„Zd"dd„Zedkrˆeejƒdkr{edejd�dSejd=eejdƒdSdS)#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_moduleÚrun_pathc@s(eZdZdZdd„Zdd„Zdd„ZdS) Ú _TempModulezCTemporarily replace a module in sys.modules with an empty namespacecCs||_t |¡|_g|_dS©N)Úmod_nameÚtypesÚ ModuleTypeÚmoduleÚ _saved_module©Úselfr©r ú,/opt/alt/python310/lib64/python3.10/runpy.pyÚ__init__s  z_TempModule.__init__cCs@|j}z |j tj|¡Wn tyYnw|jtj|<|Sr)rr ÚappendÚsysÚmodulesÚKeyErrorr r r r rÚ __enter__s ÿ z_TempModule.__enter__cGs.|jr |jdtj|j<ntj|j=g|_dS©Nr)r rrr©r Úargsr r rÚ__exit__(s  z_TempModule.__exit__N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrr r r rrs  rc@s$eZdZdd„Zdd„Zdd„ZdS)Ú_ModifiedArgv0cCs||_tƒ|_|_dSr)ÚvalueÚobjectÚ _saved_valueÚ _sentinel)r rr r rr0sz_ModifiedArgv0.__init__cCs0|j|jur tdƒ‚tjd|_|jtjd<dS)NzAlready preserving saved valuer)r r!Ú RuntimeErrorrÚargvr)r r r rr4s  z_ModifiedArgv0.__enter__cGs|j|_|jtjd<dSr)r!rr rr#rr r rr:sz_ModifiedArgv0.__exit__N)rrrrrrr r r rr/s rc Csn|dur | |¡|durd}|}d} n|j}|j}|j} |dur$|j}|j||| d|||d�t||ƒ|S)z)Helper to run code in nominated namespaceN)rÚ__file__Ú __cached__rÚ __loader__Ú __package__Ú__spec__)ÚupdateÚloaderÚoriginÚcachedÚparentÚexec) ÚcodeZ run_globalsÚ init_globalsrÚmod_specÚpkg_nameÚ script_namer*Úfnamer,r r rÚ _run_code?s* ú r5c Cs |dur|n|j}t|ƒ�7}t|ƒ�|jj}t|||||||ƒWdƒn1s+wYWdƒ| ¡SWdƒ| ¡S1sGwY| ¡S)z5Helper to run code in new namespace with sys modifiedN)r+rrr Ú__dict__r5Úcopy) r/r0rr1r2r3r4Ú temp_moduleÚ mod_globalsr r rÚ_run_module_codeYsÿ(þ úúr:c Cs.| d¡r |dƒ‚| d¡\}}}|razt|ƒWn%ty>}z|jdus3|j|kr4| |jd¡s4‚WYd}~nd}~wwtj |¡}|durat|dƒsaddl m }dj ||d�}|t |ƒƒzt j |¡}Wn3ttttfyœ} z#d}| d ¡r‹|d |dd …›d |›d �7}||  |t| ƒj| ¡ƒ| ‚d} ~ ww|dur§|d|ƒ‚|jdurÞ|dksµ| d¡r¹|dƒ‚z |d} t| |ƒWS|yÝ}z|tjvrÑ‚|d||fƒ‚d}~ww|j} | durë|d|ƒ‚z|  |¡} Wnt�y}z|t |ƒƒ|‚d}~ww| du�r|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)rr2z: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__ 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__Ú ImportErrorÚnamerrÚgetÚhasattrÚwarningsr=ÚformatÚRuntimeWarningÚ importlibÚutilÚ find_specÚAttributeErrorÚ TypeErrorÚ ValueErrorÚendswithÚtyperÚsubmodule_search_locationsÚ_get_module_detailsr*Úget_code) rÚerrorr2Ú_ÚeZexistingr=ÚmsgÚspecZexZ pkg_main_namer*r/r r rrSgsz  ÿ€ú  ý   ÿ€ø    ÿ€ýÿ€ÿ   rSc@seZdZdZdS)Ú_ErrorzBError that _run_module_as_main() should report without a tracebackN)rrrrr r r rrZ¤srZTc Csšz|s|dkrt|tƒ\}}}nttƒ\}}}Wnty6}zdtj|f}t |¡WYd}~nd}~wwtjdj}|rE|jtj d<t ||dd|ƒS)aÅRuns 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__ r?z%s: %sNr) rSrZÚ_get_main_module_detailsrÚ executableÚexitrr6r+r#r5)rZ alter_argvr1r/ÚexcrXZ main_globalsr r rÚ_run_module_as_main«s  €€þ  ÿr_FcCs<t|ƒ\}}}|dur |}|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. N)rSr:r5)rr0Úrun_nameZ alter_sysr1r/r r rrÇs c Cszd}tj|}tj|=z+z t|ƒWW|tj|<Sty6}z|t|ƒvr1|d|tjdfƒ|‚‚d}~ww|tj|<w)Nr?zcan't find %r module in %rr)rrrSrCÚstrÚpath)rUZ main_nameZ saved_mainr^r r rr[ås"   ú  ÿÿ€ü r[cCs ddlm}tj t |¡¡}t |¡� }||ƒ}Wdƒn1s#wY|durLt |¡�}t|  ¡|dƒ}Wdƒ||fS1sGwY||fS)Nr)Ú read_coder.) ÚpkgutilrcÚosrbÚabspathÚfsdecodeÚioÚ open_codeÚcompileÚread)r`r4rcZ decoded_pathÚfr/r r rÚ_get_code_from_fileøs   ÿ  ÿþrmc CsŽ|durd}| d¡d}ddlm}||ƒ}d}t|ƒjdkr)t|ƒjdkr)d }t|tdƒƒs2|rBt||ƒ\}}t|||||d �St j   d|¡zkt ƒ\} } }t |ƒ�D} t|ƒ�0| jj} t|| ||| |ƒ ¡WdƒWdƒWzt j  |¡WStyˆYSw1sŒwYWdƒn1s›wYWz t j  |¡WdSty´YdSwzt j  |¡WwtyÆYww) 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 r;r)Ú get_importerFZimpZ NullImporterT)r2r3)rArdrnrQrrÚ isinstancermr:rrbÚinsertr[rrr r6r5r7ÚremoverO) Z path_namer0r`r2rnZimporterZis_NullImporterr/r4rr1r8r9r r rrsV ÿ  ÿÿü ÿ.ø€ ÿþ ÿr?éz!No module specified for execution)Úfile)NNNNN)T)NNF)NN)rrÚimportlib.machineryrJÚimportlib.utilrhrreÚ__all__rrrr5r:rCrSÚ ExceptionrZr_rr[rmrrÚlenr#ÚprintÚstderrr r r rÚsD ÿ þ þ =  ÿ  7ú