grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026U iÛf/ã@sdZddlZddlZddlZddlZddlZddlZddlm Z m Z ddgZ Gdd„de ƒZ Gdd „d e ƒZd d d „Zd!d d „Zefdd„ZGdd„deƒZd"dd„Zd#dd„Zefdd„Zdd„Zd$dd„Zedk�reejƒdk�røedejd�nejd=eejdƒdS)%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_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/python38/lib64/python3.8/runpy.pyÚ__init__s z_TempModule.__init__cCsB|j}z|j tj|¡Wntk r0YnX|jtj|<|Sr)rr ÚappendÚsysÚmodulesÚKeyErrorr r rrrÚ __enter__ s z_TempModule.__enter__cGs.|jr|jdtj|j<n tj|j=g|_dS©Nr)r rrr©rÚargsrrrÚ__exit__)s z_TempModule.__exit__N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrrrrs rc@s$eZdZdd„Zdd„Zdd„ZdS)Ú_ModifiedArgv0cCs||_tƒ|_|_dSr)ÚvalueÚobjectÚ _saved_valueÚ _sentinel)rr rrrr1sz_ModifiedArgv0.__init__cCs0|j|jk rtdƒ‚tjd|_|jtjd<dS)NzAlready preserving saved valuer)r"r#Ú RuntimeErrorrÚargvr )rrrrr5s  z_ModifiedArgv0.__enter__cGs|j|_|jtjd<dSr)r#r r"rr%rrrrr;sz_ModifiedArgv0.__exit__N)rrrrrrrrrrr0src Csn|dk r| |¡|dkr(d}|}d} n |j}|j}|j} |dkrH|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.rrrÚ _run_code@s* ú r7c Cs^|dkr |n|j}t|ƒ�6}t|ƒ�"|jj}t|||||||ƒW5QRXW5QRX| ¡S)z5Helper to run code in new namespace with sys modifiedN)r-rrr Ú__dict__r7Úcopy) r1r2rr3r4r5r6Ú temp_moduleÚ mod_globalsrrrÚ_run_module_codeZsÿr<c Cs2| d¡r|dƒ‚| d¡\}}}|rÀz t|ƒWnHtk rz}z*|jdksh|j|krj| |jd¡sj‚W5d}~XYnXtj |¡}|dk rÀt|dƒsÀddl m }dj ||d�}|t |ƒƒzt j |¡}WnJttttfk �r} z"d}||  |t| ƒj| ¡ƒ| ‚W5d} ~ XYnX|dk�r2|d |ƒ‚|jdk �r´|d k�sT| d ¡�r\|d ƒ‚z|d } t| |ƒWS|k �r²}z"|tjk�r’‚|d ||fƒ‚W5d}~XYnX|j} | dk�rÐ|d|ƒ‚z|  |¡} Wn2tk �r}z|t |ƒƒ|‚W5d}~XYnX| dk�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)rr4z: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__Ú ImportErrorÚnamerrÚgetÚhasattrÚwarningsr?ÚformatÚRuntimeWarningÚ importlibÚutilÚ find_specÚAttributeErrorÚ TypeErrorÚ ValueErrorÚtyperÚsubmodule_search_locationsÚendswithÚ_get_module_detailsr,Úget_code) rÚerrorr4Ú_ÚeZexistingr?ÚmsgÚspecZexZ pkg_main_namer,r1rrrrThsd  ÿ  ý ,     ÿ ÿ   rTc@seZdZdZdS)Ú_ErrorzBError that _run_module_as_main() should report without a tracebackN)rrrrrrrrr[¢sr[Tc Cs˜z0|s|dkr t|tƒ\}}}nttƒ\}}}Wn:tk rj}zdtj|f}t |¡W5d}~XYnXtjdj}|rˆ|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) rTr[Ú_get_main_module_detailsrÚ executableÚexitrr8r-r%r7)rZ alter_argvr3r1ÚexcrYZ main_globalsrrrÚ_run_module_as_main©s   ÿr`FcCs@t|ƒ\}}}|dkr|}|r,t||||ƒSt|i|||ƒSdS)znExecute a module's code without importing it Returns the resulting top level namespace dictionary N)rTr<r7)rr2Úrun_nameZ alter_sysr3r1rrrrÅs c Cs„d}tj|}tj|=z\zt|ƒWW¢NStk rn}z*|t|ƒkr\|d|tjdfƒ|‚‚W5d}~XYnXW5|tj|<XdS)Nr@zcan't find %r module in %rr)rrrTrDÚstrÚpath)rVZ main_nameZ saved_mainr_rrrr\Ôs   ÿÿr\c Csftj t |¡¡}t |¡�}t|ƒ}W5QRX|dkr^t |¡�}t| ¡|dƒ}W5QRX||fS)Nr0) ÚosrcÚabspathÚfsdecodeÚioÚ open_coderÚcompileÚread)rar6Z decoded_pathÚfr1rrrÚ_get_code_from_fileçs  rlc Cs$|dkr d}| d¡d}t|ƒ}d}t|ƒjdkrFt|ƒjdkrFd}t|tdƒƒsX|rxt||ƒ\}}t|||||d �Stj   d|¡znt ƒ\}} }t|ƒ�P} t|ƒ�<| jj} t|| ||| |ƒ ¡W5QR£W5QR£W¢SQRXW5QRXW5ztj   |¡Wnt k �rYnXXdS) a_Execute code located at the specified filesystem location Returns the resulting top level namespace dictionary The file path may refer directly to a Python script (i.e. one that could be directly executed with execfile) or else it may refer to a zipfile or directory containing a top level __main__.py script. Nz r=rFZimpZ NullImporterT)r4r5)rBrrQrrÚ isinstancerlr<rrcÚinsertÚremoverPr\rrr r8r7r9) Z path_namer2rar4ZimporterZis_NullImporterr1r6rr3r:r;rrrròs< ÿ  ÿÿ8r@éz!No module specified for execution)Úfile)NNNNN)NNNNN)T)NNF)NN)rrÚimportlib.machineryrKÚimportlib.utilrgr rdZpkgutilrrÚ__all__r!rrr7r<rDrTÚ Exceptionr[r`rr\rlrrÚlenr%ÚprintÚstderrrrrrÚsN ÿþ þ  : ÿ   1