
    Rh                        d Z ddlZej                  dk7  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j                         Zdded	d
Z G d d      Z G d dej&                        Zy)z)Various Windows specific bits and pieces.    Nwin32z
win32 only)pipePopenPIPE
PipeHandlei    F)TT)duplex
overlappedbufsizec           
         t        j                  dj                  t        j                         t        t                          }| r6t        j                  }t        j                  t        j                  z  }||}}n$t        j                  }t        j                  }d|}}|t        j                  z  }|d   r|t        j                  z  }|d   rt        j                  }nd}dx}	}
	 t        j                  ||t        j                  d||t        j                   t        j"                        }	t        j$                  ||dt        j"                  t        j&                  |t        j"                        }
t        j(                  |	d      }|j+                  d       |	|
fS #  |	t        j,                  |	       |
t        j,                  |
        xY w)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ovs               ,/usr/lib/python3.12/asyncio/windows_utils.pyr   r       s   oo188IIKm,./G --%%(=(== '..&&G555H!}G000!}#88NB$$Xw00vvw;;W\\K VQg.C.Cw||- %%bT:
t$2v>#>#s   *B6F! !1Gc                   |    e Zd ZdZd Zd Zed        Zd Ze	j                  ddZej                  fdZd	 Zd
 Zy)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                     || _         y N_handleselfhandles     r/   __init__zPipeHandle.__init__V   s	        c                 x    | j                   d| j                   }nd}d| j                  j                   d| dS )Nzhandle=closed< >)r4   	__class____name__r5   s     r/   __repr__zPipeHandle.__repr__Y   sB    <<#t||./FF4>>**+1VHA66r9   c                     | j                   S r2   r3   r6   s    r/   r7   zPipeHandle.handle`   s    ||r9   c                 H    | j                   t        d      | j                   S )NzI/O operation on closed pipe)r4   
ValueErrorrC   s    r/   filenozPipeHandle.filenod   s"    <<;<<||r9   )r%   c                P    | j                    || j                          d | _         y y r2   r3   )r6   r%   s     r/   closezPipeHandle.closei   s$    <<#%DL $r9   c                 b    | j                   # |d| t        |        | j                          y y )Nz	unclosed )source)r4   ResourceWarningrH   )r6   _warns     r/   __del__zPipeHandle.__del__n   s-    <<#IdX&EJJL $r9   c                     | S r2    rC   s    r/   	__enter__zPipeHandle.__enter__s   s    r9   c                 $    | j                          y r2   )rH   )r6   tvtbs       r/   __exit__zPipeHandle.__exit__v   s    

r9   N)r@   
__module____qualname____doc__r8   rA   propertyr7   rF   r   r%   rH   warningswarnrM   rP   rU   rO   r9   r/   r   r   Q   sR    7  
 $+#6#6  
 %MM 
r9   r   c                   $     e Zd ZdZd fd	Z xZS )r   zReplacement for subprocess.Popen using overlapped pipe handles.

    The stdin, stdout, stderr are None or instances of PipeHandle.
    c                 ,   |j                  d      rJ |j                  dd      dk(  sJ d x}x}}d x}	x}
}|t        k(  r5t        dd      \  }}	t        j                  |t
        j                        }n|}|t        k(  r&t        d      \  }
}t        j                  |d      }n|}|t        k(  r&t        d      \  }}t        j                  |d      }n|t        k(  r|}n|}	 t        | $  |f|||d	| |	t        |	      | _        |
t        |
      | _        |t        |      | _        	 |t        k(  rt        j                   |       |t        k(  rt        j                   |       |t        k(  rt        j                   |       y y #  |	|
|fD ]  }|t        j                  |         xY w# |t        k(  rt        j                   |       |t        k(  rt        j                   |       |t        k(  rt        j                   |       w w xY w)
Nuniversal_newlinesr
   r   )FTT)r	   r   )TFr   )stdinstdoutstderr)getr   r   msvcrtopen_osfhandler   O_RDONLYSTDOUTsuperr8   r   r_   r`   ra   r   r%   rH   )r6   argsr_   r`   ra   kwds	stdin_rfd
stdout_wfd
stderr_wfdstdin_wh	stdout_rh	stderr_rhstdin_rh	stdout_wh	stderr_whhr?   s                   r/   r8   zPopen.__init__   s   880111xx	1%***.22	2J+///9yD=!%t!LHh--hDIIT>#'=#A Iy..y!<JJT>#'=#A Iy..y!<Jv#JJ	%GT 8:$.8268 #'1
$(3$(3}#~$~$ #		95 +=''*+  }#~$~$ s%   'F ;7F6 F3F33F6 6AH)NNN)r@   rV   rW   rX   r8   __classcell__)r?   s   @r/   r   r   }   s    +% +%r9   r   )rX   sysplatformImportErrorr   	itertoolsrc   r   
subprocessr   rZ   __all__BUFSIZEr   rf   countr   r   r   r   rO   r9   r/   <module>r}      s    / 
<<7
l
##    	    0 				! \7 +b& &X0%J 0%r9   