3 \ãã@sàdZddlZejdkredƒ‚ddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddddd gZ d Z e jZe jZejƒZeedƒr–ejZnejejdfd d„Zd de dœdd„ZGdd „d ƒZGdd„de jƒZdS)z* Various Windows specific bits and pieces éNZwin32z win32 onlyÚ socketpairÚpipeÚPopenÚPIPEÚ PipeHandlei c Cs|tjkrd}n|tjkr d}ntdƒ‚|tjkr:tdƒ‚|dkrJtdƒ‚tj|||ƒ}z¦|j|dfƒ|jdƒ|jƒdd …\}}tj|||ƒ}yP|jd ƒy|j ||fƒWnt t fk rÊYnX|jd ƒ|j ƒ\}} Wn|j ƒ‚YnXWd|j ƒX||fS) z”A 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 supportedéNéFT)ÚsocketÚAF_INETZAF_INET6Ú ValueErrorÚ SOCK_STREAMZbindZlistenZ getsocknameZ setblockingZconnectÚBlockingIOErrorÚInterruptedErrorZacceptÚclose) ZfamilyÚtypeÚprotoÚhostZlsockZaddrZportZcsockZssockÚ_©rú-/usr/lib64/python3.6/asyncio/windows_utils.pyr%s8        FT)ÚduplexÚ overlappedÚbufsizec Cs"tjdtjƒttƒfd�}|r>tj}tjtj B}||}}ntj }tj }d|}}|tj O}|drp|tj O}|dr€tj }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)ÚtempfileZmktempÚosÚgetpidÚnextÚ _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) rrrZaddressZopenmodeÚaccessZobsizeZibsizeZflags_and_attribsZh1Zh2ZovrrrrSs@           c@s\eZdZdZdd„Zdd„Zedd„ƒZdd „Ze j d œd d „Z d d„Z dd„Z dd„ZdS)rz�Wrapper 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)ÚselfÚhandlerrrÚ__init__ˆszPipeHandle.__init__cCs*|jdk rd|j}nd}d|jj|fS)Nz handle=%rÚclosedz<%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#rrrÚfileno–s zPipeHandle.fileno)r cCs|jdk r||jƒd|_dS)N)r")r#r rrrr›s  zPipeHandle.closecCs*|jdk r&tjd|t|d�|jƒdS)Nz unclosed %r)Úsource)r"ÚwarningsÚwarnÚResourceWarningr)r#rrrÚ__del__ s  zPipeHandle.__del__cCs|S)Nr)r#rrrÚ __enter__¦szPipeHandle.__enter__cCs |jƒdS)N)r)r#ÚtÚvÚtbrrrÚ__exit__©szPipeHandle.__exit__N)r(Ú __module__Ú __qualname__Ú__doc__r%r)Úpropertyr$r*rr rr/r0r4rrrrrƒs cs"eZdZdZd‡fdd„ Z‡ZS)rzˆReplacement for subprocess.Popen using overlapped pipe handles. The stdin, stdout, stderr are None or instances of PipeHandle. Nc s¤|jdƒ st‚|jddƒdks$t‚d}}}d} } } |tkrdtd dd�\} } tj| tjƒ}n|}|tkrŒtd d�\} } tj| dƒ}n|}|tkr´td d�\} }tj|dƒ}n|tkrÂ|}n|}zšy t ƒj |f|||dœ|—ŽWn8x(| | | fD]}|dk �rüt j |ƒ�qüW‚Yn>X| dk �r6t | ƒ|_| dk �rJt | ƒ|_| dk �r^t | ƒ|_Wd|tk�rvtj|ƒ|tk�rŠtj|ƒ|tk�ržtj|ƒXdS) NZuniversal_newlinesrrFT)rr)r)ÚstdinÚstdoutÚstderr)FT)TF)TF)ÚgetÚAssertionErrorrrÚmsvcrtZopen_osfhandlerÚO_RDONLYÚSTDOUTÚsuperr%rr rr9r:r;r)r#Úargsr9r:r;ÚkwdsZ stdin_rfdZ stdout_wfdZ stderr_wfdZstdin_whZ stdout_rhZ stderr_rhZstdin_rhZ stdout_whZ stderr_whÚh)r'rrr%µsL             zPopen.__init__)NNN)r(r5r6r7r%Ú __classcell__rr)r'rr°s)TT)r7ÚsysÚplatformÚ ImportErrorrÚ itertoolsr>rr Ú subprocessrr,Ú__all__ZBUFSIZErr@ÚcountrÚhasattrrr r rrrrrrrÚs,  .0-