3
Z_ð]Í  ã               @   sV  d dl Z d dlZd dlmZ d dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
 d dlZdddgZd	efd
e	fde
fgZejdkrœd dlmZ ejdefƒ ejdeƒ fežŽ  ejdƒZejjdeƒZejdkZeeddƒdkrôG dd„ deƒZnejZG dd„ dejƒZdd„ ZeejƒZeej ƒZ e!edƒ�rHejdƒ eej"ƒZ"[ej#Z#[dS )é    N)ÚFunctionType)Úgreenio)Úpatcher)ÚselectÚ	threadingÚtimeÚcallÚ
check_callÚPopenr   r   r   é   é   )Ú	selectorsr   Ú
subprocessÚwin32ÚTimeoutExpiredc               @   s"   e Zd ZdZddd„Zdd„ ZdS )r   zeThis exception is raised when the timeout expires while waiting for
        a child process.
        Nc             C   s   || _ || _|| _d S )N)ÚcmdÚtimeoutÚoutput)Úselfr   r   r   © r   ú=/tmp/pip-build-yz_zf6az/eventlet/eventlet/green/subprocess.pyÚ__init__!   s    zTimeoutExpired.__init__c             C   s   d| j | jf S )Nz'Command '%s' timed out after %s seconds)r   r   )r   r   r   r   Ú__str__&   s    zTimeoutExpired.__str__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s   
c               @   s²   e Zd ZdZes&d	dd„Zejjje_d
dd„Zejjje_es®e	e
je
jejjƒƒeƒ ƒZy<e	e
je
jejjƒƒeƒ ƒZe	e
je
jejjƒƒeƒ ƒZW n ek
r¬   Y nX dS )r
   z-eventlet-friendly version of subprocess.Popenr   c       	      O   s¦   || _ tjj| |df|ž|Ž x‚d
D ]z}t| |ƒ}|d k	r$t|ƒtjkr$t|ddƒ}|s„|jƒ rh|d7 }|j	ƒ rx|d7 }|dkr„d}tj|||ƒ}t
| ||ƒ q$W d S )Nr   ÚstdinÚstdoutÚstderrÚmodeÚ ÚrÚwé   )r   r   r   éÿÿÿÿ)ÚargsÚsubprocess_origr
   r   ÚgetattrÚtyper   Z	GreenPipeÚreadableÚwritableÚsetattr)	r   r&   ÚbufsizeZargssÚkwdsÚattrÚpiper    Zwrapped_piper   r   r   r   7   s    

zPopen.__init__Nç{®Gáz„?c             C   s–   |d k	rt j ƒ | }yHxB| jƒ }|d k	r,|S |d k	rLt j ƒ |krLt| j|ƒ‚tj|ƒ qW W n4 tk
r� } z|jtjkr~dS ‚ W Y d d }~X nX d S )Nr$   r%   )	r   Úpollr   r&   ÚeventletÚsleepÚOSErrorÚerrnoZECHILD)r   r   Zcheck_intervalÚendtimeÚstatusÚer   r   r   ÚwaitO   s    z
Popen.wait)r   )Nr1   )r   r   r   r   Ú	mswindowsr   r'   r
   r:   r   ÚsixÚget_function_codeÚget_unbound_functionÚ_communicateÚglobalsZ_communicate_with_selectZ_communicate_with_pollÚAttributeErrorr   r   r   r   r
   .   s,   




c             C   s,   t tj| ƒtƒ ƒ}tjr | j|_| j|_|S )N)r   r<   r=   r@   ÚPY3Ú__kwdefaults__Ú__defaults__)ÚfunctionZnew_functionr   r   r   Úpatched_function|   s
    rF   Úcheck_output)r   r   )$r6   ÚsysÚtypesr   r3   r   r   Zeventlet.greenr   r   r   r<   Z__patched__Zto_patchÚversion_infor   ÚappendZinjectr@   Úoriginalr'   ÚmodulesÚgetZsubprocess_importedÚplatformr;   r(   Ú	Exceptionr   r
   rF   r   r	   ÚhasattrrG   ÚCalledProcessErrorr   r   r   r   Ú<module>   s:   



N



