o
    f                     @   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rt|	 |
durt|
  )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   zWrapper 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   zReplacement 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rt
| q| |	d urt|	| _|
d urt|
| _|d urt|| _W |tkrt| |tkrt| |tkrt| d S d S |tkrt| |tkrt| |tkrt| 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,