+e@sMdZddlZejdkr0ednddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddddd gZ d Z e jZe jZejZeedrejZnejejdd dZd d ddde ddZGdd d ZGddde jZdS)z* Various Windows specific bits and pieces Nwin32z win32 only socketpairpipePopenPIPE PipeHandlei c Csq|tjkrd}n$|tjkr0d}n td|tjkrZtdn|dkrutdntj|||}z|j|df|jd|jdd \}}tj|||}yb|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:/opt/alt/python34/lib64/python3.4/asyncio/windows_utils.pyr%s8          duplexF overlappedTbufsizec Cstjddtjttf}|rWtj}tjtj B}||}}ntj }tj }d|}}|tj O}|dr|tj O}n|drtj }nd}d} } ytj ||tjd||tjtj} tj||dtjtj|tj} tj| dd} | jd| | fSWnC| dk rltj| n| dk rtj| nYnXdS)zELike os.pipe() but with overlapped support and using handles not fds.prefixz\\.\pipe\python-pipe-%d-%d-rrNrT)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@seZdZdZddZddZeddZdd Zd e j 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__cCs9|jdk rd|j}nd}d|jj|fS)Nz handle=%rclosedz<%s %s>)r# __class____name__)r$r%rrr__repr__szPipeHandle.__repr__cCs|jS)N)r#)r$rrrr%szPipeHandle.handlecCs%|jdkrtdn|jS)NzI/O operatioon on closed pipe)r#r )r$rrrfilenoszPipeHandle.filenor!cCs,|jdk r(||jd|_ndS)N)r#)r$r!rrrrs zPipeHandle.closecCs4|jdk r0tjd|t|jndS)Nz unclosed %r)r#warningswarnResourceWarningr)r$rrr__del__szPipeHandle.__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+r r!rr/r0r4rrrrrs      cs1eZdZdZdddfddZS)rzReplacement for subprocess.Popen using overlapped pipe handles. The stdin, stdout, stderr are None or instances of PipeHandle. Nc sd}}}d} } } |tkr[tdd dd\} } tj| tj}n|}|tkrtdd \} } tj| d}n|}|tkrtdd \} }tj|d}n|tkr|}n|}zy)tj|d|d|d||WnAx3| | | fD]"}|dk r0t j |q0q0WYn[X| dk r|t | |_ n| dk rt | |_ n| dk rt | |_nWd|tkrtj|n|tkrtj|n|tkrtj|nXdS) NrFTrrstdinstdoutstderr)FT)TF)TF)rrmsvcrtZopen_osfhandlerO_RDONLYSTDOUTsuperr&r r!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__)r)r5r6r7r&rr)r(rrs )TT)r7sysplatform ImportErrorr itertoolsr<rr subprocessrr,__all__ZBUFSIZErr>countrhasattrrr r rrrrrrrs,             .0,