
    L-Ph/                    @   d Z ddlm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
Z
ddlmZ ddlmZmZ ddlmZ ddlmZmZmZmZ ddlmZmZ dd	lmZ dd
lmZ  ee          Zej        j        Z G d d          Z ddZ! G d d          Z"ddZ#ddZ$ddZ%ddZ&dS ) zExecute files of Python code.    )annotationsN)
ModuleSpec)CodeType
ModuleType)Any)CoverageException_ExceptionDuringRunNoCodeNoSource)canonical_filenamepython_reported_file)isolate_module)get_python_sourcec                      e Zd ZdZd
dZd	S )DummyLoaderzzA shim for the pep302 __loader__, emulating pkgutil.ImpLoader.

    Currently only implements the .fullname attribute
    fullnamestr_argsr   returnNonec                    || _         d S )N)r   )selfr   r   s      Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/coverage/execfile.py__init__zDummyLoader.__init__#   s         N)r   r   r   r   r   r   )__name__
__module____qualname____doc__r    r   r   r   r      s2         ! ! ! ! ! !r   r   
modulenamer   r   "tuple[str | None, str, ModuleSpec]c                   	 t           j                            |           }n/# t          $ r"}t	          t          |                    |d}~ww xY w|st	          d|           |j        }|j        }|j        rM| dz   }t           j                            |          }|st	          d| d| dz             |j        }|j        }|	                    d          d         }|||fS )zFind the module named `modulename`.

    Returns the file path of the module, the name of the enclosing
    package, and the spec.
    NzNo module named z	.__main__z; z- is a package and cannot be directly executed.r   )
	importlibutil	find_specImportErrorr   r   originnamesubmodule_search_locations
rpartition)r!   specerrpathnamepackagenamemod_mains         r   find_moduler2   '   s   *~''
33 * * *s3xx  c)* :8*88999{H)K& 	 +~''11 	/8///NNNO   ;i((--a0K[$&&s   " 
AA		Ac                  4    e Zd ZdZddd	Zdd
ZddZddZdS )PyRunnerzwMulti-stage execution of Python code.

    This is meant to emulate real Python execution as closely as possible.

    Fargs	list[str]	as_moduleboolr   r   c                    || _         || _        |d         | _        d | _        d | _        d | _        d | _        d | _        d S )Nr   )r5   r7   arg0packager!   r/   loaderr-   )r   r5   r7   s      r   r   zPyRunner.__init__K   sB    	"G	#'&*$(*.'+			r   c                   t          t          j        dd          rd}n| j        rt	          j                    }nmt          j                            | j                  r| j        }nAt          j        	                    t          j        
                    | j                            }t          j                            t          j        d                   rt          j                    d         d         j        j        }t          j        	                    t          j        d                   }t          j        	                    t          j        
                    |                    }t          |          }t          |          }||k    rd}nPt          j        d         t          j        
                    t          j        d                   k    rt          j        d= |t!          |          t          j        d<   dS dS )zsSet sys.path properly.

        This needs to happen before any importing, and without importing anything.
        	safe_pathFNr      )getattrsysflagsr7   osgetcwdpathisdirr:   abspathdirnameinspectstackf_codeco_filenamer   r   )r   path0top_filesys_path_0_abstop_file_dir_abss        r   preparezPyRunner.prepareV   sx    39k511 
	@EE^ 	@IKKEEW]]49%% 	@ IEEGOOBGOODI$>$>??E7==!%% 	  }r*1-4@HW__SXa[99N!wrwx/H/HII/??N12BCC!111
 x{bgoochqk::::HQK.u55CHQKKK r   c                   | j         r| j        | _        t          | j                  \  }| _        | _        | j        | j        j        | _        t          | j                  | _        |J t          j
                            |          | _        | j        x| j        d<   | _        n"t          j
                            | j                  rdD ]q}t          j
                            | j        d|           }t          j
                            |          }t          j
                            |          r	|| _         nrt#          d| j         d          t%          |          }t&          j                            dd|          | _        d| j        _        d	| _        t          d          | _        nt          d          | _        t%          | j                  | _        dS )
zDo more preparation to run Python code.

        Includes finding the module to run and adjusting sys.argv[0].
        This method is allowed to import code.

        Nr   )z.py.pyc.pyo__main__z!Can't find '__main__' module in '')r)   T )r7   r:   r!   r2   r;   r-   r*   r   r<   rD   rF   rH   r/   r5   rG   joinexistsr   r   r%   	machineryr   has_location)r   r/   exttry_filenames       r   	_prepare2zPyRunner._prepare2   s    > 	2"iDO0;DO0L0L-HdlDIy$"&).%do66DK'''GOOH55DM'+}4DIaL499W]]49%% 	2 / 	Q 	Q!w||DI7G#7G7GHH  "w|<<7>>,//  ,DIE O49OOOPPP 0==L!+66z4P\6]]DI%)DI"DL%j11DKK%j11DK(33			r   c                    |                                   t          d          }| j                            d          }| j        |_        |r|j        dd         |_        | j        | j        |_        | j        |_        | j	        | j	        |_
        t          j        d         |_        |t          j        d<   | j        t          _        	 |rt!          | j                  }nt#          | j                  }nF# t$          $ r  t&          $ r/}d| j         d|j        j         d| }t%          |          |d}~ww xY wt-          j                    }	 t1          ||j                   nj# t4          $ r  t&          $ rR t          j                    \  }}}	|J |J |	J t9          |d	d           	 |j        J |j        j        |_        t          j        |||	j                   t          j         d
           n# t4          $ r  t&          $ r}t          j!        "                    d           t          j                    \  }
}}|
J |J |J d|_#        |j        J |j        j        |_        t          j$        |
||j                   t          j!        "                    d           tK          |||	j                  |d}~ww xY wY nw xY wt-          j&        |           dS # t-          j&        |           w xY w)zRun the Python code!rV   )rT   rU   Nr?   builtinszCouldn't run 'z' as Python code: z: __context__r@   zError in sys.excepthook:
Tz
Original exception was:
)'r_   r   r:   endswith__file__r;   __package__r<   
__loader__r-   __spec__rB   modules__builtins__r5   argvmake_code_from_pycmake_code_from_pyr   	Exception	__class__r   rD   rE   exec__dict__
SystemExitexc_inforA   __traceback__tb_next
excepthookexitstderrwrite__suppress_context____excepthook__r	   chdir)r   main_modfrom_pyccodeexcmsgcwdtypr.   tbtyp2err2tb2s                r   runzPyRunner.run   sK    	 j))9%%&677 I 	7 ( 1#2# 6H<##'<H "k9  $	H #J 7"*J 9
	2 4)$)44(33  	 	 	 	2 	2 	2_49__@V__Z]__C#C((c1	2 ikk/	x()))) 	 	 	  '	 '	 '	 <>>LCb??????>>> C---(444$'$5$=!sC444$ #     I I I 
  !=>>>"%,..dC'''''',0))555%)%7%?""4s{;;;
  !>???)#sBJ??SHI O'	R HSMMMMMBHSMMMMsh   
+C6 6D9
*D44D9E' %K' 'A	K15G;&K;KB4KKKK' KK' 'K=N)F)r5   r6   r7   r8   r   r   )r   r   )r   r   r   r   r   rR   r_   r   r    r   r   r4   r4   E   s{         
	, 	, 	, 	, 	,(6 (6 (6 (6T'4 '4 '4 '4RX X X X X Xr   r4   r5   r6   r   c                x    t          | d          }|                                 |                                 dS )a  Run a Python module, as though with ``python -m name args...``.

    `args` is the argument array to present as sys.argv, including the first
    element naming the module being executed.

    This is a helper for tests, to encapsulate how to use PyRunner.

    Tr7   Nr4   rR   r   r5   runners     r   run_python_moduler     s7     dd+++F
NN
JJLLLLLr   c                x    t          | d          }|                                 |                                 dS )aG  Run a Python file as if it were the main program on the command line.

    `args` is the argument array to present as sys.argv, including the first
    element naming the file being executed.  `package` is the name of the
    enclosing package, if any.

    This is a helper for tests, to encapsulate how to use PyRunner.

    Fr   Nr   r   s     r   run_python_filer     s7     de,,,F
NN
JJLLLLLr   filenamer   c                    	 t          |           }n-# t          t          f$ r}t          d|  d          |d}~ww xY wt          || dd          }|S )z8Get source from `filename` and make a code object of it.No file to run: 'rW   Nro   T)modedont_inherit)r   OSErrorr   compile)r   sourcer   r~   s       r   rl   rl   !  sx    A"8,,X A A A6866677S@A 68&tDDDDKs    <7<c                `   	 t          | d          }n&# t          $ r}t          d|  d          |d}~ww xY w|5  |                    d          }|t          k    rt          d|dt                    t          j        d|                    d                    d	         }|d
z  }|r|                    d           n*|                    d           |                    d           t          j        |          }t          |t                    sJ 	 ddd           n# 1 swxY w Y   |S )z#Get a code object from a .pyc file.rbr   rW   N   zBad magic number in .pyc file: z != z<Lr   r@      )openr   r
   readPYC_MAGIC_NUMBERstructunpackmarshalload
isinstancer   )r   fpycr   magicrC   
hash_basedr~   s          r   rk   rk   ,  s   ?Hd## ? ? ?4444553>? 
 * * 		!$$$\5\\HX\\]]]dDIIaLL11!4T\
 	IIaLLLL IIaLLLIIaLLL |D!!$))))))%* * * * * * * * * * * * * * *( Ks"    
616CD##D'*D')r!   r   r   r"   )r5   r6   r   r   )r   r   r   r   )'r   
__future__r   importlib.machineryr%   importlib.utilrJ   r   rD   r   rB   r   typesr   r   typingr   coverage.exceptionsr   r	   r
   r   coverage.filesr   r   coverage.miscr   coverage.pythonr   r&   MAGIC_NUMBERr   r   r2   r4   r   r   rl   rk   r    r   r   <module>r      s   $ # " " " " " "           				  



 * * * * * * & & & & & & & &       X X X X X X X X X X X X C C C C C C C C ( ( ( ( ( ( - - - - - -^B >. ! ! ! ! ! ! ! !' ' ' '<| | | | | | | |~              r   