
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
ct„jˆ)  ã               @   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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add„ ZG dd„ de jdd#ƒƒZdd„ Zdd„ Zdd„ Zdd„ Zejejdœdd„Zdd„ Zd$dd„Zd%dd„Zd&dd„Zd'd!d"„ZdS )(é    N)Úsource_from_cache)Úmake_legacy_pycÚstrip_python_stderrc               C   sV   t dkrRdtjkrda dS ytjtjdddgƒ W n tjk
rL   da Y nX da t S )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
PYTHONHOMETz-Ez-czimport sys; sys.exit(0)F)Ú$__cached_interp_requires_environmentÚosÚenvironÚ
subprocessZ
check_callÚsysÚ
executableZCalledProcessError© r   r   ú2/usr/lib64/python3.6/test/support/script_helper.pyÚ interpreter_requires_environment   s    


r   c               @   s   e Zd ZdZdd„ ZdS )Ú_PythonRunResultz2Helper for reporting Python subprocess run resultsc             C   sˆ   d	}| j | j }}t|ƒ|kr0d|| d…  }t|ƒ|krNd|| d…  }|jddƒjƒ }|jddƒjƒ }td| j|||f ƒ‚dS )
z4Provide helpful details about failed subcommand runséP   éd   s   (... truncated stdout ...)Ns   (... truncated stderr ...)ÚasciiÚreplacezRProcess return code is %d
command line: %r

stdout:
---
%s
---

stderr:
---
%s
---i@  )ÚoutÚerrÚlenÚdecodeÚrstripÚAssertionErrorÚrc)ÚselfÚcmd_lineÚmaxlenr   r   r   r   r   Úfail>   s    z_PythonRunResult.failN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   ;   s   r   r   r   r   c        
      O   s  t ƒ }d|kr|jdƒ}n| o$| }tjddg}|rB|jdƒ n| rX| rX|jdƒ |jdd ƒr‚i }tjdkrŒtjd |d< n
tjjƒ }d	|krœd
|d	< |j	|ƒ |j
| ƒ tj|tjtjtj|d�}|�* z|jƒ \}}W d |jƒ  tjƒ  X W d Q R X |j}	t|ƒ}t|	||ƒ|fS )NZ
__isolatedz-XZfaulthandlerz-Iz-EZ
__cleanenvZwin32Z
SYSTEMROOTÚTERMÚ )ÚstdinÚstdoutÚstderrÚenv)r   Úpopr	   r
   ÚappendÚplatformr   r   ÚcopyÚupdateÚextendr   ÚPopenÚPIPEZcommunicateÚkillÚ_cleanupÚ
returncoder   r   )
ÚargsÚenv_varsZenv_requiredÚisolatedr   r'   Úprocr   r   r   r   r   r   Úrun_python_until_end[   s:    





r7   c             O   s4   t ||Ž\}}|jr| s&|j r0|  r0|j|ƒ |S )N)r7   r   r   )Zexpected_successr3   r4   Úresr   r   r   r   Ú_assert_pythonŽ   s    
r9   c              O   s   t d| ž|Ž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.
    T)T)r9   )r3   r4   r   r   r   Úassert_python_ok”   s    r:   c              O   s   t d| ž|Ž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.
    F)F)r9   )r3   r4   r   r   r   Úassert_python_failure¡   s    r;   )r%   r&   c             O   sX   t jg}tƒ s|jdƒ |j|ƒ |jdttjƒƒ}d|d< t	j
|ft	j| |dœ|—ŽS )z�Run a Python subprocess with the given arguments.

    kw is extra keyword args to pass to subprocess.Popen. Returns a Popen
    object.
    z-Er'   Zvt100r"   )r$   r%   r&   )r	   r
   r   r)   r-   Ú
setdefaultÚdictr   r   r   r.   r/   )r%   r&   r3   Úkwr   r'   r   r   r   Úspawn_python«   s    

r?   c             C   s2   | j jƒ  | jjƒ }| jjƒ  | jƒ  tjƒ  |S )z?Run the given Popen process until completion and return stdout.)r$   Úcloser%   ÚreadÚwaitr   r1   )ÚpÚdatar   r   r   Úkill_pythonÁ   s    


rE   Fc             C   sP   |}|s|t jd 7 }t jj| |ƒ}t|ddd�}|j|ƒ |jƒ  tjƒ  |S )NÚpyÚwzutf-8)Úencoding)	r   ÚextsepÚpathÚjoinÚopenÚwriter@   Ú	importlibÚinvalidate_caches)Z
script_dirÚscript_basenameÚsourceZomit_suffixZscript_filenameÚscript_nameZscript_filer   r   r   Úmake_scriptÌ   s    
rS   c       	      C   s¤   |t j d }t jj| |ƒ}tj|dƒ}|d kr~|jt jƒ}t|ƒdkrr|d dkrrt	t
|ƒƒ}t jj|ƒ}|}nt jj|ƒ}|j||ƒ |jƒ  |t jj||ƒfS )NÚziprG   é   Ú__pycache__éþÿÿÿ)r   rI   rJ   rK   ÚzipfileÚZipFileÚsplitÚsepr   r   r   ÚbasenamerM   r@   )	Úzip_dirÚzip_basenamerR   Zname_in_zipÚzip_filenameÚzip_nameÚzip_fileÚpartsZ
legacy_pycr   r   r   Úmake_zip_scriptØ   s    rc   r#   c             C   s   t j| ƒ t| d|ƒ d S )NÚ__init__)r   ÚmkdirrS   )Zpkg_dirZinit_sourcer   r   r   Úmake_pkgí   s    
rf   é   c                s0  g }t | ddƒ}|j|ƒ tjj|ƒ}	t | ||ƒ}
|j|
ƒ |rjtj|dd�}tj|
dd�}
|j||
fƒ ‡ fdd„td|d ƒD ƒ}tjj	|d
 tjj|
ƒƒ}|tj
 d }tjj	| |ƒ}tj|d	ƒ}x&|D ]}tjj	||	ƒ}|j||ƒ qÎW |j|
|ƒ |jƒ  x|D ]}tj|ƒ �q
W |tjj	||ƒfS )Nrd   r#   T)Údoraisec                s   g | ]}t jjˆ g| ƒ‘qS r   )r   r[   rK   )Ú.0Úi)Úpkg_namer   r   ú
<listcomp>ý   s    z make_zip_pkg.<locals>.<listcomp>rg   rT   rG   éÿÿÿÿ)rS   r)   r   rJ   r\   Ú
py_compileÚcompiler-   ÚrangerK   rI   rX   rY   rM   r@   Úunlink)r]   r^   rk   rP   rQ   ZdepthZcompiledrq   Z	init_nameZinit_basenamerR   Z	pkg_namesZscript_name_in_zipr_   r`   ra   ÚnameZinit_name_in_zipr   )rk   r   Úmake_zip_pkgñ   s.    



rs   )r   r   r   )F)N)r#   )rg   F) ÚcollectionsrN   r	   r   Zos.pathZtempfiler   rn   Ú
contextlibZshutilrX   Úimportlib.utilr   Ztest.supportr   r   r   r   Ú
namedtupler   r7   r9   r:   r;   r/   ZSTDOUTr?   rE   rS   rc   rf   rs   r   r   r   r   Ú<module>   s4   $3



