a  zeG)@sddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z da ddZ GdddeddZd d Zd d Zd dZddZejejdddZddZd!ddZd"ddZd#ddZd$dd ZdS)%N)source_from_cache)make_legacy_pyccCsTtdurPdtjvrdadSzttjdddgWntjyJdaYn0datS)a  Returns True if our sys.executable interpreter requires environment variables in order to be able to run at all. This is designed to be used with @unittest.skipIf() to annotate tests that need to use an assert_python*() function to launch an isolated mode (-I) or no environment mode (-E) sub-interpreter process. A normal build & test does not run into this situation but it can happen when trying to run the standard library test suite from an interpreter that doesn't have an obvious home with Python's current home finding logic. Setting PYTHONHOME is one way to get most of the testsuite to run in that situation. PYTHONPATH or PYTHONUSERSITE are other common environment variables that might impact whether or not the interpreter can start. NZ PYTHONHOMET-Ez-czimport sys; sys.exit(0)F)$__cached_interp_requires_environmentosenviron subprocess check_callsys executableCalledProcessErrorr r N/opt/bitninja-python-dojo/embedded/lib/python3.9/test/support/script_helper.py interpreter_requires_environments    rc@seZdZdZddZdS)_PythonRunResultz2Helper for reporting Python subprocess run resultscCsd}|j|j}}t||kr0d|| d}t||krNd|| d}|dd}|dd}td|j|||fdS)z4Provide helpful details about failed subcommand runsi@s(... truncated stdout ...)Ns(... truncated stderr ...)asciireplacezRProcess return code is %d command line: %r stdout: --- %s --- stderr: --- %s ---)outerrlendecoderstripAssertionErrorrc)selfcmd_linemaxlenrrr r rfail;s   z_PythonRunResult.failN)__name__ __module__ __qualname____doc__rr r r rr8sr)rrrc OsDt}|dd}d|vr&|d}n | o0| }tjddg}|rN|dn|s`|s`|d|ddri}tjdkrtjd |d <n tj}d |vrd |d <| || |t j |t j t j t j ||d }|Dz |\}} W|t n|t 0Wdn1s$0Y|j} t| || |fS) NZ__cwdZ __isolatedz-X faulthandlerz-IrZ __cleanenvwin32Z SYSTEMROOTTERM)stdinstdoutstderrenvcwd)rpopr r appendplatformrrcopyupdateextendrPopenPIPE communicatekill_cleanup returncoder) argsenv_varsZ env_requiredr*isolatedrr)procrrrr r rrun_python_until_endXs@             *r;cOs4t|i|\}}|jr|s&|js0|s0|||S)N)r;rr)Zexpected_successr7r8resrr r r_assert_pythons r=cOstdg|Ri|S)a| Assert that running the interpreter with `args` and optional environment variables `env_vars` succeeds (rc == 0) and return a (return code, stdout, stderr) tuple. If the __cleanenv keyword is set, env_vars is used as a fresh environment. Python is started in isolated mode (command line option -I), except if the __isolated keyword is set to False. Tr=r7r8r r rassert_python_oks r@cOstdg|Ri|S)z Assert that running the interpreter with `args` and optional environment variables `env_vars` fails (rc != 0) and return a (return code, stdout, stderr) tuple. See assert_python_ok() for more options. Fr>r?r r rassert_python_failuresrA)r'r(cOsXtjg}ts|d|||dttj}d|d<t j |ft j ||d|S)zRun a Python subprocess with the given arguments. kw is extra keyword args to pass to subprocess.Popen. Returns a Popen object. rr)Zvt100r$)r&r'r() r r rr,r0 setdefaultdictrrrr1r2)r'r(r7kwrr)r r r spawn_pythons   rEcCs2|j|j}|j|t|S)z?Run the given Popen process until completion and return stdout.)r&closer'readwaitrr5)pdatar r r kill_pythons    rKFcCsh|}|s|tjd7}tj||}t|ddd}||Wdn1sR0Yt|S)Npywzutf-8)encoding)rextseppathjoinopenwrite importlibinvalidate_caches)Z script_dirscript_basenamesourceZ omit_suffixZscript_filename script_nameZ script_filer r r make_scripts(rYc Cs|tjd}tj||}t|dr}|dur|tj}t|dkrt|ddkrtt t |}tj |}|}n tj |}| ||Wdn1s0Y|tj||fS)NziprM __pycache__) rrOrPrQzipfileZipFilesplitseprrrbasenamerS) zip_dir zip_basenamerXZ name_in_zip zip_filenamezip_namezip_filepartsZ legacy_pycr r rmake_zip_scripts    *rir%cCst|t|d|dS)N__init__)rmkdirrY)Zpkg_dirZ init_sourcer r rmake_pkgs rlcsBg}t|dd}||tj|} t|||} || |rjtj|dd}tj| dd} ||| ffddtd|dD} tj | dtj| } |tj d } tj || }t |d @}| D]}tj || }| ||q| | | Wdn1s0Y|D]}t|q|tj || fS) Nrjr%T)doraisecsg|]}tjg|qSr )rrarQ).0ipkg_namer r z make_zip_pkg..rmrZrM)rYr,rrPrb py_compilecompiler0rangerQrOr^r_rSunlink)rcrdrrrVrWdepthZcompiledryZ init_nameZ init_basenamerXZ pkg_namesZscript_name_in_ziprerfrgnameZinit_name_in_zipr rqr make_zip_pkgs,     ,r|)F)N)r%)rmF) collectionsrTr rZos.pathrrvr^importlib.utilrZ test.supportrrr namedtuplerr;r=r@rAr2STDOUTrErKrYrirlr|r r r rs2  $ 3