3 \@sdZddlZejdkredddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddddd gZ d Z e jZe jZejZeedrejZnejejdfd dZd de dddZGdd d ZGddde jZdS)z* Various Windows specific bits and pieces NZwin32z win32 only socketpairpipePopenPIPE PipeHandlei c Cs|tjkrd}n|tjkr d}ntd|tjkr:td|dkrJtdtj|||}z|j|df|jd|jdd \}}tj|||}yP|jd y|j ||fWnt t fk rYnX|jd |j \}} Wn|j YnXWd|j X||fS) zA 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 supportedNFT)socketAF_INETZAF_INET6 ValueError SOCK_STREAMZbindZlistenZ getsocknameZ setblockingZconnectBlockingIOErrorInterruptedErrorZacceptclose) ZfamilytypeprotohostZlsockZaddrZportZcsockZssock_r%/usr/lib64/python3.6/windows_utils.pyr%s8        FT)duplex overlappedbufsizec Cs"tjdtjttfd}|r>tj}tjtj B}||}}ntj }tj }d|}}|tj O}|drp|tj O}|drtj }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)tempfileZmktemposgetpidnext _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) rrrZaddressZopenmodeaccessZobsizeZibsizeZflags_and_attribsZh1Zh2ZovrrrrSs@           c@s\eZdZdZddZddZeddZdd Ze j d d d Z d dZ ddZ ddZdS)rzWrapper 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)selfhandlerrr__init__szPipeHandle.__init__cCs*|jdk rd|j}nd}d|jj|fS)Nz handle=%rclosedz<%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#rrrfilenos zPipeHandle.fileno)r cCs|jdk r||jd|_dS)N)r")r#r rrrrs  zPipeHandle.closecCs*|jdk r&tjd|t|d|jdS)Nz unclosed %r)source)r"warningswarnResourceWarningr)r#rrr__del__s  zPipeHandle.__del__cCs|S)Nr)r#rrr __enter__szPipeHandle.__enter__cCs |jdS)N)r)r#tvtbrrr__exit__szPipeHandle.__exit__N)r( __module__ __qualname____doc__r%r)propertyr$r*rr rr/r0r4rrrrrs cs"eZdZdZdfdd ZZS)rzReplacement for subprocess.Popen using overlapped pipe handles. The stdin, stdout, stderr are None or instances of PipeHandle. Nc s|d}}}d} } } |tkr@tddd\} } tj| tj}n|}|tkrhtdd\} } tj| d}n|}|tkrtd d\} }tj|d}n|tkr|}n|}zy tj|f|||d|Wn4x$| | | fD]}|dk rt j |qWYn>X| dk rt | |_ | dk r"t | |_ | dk r6t | |_Wd|tkrNtj||tkrbtj||tkrvtj|XdS) NFT)rr)rr)stdinstdoutstderr)FT)TF)TF)rrmsvcrtZopen_osfhandlerO_RDONLYSTDOUTsuperr%rr rr9r:r;r)r#argsr9r:r;kwdsZ stdin_rfdZ stdout_wfdZ stderr_wfdZstdin_whZ stdout_rhZ stderr_rhZstdin_rhZ stdout_whZ stderr_whh)r'rrr%sH            zPopen.__init__)NNN)r(r5r6r7r% __classcell__rr)r'rrs)TT)r7sysplatform ImportErrorr itertoolsr<rr subprocessrr,__all__ZBUFSIZErr>countrhasattrrr r rrrrrrrs,  .0-