a
    "h3                     @   s  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  rede jd ne jd = ee jd   dS )$    N)	read_codeget_importer
run_modulerun_pathc                   @   s$   e Zd Zdd Zdd Zdd ZdS )_TempModulec                 C   s   || _ t|| _g | _d S N)mod_nametypes
ModuleTypemodule_saved_moduleselfr    r   -/opt/python-3.9.21/usr/lib/python3.9/runpy.py__init__   s    z_TempModule.__init__c                 C   s@   | j }z| jtj|  W n ty.   Y n0 | 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__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u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__Nr   r   r   r   r   r   0   s   r   c           
   	   C   sn   |d ur| | |d u r(d }|}d }	n |j}|j}|j}	|d u rH|j}|j |||	d |||d t| | |S )N)r   __file__
__cached____doc__
__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*    

r8   c           	   
   C   s   |d u r|n|j }t|T}t|, |jj}t| |||||| W d    n1 sV0    Y  W d    n1 st0    Y  | S r   )r.   r   r   r   __dict__r8   copy)	r2   r3   r   r4   r5   r6   r7   temp_modulemod_globalsr   r   r   _run_module_codeZ   s    @r=   c                 C   sd  |  dr|d| d\}}}|rzt| W nJ ty| } z2|jd u sf|j|krh| |jd sh W Y d }~n
d }~0 0 tj| }|d urt|dsddl	m
} dj| |d}|t| ztj| }W nv ttttfyH }	 zTd}| d	r|d
| d d  d|  d7 }||| t|	j|	|	W Y d }	~	n
d }	~	0 0 |d u r`|d|  |jd ur| dks| dr|dz| d }
t|
|W S  |y } z*| tjvr |d|| f W Y d }~n
d }~0 0 |j}|d u r |d|  z|| }W n4 tyB } z|t||W Y d }~n
d }~0 0 |d u rZ|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   r5   z:Error while finding module specification for {!r} ({}: {})z.pyz. Try using 'z' instead of 'z' as the module name.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endswithtyper   submodule_search_locations_get_module_detailsr-   get_code)r   errorr5   _eexistingr@   msgspecexZpkg_main_namer-   r2   r   r   r   rV   h   sj    

0

$
rV   c                   @   s   e Zd ZdS )_ErrorN)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yl } z$dtj|f }t| W Y d }~n
d }~0 0 tjd j}|r|jtj	d< t
||d d|S )NrB   z%s: %sr   )rV   r_   _get_main_module_detailsr   
executableexitr   r9   r.   r%   r8   )r   Z
alter_argvr4   r2   excr\   Zmain_globalsr   r   r   _run_module_as_main   s     rd   Fc                 C   s@   t | \} }}|d u r| }|r,t||||S t|i |||S d S r   )rV   r=   r8   )r   r3   run_nameZ	alter_sysr4   r2   r   r   r   r      s    c              
   C   s   d}t j| }t j|= zpzt|W W |t j|< S  tyx } z2|t|v rb| d|t jd f | W Y d }~n
d }~0 0 W |t j|< n|t j|< 0 d S )NrB   zcan't find %r module in %rr   )r   r   rV   rF   strpath)rX   Z	main_nameZ
saved_mainrc   r   r   r   r`      s     


r`   c                 C   s   t jt |}t|}t|}W d    n1 s:0    Y  |d u rt| }t| |d}W d    n1 s|0    Y  ||fS )Nr1   )	osrg   abspathfsdecodeio	open_coder   compileread)re   r7   Zdecoded_pathfr2   r   r   r   _get_code_from_file   s    &.rp   c                 C   s  |d u 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|  zt \}}	}t|}
t| d |
jj}t|||||	| W  d    W  d    W ztj	|  W S  ty   Y S 0 S 1 s0    Y  W d    n1 s20    Y  W ztj	|  W n tyb   Y n0 n(ztj	|  W n ty   Y n0 0 d S )	Nz
<run_path>r>   r   FZimpZNullImporterT)r5   r6   )rD   r   rT   r   r   
isinstancerp   r=   r   rg   insertr`   r   r   r   r9   r8   r:   removerR   )Z	path_namer3   re   r5   ZimporterZis_NullImporterr2   r7   r   r4   r;   r<   r   r   r   r     sH    
$6rB      z!No module specified for execution)file)NNNNN)NNNNN)T)NNF)NN)r   Zimportlib.machineryrM   importlib.utilrk   r	   rh   Zpkgutilr   r   __all__r!   r   r   r8   r=   rF   rV   	Exceptionr_   rd   r   r`   rp   r   r   lenr%   printstderrr   r   r   r   <module>   s@      
   
=
  

6
