o
    >c73                     @   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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ree jdk rzede jd dS e jd = ee jd   dS dS )"    N
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   Y/Volumes/Data/workspace/med-macos-weekly/build/ExtProjs/pyncpp/python/source/Lib/runpy.py__init__   s   
z_TempModule.__init__c                 C   s@   | j }z| jtj|  W n	 ty   Y nw | 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   0   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   4   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   /   s    r   c           
   	   C   sp   	 |d ur
| | |d u rd }|}d }	n|j}|j}|j}	|d u r%|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,   

r6   c           	   
   C   s   	 |d u r|n|j }t|7}t| |jj}t| |||||| W d    n1 s,w   Y  W d    | S W d    | S 1 sHw   Y  | S r   )r,   r   r   r	   __dict__r6   copy)	r0   r1   r   r2   r3   r4   r5   temp_modulemod_globalsr   r   r   _run_module_codeY   s   (r;   c                 C   s.  |  dr	|d| d\}}}|razt| W n% ty> } z|jd u s3|j|kr4| |jd s4 W Y d }~nd }~ww tj| }|d urat|dsaddl	m
} dj| |d}|t| ztj| }W n3 ttttfy }	 z#d}| d	r|d
| d d  d|  d7 }||| t|	j|	|	d }	~	ww |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 d }~ww |j}|d u r|d|  z|| }W n ty } z|t||d }~ww |d u 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   r3   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   errorr3   _eZexistingr>   msgspecZexZpkg_main_namer+   r0   r   r   r   rT   g   sz   


	



rT   c                   @   s   e Zd ZdS )_ErrorN)r   r   r   r   r   r   r   r[      s    r[   Tc              
   C   s   	 z|s| dkrt | t\} }}ntt\} }}W n ty7 } zdtj|f }t| W Y d }~nd }~ww tjd j}|rF|jtj	d< t
||d d|S )Nr@   z%s: %sr   )rT   r[   _get_main_module_detailsr   
executableexitr   r7   r,   r#   r6   )r   Z
alter_argvr2   r0   excrY   Zmain_globalsr   r   r   _run_module_as_main   s"   r`   Fc                 C   s>   	 t | \} }}|d u r| }|rt||||S t|i |||S r   )rT   r;   r6   )r   r1   run_name	alter_sysr2   r0   r   r   r   r      s   c              
   C   sz   d}t j| }t j|= z+zt|W W |t j|< S  ty6 } z|t|v r1| d|t jd f | d }~ww |t j|< w )Nr@   zcan't find %r module in %rr   )r   r   rT   rD   strpath)rV   	main_nameZ
saved_mainr_   r   r   r   r\      s"   

r\   c                 C   s   ddl m} tjt|}t|}||}W d    n1 s#w   Y  |d u rLt|}t|	 |d}W d    ||fS 1 sGw   Y  ||fS )Nr   )	read_coder/   )
pkgutilrf   osrd   abspathfsdecodeio	open_codecompileread)ra   r5   rf   Zdecoded_pathfr0   r   r   r   _get_code_from_file   s   

rp   c                 C   s  	 |d u rd}| dd }ddlm} || }d}t|jdkr*t|jdkr*d}t|td s3|rCt|| \}}t|||||d	S t	j
d|  zkt \}	}
}t|D}t| 0 |jj}t|||||
| W  d    W  d    W zt	j
|  W S  ty   Y S w 1 sw   Y  W d    n1 sw   Y  W z	t	j
|  W d S  ty   Y d S w zt	j
|  W w  ty   Y w w )
Nz
<run_path>r<   r   )get_importerFZimpZNullImporterT)r3   r4   )rB   rg   rq   rR   r   r   
isinstancerp   r;   r   rd   insertr\   r   r   r	   r7   r6   r8   removerP   )Z	path_namer1   ra   r3   rq   ZimporterZis_NullImporterr0   r5   r   r2   r9   r:   r   r   r   r     sX   
.r@      z!No module specified for execution)file)NNNNN)T)NNF)NN)r   Zimportlib.machineryrK   Zimportlib.utilrk   r   rh   __all__r   r   r   r6   r;   rD   rT   	Exceptionr[   r`   r   r\   rp   r   r   lenr#   printstderrr   r   r   r   <module>   sD    

=


7