3 \��@s�dZddlZejdkred��ddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddddd gZ d Z e jZe jZej�Zeed�r�ejZnejejdfd d�Zd de d�dd�ZGdd �d �ZGdd�de j�ZdS)z* Various Windows specific bits and pieces �NZwin32z win32 only� socketpair�pipe�Popen�PIPE� PipeHandlei c Cs|tjkrd}n|tjkr d}ntd��|tjkr:td��|dkrJtd��tj|||�}z�|j|df�|jd�|j�dd �\}}tj|||�}yP|jd �y|j ||f�Wnt t fk r�YnX|jd �|j �\}} Wn|j ��YnXWd|j �X||fS) 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 supportedrzOnly protocol zero is supported�N�FT)�socket�AF_INETZAF_INET6� ValueError� SOCK_STREAMZbindZlistenZ getsocknameZ setblockingZconnect�BlockingIOError�InterruptedErrorZaccept�close) Zfamily�type�proto�hostZlsockZaddrZportZcsockZssock�_�r�-/usr/lib64/python3.6/asyncio/windows_utils.pyr%s8        FT)�duplex� overlapped�bufsizec Cs"tjdtj�tt�fd�}|r>tj}tjtj B}||}}ntj }tj }d|}}|tj O}|drp|tj O}|dr�tj }nd}d} } yZtj ||tjd||tjtj�} tj||dtjtj|tj�} tj| dd�} | jd�| | fS| dk �rtj| �| dk �rtj| ��YnXdS)zELike os.pipe() but with overlapped support and using handles not fds.z\\.\pipe\python-pipe-%d-%d-)�prefixrrNT)r)�tempfileZmktemp�os�getpid�next� _mmap_counter�_winapiZPIPE_ACCESS_DUPLEXZ GENERIC_READZ GENERIC_WRITEZPIPE_ACCESS_INBOUNDZFILE_FLAG_FIRST_PIPE_INSTANCEZFILE_FLAG_OVERLAPPEDZCreateNamedPipeZ PIPE_WAITZNMPWAIT_WAIT_FOREVERZNULLZ CreateFileZ OPEN_EXISTINGZConnectNamedPipeZGetOverlappedResult� CloseHandle) rrrZaddressZopenmode�accessZobsizeZibsizeZflags_and_attribsZh1Zh2ZovrrrrSs@           c@s\eZdZdZdd�Zdd�Zedd��Zdd �Ze j d �d d �Z d d�Z dd�Z dd�ZdS)rz�Wrapper for an overlapped pipe handle which is vaguely file-object like. The IOCP event loop can use these instead of socket objects. cCs ||_dS)N)�_handle)�self�handlerrr�__init__�szPipeHandle.__init__cCs*|jdk rd|j}nd}d|jj|fS)Nz handle=%r�closedz<%s %s>)r"� __class__�__name__)r#r$rrr�__repr__�s  zPipeHandle.__repr__cCs|jS)N)r")r#rrrr$�szPipeHandle.handlecCs|jdkrtd��|jS)NzI/O operatioon on closed pipe)r"r )r#rrr�fileno�s zPipeHandle.fileno)r cCs|jdk r||j�d|_dS)N)r")r#r rrrr�s  zPipeHandle.closecCs*|jdk r&tjd|t|d�|j�dS)Nz unclosed %r)�source)r"�warnings�warn�ResourceWarningr)r#rrr�__del__�s  zPipeHandle.__del__cCs|S)Nr)r#rrr� __enter__�szPipeHandle.__enter__cCs |j�dS)N)r)r#�t�v�tbrrr�__exit__�szPipeHandle.__exit__N)r(� __module__� __qualname__�__doc__r%r)�propertyr$r*rr rr/r0r4rrrrr�s cs"eZdZdZd�fdd� Z�ZS)rz�Replacement for subprocess.Popen using overlapped pipe handles. The stdin, stdout, stderr are None or instances of PipeHandle. Nc s�|jd� st�|jdd�dks$t�d}}}d} } } |tkrdtd dd�\} } tj| tj�}n|}|tkr�td d�\} } tj| d�}n|}|tkr�td d�\} }tj|d�}n|tkr�|}n|}z�y t �j |f|||d�|��Wn8x(| | | fD]}|dk �r�t j |��q�W�Yn>X| dk �r6t | �|_| dk �rJt | �|_| dk �r^t | �|_Wd|tk�rvtj|�|tk�r�tj|�|tk�r�tj|�XdS) NZuniversal_newlinesrrFT)rr)r)�stdin�stdout�stderr)FT)TF)TF)�get�AssertionErrorrr�msvcrtZopen_osfhandler�O_RDONLY�STDOUT�superr%rr rr9r:r;r)r#�argsr9r:r;�kwdsZ stdin_rfdZ stdout_wfdZ stderr_wfdZstdin_whZ stdout_rhZ stderr_rhZstdin_rhZ stdout_whZ stderr_wh�h)r'rrr%�sL             zPopen.__init__)NNN)r(r5r6r7r%� __classcell__rr)r'rr�s)TT)r7�sys�platform� ImportErrorr� itertoolsr>rr � subprocessrr,�__all__ZBUFSIZErr@�countr�hasattrrr r rrrrrrr�s,  .0-