
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
U
    ¡ê,a/  ã                   @   s  d Z ddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
 ddgZG dd„ deƒZG dd	„ d	eƒZd d
d„Zd!dd„Zefdd„ZG dd„ deƒZd"dd„Zd#dd„Zefdd„Zdd„ Zd$dd„Zedk�reejƒdk � røedejd� nejd= eejd ƒ dS )%aZ  runpy.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(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú_TempModulezCTemporarily replace a module in sys.modules with an empty namespacec                 C   s   || _ t |¡| _g | _d S ©N)Úmod_nameÚtypesÚ
ModuleTypeÚmoduleÚ_saved_module©Úselfr   © r   ú*/opt/alt/python38/lib64/python3.8/runpy.pyÚ__init__   s    z_TempModule.__init__c                 C   sB   | j }z| j tj| ¡ W n tk
r0   Y nX | jtj|< | S r   )r   r   ÚappendÚsysÚmodulesÚKeyErrorr   r   r   r   r   Ú	__enter__    s    z_TempModule.__enter__c                 G   s.   | j r| j d tj| j< n
tj| j= g | _ d S ©Nr   )r   r   r   r   ©r   Úargsr   r   r   Ú__exit__)   s    
z_TempModule.__exit__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r      s   	r   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú_ModifiedArgv0c                 C   s   || _ tƒ  | _| _d S r   )ÚvalueÚobjectÚ_saved_valueÚ	_sentinel)r   r    r   r   r   r   1   s    z_ModifiedArgv0.__init__c                 C   s0   | j | jk	rtdƒ‚tjd | _ | jtjd< d S )NzAlready preserving saved valuer   )r"   r#   ÚRuntimeErrorr   Úargvr    )r   r   r   r   r   5   s    z_ModifiedArgv0.__enter__c                 G   s   | j | _| jtjd< d S r   )r#   r    r"   r   r%   r   r   r   r   r   ;   s    z_ModifiedArgv0.__exit__N)r   r   r   r   r   r   r   r   r   r   r   0   s   r   c           
   	   C   sn   |dk	r|  |¡ |dkr(d}|}d}	n |j}|j}|j}	|dkrH|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*    
ú
r7   c           	   
   C   s^   |dkr|n|j }t|ƒ�6}t|ƒ�" |jj}t| ||||||ƒ W 5 Q R X W 5 Q R X | ¡ S )z5Helper to run code in new namespace with sys modifiedN)r-   r   r   r   Ú__dict__r7   Úcopy)	r1   r2   r   r3   r4   r5   r6   Útemp_moduleÚmod_globalsr   r   r   Ú_run_module_codeZ   s       ÿr<   c                 C   s2  |   d¡r|dƒ‚|  d¡\}}}|rÀzt|ƒ W nH tk
rz } z*|jd ksh|j|krj|  |jd ¡sj‚ W 5 d }~X Y nX tj | ¡}|d k	rÀt|dƒsÀddl	m
} dj| |d�}|t|ƒƒ ztj | ¡}W nJ ttttfk
�r }	 z"d}|| | t|	ƒj|	¡ƒ|	‚W 5 d }	~	X Y nX |d k�r2|d	|  ƒ‚|jd k	�r´| d
k�sT|  d¡�r\|dƒ‚z| d }
t|
|ƒW S  |k
�r² } z"| tjk�r’‚ |d|| f ƒ‚W 5 d }~X Y nX |j}|d k�rÐ|d|  ƒ‚z| | ¡}W n2 tk
�r } z|t|ƒƒ|‚W 5 d }~X Y nX |d k�r(|d|  ƒ‚| ||fS )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   r4   z:Error while finding module specification for {!r} ({}: {})zNo 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 executedzNo code object available for %s)Ú
startswithÚ
rpartitionÚ
__import__ÚImportErrorÚnamer   r   ÚgetÚhasattrÚwarningsr?   ÚformatÚRuntimeWarningÚ	importlibÚutilÚ	find_specÚAttributeErrorÚ	TypeErrorÚ
ValueErrorÚtyper   Úsubmodule_search_locationsÚendswithÚ_get_module_detailsr,   Úget_code)r   Úerrorr4   Ú_ÚeZexistingr?   ÚmsgÚspecZexZpkg_main_namer,   r1   r   r   r   rT   h   sd    
ÿ ý,
ÿ
ÿ 
rT   c                   @   s   e Zd ZdZdS )Ú_ErrorzBError that _run_module_as_main() should report without a tracebackN)r   r   r   r   r   r   r   r   r[   ¢   s   r[   Tc              
   C   s˜   z0|s| dkr t | tƒ\} }}nttƒ\} }}W n: tk
rj } zdtj|f }t |¡ W 5 d}~X Y nX tjd j}|rˆ|jtj	d< t
||dd|ƒ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   )rT   r[   Ú_get_main_module_detailsr   Ú
executableÚexitr   r8   r-   r%   r7   )r   Z
alter_argvr3   r1   ÚexcrY   Zmain_globalsr   r   r   Ú_run_module_as_main©   s     ÿr`   Fc                 C   s@   t | ƒ\} }}|dkr| }|r,t||||ƒS t|i |||ƒS dS )znExecute a module's code without importing it

       Returns the resulting top level namespace dictionary
    N)rT   r<   r7   )r   r2   Úrun_nameZ	alter_sysr3   r1   r   r   r   r   Å   s    c              
   C   s„   d}t j| }t j|= z\zt|ƒW W ¢NS  tk
rn } z*|t|ƒkr\| d|t jd f ƒ|‚‚ W 5 d }~X Y nX W 5 |t j|< X d S )Nr@   zcan't find %r module in %rr   )r   r   rT   rD   ÚstrÚpath)rV   Z	main_nameZ
saved_mainr_   r   r   r   r\   Ô   s    
ÿÿr\   c              	   C   sf   t j t  |¡¡}t |¡�}t|ƒ}W 5 Q R X |d kr^t |¡�}t| ¡ |dƒ}W 5 Q R X ||fS )Nr0   )	Úosrc   ÚabspathÚfsdecodeÚioÚ	open_coder   ÚcompileÚread)ra   r6   Zdecoded_pathÚfr1   r   r   r   Ú_get_code_from_fileç   s    rl   c                 C   s$  |dkrd}|  d¡d }t| ƒ}d}t|ƒjdkrFt|ƒjdkrFd}t|tdƒƒsX|rxt|| ƒ\}}t|||||d	�S tj	 
d| ¡ zntƒ \}}	}t|ƒ�P}
t| ƒ�< |
jj}t|||||	|ƒ ¡ W  5 Q R £ W  5 Q R £ W ¢S Q R X W 5 Q R X W 5 ztj	 | ¡ W n tk
�r   Y nX X dS )
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
<run_path>r=   r   FZimpZNullImporterT)r4   r5   )rB   r   rQ   r   r   Ú
isinstancerl   r<   r   rc   ÚinsertÚremoverP   r\   r   r   r   r8   r7   r9   )Z	path_namer2   ra   r4   ZimporterZis_NullImporterr1   r6   r   r3   r:   r;   r   r   r   r   ò   s<    
 ÿ
ÿ  ÿ8r@   é   z!No module specified for execution)Úfile)NNNNN)NNNNN)T)NNF)NN)r   r   Úimportlib.machineryrK   Úimportlib.utilrg   r	   rd   Zpkgutilr   r   Ú__all__r!   r   r   r7   r<   rD   rT   Ú	Exceptionr[   r`   r   r\   rl   r   r   Úlenr%   ÚprintÚstderrr   r   r   r   Ú<module>   sN    ÿ       þ
       þ
:
    ÿ

1
