L i.HdZddlmZddlZddlZddlZddlZddlZddl Z ddl Z ddlm Z ddl m Z mZddlmZddlmZmZmZmZddlmZmZdd lmZdd lmZeeZej:j<ZGd d Z dd Z!GddZ"ddZ#ddZ$ddZ%ddZ&y)zExecute files of Python code.) annotationsN) ModuleSpec)CodeType ModuleType)Any)CoverageExceptionNoCodeNoSource_ExceptionDuringRun)canonical_filenamepython_reported_file)isolate_module)get_python_sourceceZdZdZddZy) DummyLoaderzzA shim for the pep302 __loader__, emulating pkgutil.ImpLoader. Currently only implements the .fullname attribute c||_y)N)fullname)selfr_argss W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/coverage/execfile.py__init__zDummyLoader.__init__$s   N)rstrrrreturnNone)__name__ __module__ __qualname____doc__rrrrrs  !rrc tjj|}|st d||j }|j}|jrS|dz}tjj|}|st d|d|dz|j }|j}|jdd}|||fS#t$r}t t ||d}~wwxYw)zFind the module named `modulename`. Returns the file path of the module, the name of the enclosing package, and the spec. NzNo module named z .__main__z; z- is a package and cannot be directly executed.r) importlibutil find_spec ImportErrorr roriginnamesubmodule_search_locations rpartition) modulenamespecerrpathname packagenamemod_mains r find_moduler1(s*~~'' 3 )*899{{H))K && +~~''1"8*B/N"OPQ ;;ii ((-a0K [$ &&# *s3x c)*sC C$ CC$c2eZdZdZdddZd dZd dZd dZy) PyRunnerzwMulti-stage execution of Python code. This is meant to emulate real Python execution as closely as possible. cz||_||_|d|_d|_d|_d|_d|_d|_y)Nr)args as_modulearg0packager+r.loaderr,)rr5r6s rrzPyRunner.__init__Ms> "G #' &*$( *. '+ rc2ttjddrd}n|jrt j }n|tj j|jr |j}nFtj jtj j|j}tj jtj drtjddjj}tj jtj d}tj jtj j|}t|}t|}||k7rXd}nUtj dtj jtj dk(rtj d=|t!|tj d<yy)zsSet sys.path properly. This needs to happen before any importing, and without importing anything. safe_pathFNr)getattrsysflagsr6osgetcwdpathisdirr7abspathdirnameinspectstackf_code co_filenamer r )rpath0top_filesys_path_0_abstop_file_dir_abss rpreparezPyRunner.prepareXsU 399k5 1E ^^IIKE WW]]499 %IIEGGOOBGGOODII$>?E 77==! % }}r*1-44@@HWW__SXXa[9N!wwrwwx/HI /?N12BC !11 xx{bggoochhqk::HHQK  .u5CHHQK rc|jr|j|_t|j\}|_|_|j |j j |_t|j|_|Jtjj||_ |jx|jd<|_n(tjj|jrdD]v}tjj|jd|}tjj|}tjj!|so||_nt#d|jdt%|}t&j(j+dd||_d|j _d |_td|_ntd|_t%|j|_y) 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)r6r7r+r1r8r,r(rr9rArCrEr.r5rDjoinexistsr r r# machineryr has_location)rr.ext try_filenames r _prepare2zPyRunner._prepare2s >>"iiDO0;DOO0L -HdlDIyy$"&))..%doo6DK' ''GGOOH5DM'+}} 4DIIaL49 WW]]499 %/ Q!ww||DII#7GH  "ww|< 77>>,/ ,DI Q!B499+QOPP0 =L!++66z4P\6]DI%)DII "DL%j1DK%j1DK(3 rc|jtd}|jjd}|j|_|r|jdd|_|j |j |_|j|_|j|j|_ tjd|_ |tjd<|jt_ |rt!|j}nt#|j}t-j.} t1||j2t-jL|y#t$$rt&$r:}d|jd|j(j*d|}t%||d}~wwxYw#t4$rt&$r{tj6\}}} |J|J| Jt9|d d |j:J|j:j<|_tj>||| j<tj@d n#t4$rt&$r}tjBjEd tj6\} } } | J| J| Jd | _#| j:J| j:j<| _tjH| | | j<tjBjEd tK||| j<|d}~wwxYwYwxYw#t-jL|wxYw)zRun the Python code!rS)rQrRNr<builtinszCouldn't run 'z' as Python code: z: __context__r=zError in sys.excepthook: Tz Original exception was: )'r\rr7endswith__file__r8 __package__r9 __loader__r,__spec__r?modules __builtins__r5argvmake_code_from_pycmake_code_from_pyr Exception __class__rrArBexec__dict__ SystemExitexc_infor> __traceback__tb_next excepthookexitstderrwrite__suppress_context____excepthook__r chdir) rmain_modfrom_pyccodeexcmsgcwdtypr-tbtyp2err2tb2s rrunz PyRunner.runs j)99%%&67 II  ( 1 1#2 6H  << ##'<LCb? "?? "?> !> C - ((444$'$5$5$=$=!sC4$ #  I   !=>"%,,.dC''''''&,0)))555%)%7%7%?%?"""4s{{;   !>?)#sBJJ?SH IO' R HHSMsc*-E,F'F$*5FF$'AL5,A I 6L5 L.C L))L..L51L84L55L88MN)F)r5 list[str]r6boolrr)rr)rrrrrrOr\rr rrr3r3Fs ,(6T'4RXrr3c^t|d}|j|jy)aRun 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. Tr6Nr3rOrr5runners rrun_python_modulers#dd +F NN JJLrc^t|d}|j|jy)aGRun 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. FrNrrs rrun_python_filers#de ,F NN JJLrc t|}t||dd}|S#ttf$r}td|d|d}~wwxYw)z8Get source from `filename` and make a code object of it.No file to run: 'rTNrlT)mode dont_inherit)rOSErrorr compile)filenamesourcer|r{s rriri#sYA"8, 68&t DD K X A*8*A67S@As A=Ac t|d}|5|jd}|tk7rtd|dtt j d|jdd }|d z}|r|jd n"|jd|jdtj|}t|tsJ ddd|S#t$r}td|d|d}~wwxYw#1swYSxYw) z#Get a code object from a .pyc file.rbrrTNzBad magic number in .pyc file: z != z?*( Ks# CB:C6 C3C..C36D)r+rrz"tuple[str | None, str, ModuleSpec])r5rrr)rrrr)'r __future__rimportlib.machineryr#importlib.utilrGrrArr?rtypesrrtypingrcoverage.exceptionsrr r r coverage.filesr r coverage.miscrcoverage.pythonrr$ MAGIC_NUMBERrrr1r3rrrirhr rrrs$" *&XXC(-B>>..!!''''<}}@  r