o
    éT•jÄ  ã                   @   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ZdZejZejZe ¡ 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.é    NÚwin32z
win32 only)ÚpipeÚPopenÚPIPEÚ
PipeHandlei    F)TT)ÚduplexÚ
overlappedÚbufsizec              
   C   s  t jd t ¡ ttƒ¡d�}| rtj}tj	tj
B }||}}ntj}tj
}d|}}|tjO }|d r8|tjO }|d r@tj}nd}d }	}
z.t ||tjd||tjtj¡}	t ||dtjtj|tj¡}
tj|	dd�}| d¡ |	|
fW S    |	dur�t |	¡ |
durŠt |
¡ ‚ )zELike os.pipe() but with overlapped support and using handles not fds.z\\.\pipe\python-pipe-{:d}-{:d}-)Úprefixr   é   NT©r   )ÚtempfileÚmktempÚformatÚosÚgetpidÚnextÚ_mmap_counterÚ_winapiÚPIPE_ACCESS_DUPLEXÚGENERIC_READÚGENERIC_WRITEÚPIPE_ACCESS_INBOUNDÚFILE_FLAG_FIRST_PIPE_INSTANCEÚFILE_FLAG_OVERLAPPEDÚCreateNamedPipeÚ	PIPE_WAITÚNMPWAIT_WAIT_FOREVERÚNULLÚ
CreateFileÚOPEN_EXISTINGÚConnectNamedPipeÚGetOverlappedResultÚCloseHandle)r   r   r	   ÚaddressÚopenmodeÚaccessÚobsizeÚibsizeÚflags_and_attribsÚh1Úh2Úov© r-   ú,/usr/lib/python3.10/asyncio/windows_utils.pyr       sJ   ÿÿ


þþ



r   c                   @   sb   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ejf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__V   s   
zPipeHandle.__init__c                 C   s2   | j d urd| j ›�}nd}d| jj› d|› d�S )Nzhandle=Úclosedú<ú ú>)r1   Ú	__class__Ú__name__r2   r-   r-   r.   Ú__repr__Y   s   
zPipeHandle.__repr__c                 C   s   | j S r/   r0   ©r3   r-   r-   r.   r4   `   s   zPipeHandle.handlec                 C   s   | j d u r	tdƒ‚| j S )NzI/O operation on closed pipe)r1   Ú
ValueErrorr=   r-   r-   r.   Úfilenod   s   
zPipeHandle.fileno)r#   c                C   s"   | j d ur|| j ƒ d | _ d S d S r/   r0   )r3   r#   r-   r-   r.   Úclosei   s   


þzPipeHandle.closec                 C   s.   | j d ur|d| ›�t| d� |  ¡  d S d S )Nz	unclosed )Úsource)r1   ÚResourceWarningr@   )r3   Ú_warnr-   r-   r.   Ú__del__n   s   
þzPipeHandle.__del__c                 C   s   | S r/   r-   r=   r-   r-   r.   Ú	__enter__s   s   zPipeHandle.__enter__c                 C   s   |   ¡  d S r/   )r@   )r3   ÚtÚvÚtbr-   r-   r.   Ú__exit__v   s   zPipeHandle.__exit__N)r;   Ú
__module__Ú__qualname__Ú__doc__r5   r<   Úpropertyr4   r?   r   r#   r@   ÚwarningsÚwarnrD   rE   rI   r-   r-   r-   r.   r   Q   s    
r   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Â  |  d¡rJ ‚|  dd¡dksJ ‚d  } }}d  }	 }
}|tkr1tddd�\}}	t |tj¡}n|}|tkrEtdd�\}
}t |d¡}n|}|tkrYtdd�\}}t |d¡}n	|tkr`|}n|}zaztƒ j	|f|||d	œ|¤Ž W n   |	|
|fD ]}|d ur‡t
 |¡ q|‚ |	d ur’t|	ƒ| _|
d ur›t|
ƒ| _|d ur¤t|ƒ| _W |tkr®t |¡ |tkr·t |¡ |tkrÂt |¡ d S d S |tkrÍt |¡ |tkrÖt |¡ |tkràt |¡ w w )
NÚuniversal_newlinesr	   r   )FTT)r   r   )TFr   )ÚstdinÚstdoutÚstderr)Úgetr   r   ÚmsvcrtÚopen_osfhandler   ÚO_RDONLYÚSTDOUTÚsuperr5   r   r#   r   rQ   rR   rS   r@   )r3   ÚargsrQ   rR   rS   ÚkwdsÚ	stdin_rfdÚ
stdout_wfdÚ
stderr_wfdÚstdin_whÚ	stdout_rhÚ	stderr_rhÚstdin_rhÚ	stdout_whÚ	stderr_whÚh©r:   r-   r.   r5   ‚   sf   ÿ
ÿ
€


€

ÿü

ÿzPopen.__init__)NNN)r;   rJ   rK   rL   r5   Ú__classcell__r-   r-   rf   r.   r   }   s    r   )rL   ÚsysÚplatformÚImportErrorr   Ú	itertoolsrU   r   Ú
subprocessr   rN   Ú__all__ÚBUFSIZEr   rX   Úcountr   r   r   r   r-   r-   r-   r.   Ú<module>   s&    
1,