
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3

  \ã  ã               @   sà   d Z ddlZejdkredƒ‚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ddd	gZd
Ze	jZe	jZejƒ Zeedƒr–ejZnejejdfdd„Zddedœdd„ZG dd	„ d	ƒZG dd„ de	jƒZdS )z*
Various Windows specific bits and pieces
é    NZwin32z
win32 onlyÚ
socketpairÚpipeÚPopenÚPIPEÚ
PipeHandlei    c       
      C   s  | t jkrd}n| t jkr d}ntdƒ‚|t jkr:tdƒ‚|dkrJtdƒ‚t j | ||ƒ}z¦|j|dfƒ |jdƒ |jƒ dd	… \}}t j | ||ƒ}yP|jd
ƒ y|j	||fƒ W n t
tfk
rÊ   Y nX |jdƒ |jƒ \}}	W n   |jƒ  ‚ Y nX W d|jƒ  X ||fS )z”A socket pair usable as a self-pipe, for Windows.

        Origin: https://gist.github.com/4325783, by Geert Jansen.
        Public domain.
        z	127.0.0.1z::1z?Only AF_INET and AF_INET6 socket address families are supportedz)Only SOCK_STREAM socket type is supportedr   zOnly protocol zero is supportedé   Né   FT)ÚsocketÚAF_INETZAF_INET6Ú
ValueErrorÚSOCK_STREAMZbindZlistenZgetsocknameZsetblockingZconnectÚBlockingIOErrorÚInterruptedErrorZacceptÚclose)
ZfamilyÚtypeÚprotoÚhostZlsockZaddrZportZcsockZssockÚ_© r   ú-/usr/lib64/python3.6/asyncio/windows_utils.pyr   %   s8    






FT)ÚduplexÚ
overlappedÚbufsizec             C   s"  t jdtjƒ ttƒf d�}| r>tj}tjtj	B }|| }}ntj
}tj	}d| }}|tjO }|d rp|tjO }|d r€tj}nd}d }	}
yZtj||tjd||tjtjƒ}	tj||dtjtj|tjƒ}
tj|	dd�}|jdƒ |	|
fS    |	dk	�rtj|	ƒ |
dk	�rtj|
ƒ ‚ Y nX dS )zELike os.pipe() but with overlapped support and using handles not fds.z\\.\pipe\python-pipe-%d-%d-)Úprefixr   r   NT)r   )ÚtempfileZmktempÚosÚgetpidÚnextÚ_mmap_counterÚ_winapiZPIPE_ACCESS_DUPLEXZGENERIC_READZGENERIC_WRITEZPIPE_ACCESS_INBOUNDZFILE_FLAG_FIRST_PIPE_INSTANCEZFILE_FLAG_OVERLAPPEDZCreateNamedPipeZ	PIPE_WAITZNMPWAIT_WAIT_FOREVERZNULLZ
CreateFileZOPEN_EXISTINGZConnectNamedPipeZGetOverlappedResultÚCloseHandle)r   r   r   ZaddressZopenmodeÚaccessZobsizeZibsizeZflags_and_attribsZh1Zh2Zovr   r   r   r   S   s@    








c               @   s\   e Zd ZdZdd„ Zdd„ Zedd„ ƒZdd	„ Ze	j
d
œdd„Zdd„ Zdd„ Zdd„ ZdS )r   z�Wrapper for an overlapped pipe handle which is vaguely file-object like.

    The IOCP event loop can use these instead of socket objects.
    c             C   s
   || _ d S )N)Ú_handle)ÚselfÚhandler   r   r   Ú__init__ˆ   s    zPipeHandle.__init__c             C   s*   | j d k	rd| j  }nd}d| jj|f S )Nz	handle=%rÚclosedz<%s %s>)r"   Ú	__class__Ú__name__)r#   r$   r   r   r   Ú__repr__‹   s    
zPipeHandle.__repr__c             C   s   | j S )N)r"   )r#   r   r   r   r$   ’   s    zPipeHandle.handlec             C   s   | j d krtdƒ‚| j S )NzI/O operatioon on closed pipe)r"   r   )r#   r   r   r   Úfileno–   s    
zPipeHandle.fileno)r    c            C   s   | j d k	r|| j ƒ d | _ d S )N)r"   )r#   r    r   r   r   r   ›   s    

zPipeHandle.closec             C   s*   | j d k	r&tjd|  t| d� | jƒ  d S )Nzunclosed %r)Úsource)r"   ÚwarningsÚwarnÚResourceWarningr   )r#   r   r   r   Ú__del__    s    
zPipeHandle.__del__c             C   s   | S )Nr   )r#   r   r   r   Ú	__enter__¦   s    zPipeHandle.__enter__c             C   s   | j ƒ  d S )N)r   )r#   ÚtÚvÚtbr   r   r   Ú__exit__©   s    zPipeHandle.__exit__N)r(   Ú
__module__Ú__qualname__Ú__doc__r%   r)   Úpropertyr$   r*   r   r    r   r/   r0   r4   r   r   r   r   r   ƒ   s   c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )r   zˆReplacement for subprocess.Popen using overlapped pipe handles.

    The stdin, stdout, stderr are None or instances of PipeHandle.
    Nc                s¤  |j dƒ st‚|j ddƒdks$t‚d  } }}d  }	 }
}|tkrdtd	dd�\}}	tj|tjƒ}n|}|tkrŒtd
d�\}
}tj|dƒ}n|}|tkr´tdd�\}}tj|dƒ}n|tkrÂ|}n|}zšy t	ƒ j
|f|||dœ|—Ž W n8   x(|	|
|fD ]}|d k	� rütj|ƒ � qüW ‚ Y n>X |	d k	�r6t|	ƒ| _|
d k	�rJt|
ƒ| _|d k	�r^t|ƒ| _W d |tk�rvtj|ƒ |tk�rŠtj|ƒ |tk�ržtj|ƒ X d S )NZuniversal_newlinesr   r   FT)r   r   )r   )ÚstdinÚstdoutÚstderr)FT)TF)TF)ÚgetÚAssertionErrorr   r   ÚmsvcrtZopen_osfhandler   ÚO_RDONLYÚSTDOUTÚsuperr%   r   r    r   r9   r:   r;   r   )r#   Úargsr9   r:   r;   ÚkwdsZ	stdin_rfdZ
stdout_wfdZ
stderr_wfdZstdin_whZ	stdout_rhZ	stderr_rhZstdin_rhZ	stdout_whZ	stderr_whÚh)r'   r   r   r%   µ   sL    










zPopen.__init__)NNN)r(   r5   r6   r7   r%   Ú__classcell__r   r   )r'   r   r   °   s   )TT)r7   ÚsysÚplatformÚImportErrorr   Ú	itertoolsr>   r   r	   Ú
subprocessr   r,   Ú__all__ZBUFSIZEr   r@   Úcountr   Úhasattrr   r
   r   r   r   r   r   r   r   r   Ú<module>   s,   

.0-