3 \ã ã @ sà d Z ddlZejdkredƒ‚ddlZddlZddlZddlZddlZddl Z ddl Z ddlZddddd gZd Z e jZe jZejƒ Zeedƒr–ejZnejejdfdd„Zdde dœdd„ZG dd „ d ƒZG dd„ de jƒZdS )z* Various Windows specific bits and pieces é NZwin32z win32 onlyÚ socketpairÚpipeÚPopenÚPIPEÚ PipeHandlei c C s | t jkrd}n| t jkr d}ntdƒ‚|t jkr:tdƒ‚|dkrJtdƒ‚t j | ||ƒ}z¦|j|dfƒ |jdƒ |jƒ dd … \}}t j | ||ƒ}yP|jd ƒ y|j ||fƒ W n t tfk rÊ Y nX |jdƒ |jƒ \}} W n |j ƒ ‚ Y nX W d|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 supportedr zOnly protocol zero is supportedé Né FT)ÚsocketÚAF_INETZAF_INET6Ú ValueErrorÚSOCK_STREAMZbindZlistenZgetsocknameZsetblockingZconnectÚBlockingIOErrorÚInterruptedErrorZacceptÚclose) ZfamilyÚtypeÚprotoÚhostZlsockZaddrZportZcsockZssockÚ_© r ú-/usr/lib64/python3.6/asyncio/windows_utils.pyr % s8 FT)ÚduplexÚ overlappedÚbufsizec C s" t jdtjƒ ttƒf d�}| r>tj}tjtj B }|| }}ntj }tj }d| }}|tjO }|d rp|tjO }|d r€tj}nd}d } } yZtj ||tjd||tjtjƒ} tj||dtjtj|tjƒ} tj| dd�}|jdƒ | | fS | dk �rtj| ƒ | dk �rtj| ƒ ‚ Y nX dS )zELike os.pipe() but with overlapped support and using handles not fds.z\\.\pipe\python-pipe-%d-%d-)Úprefixr r NT)r )ÚtempfileZmktempÚosÚgetpidÚnextÚ _mmap_counterÚ_winapiZPIPE_ACCESS_DUPLEXZGENERIC_READZ GENERIC_WRITEZPIPE_ACCESS_INBOUNDZFILE_FLAG_FIRST_PIPE_INSTANCEZFILE_FLAG_OVERLAPPEDZCreateNamedPipeZ PIPE_WAITZNMPWAIT_WAIT_FOREVERZNULLZ CreateFileZ OPEN_EXISTINGZConnectNamedPipeZGetOverlappedResultÚCloseHandle)r r r ZaddressZopenmodeÚaccessZobsizeZibsizeZflags_and_attribsZh1Zh2Zovr r r r S s@ c @ s\ e Zd ZdZdd„ Zdd„ Zedd„ ƒZdd „ Ze j d œdd„Zd d„ Zdd„ Z dd„ ZdS )r z�Wrapper 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__ˆ s zPipeHandle.__init__c C s* | j d k rd| j }nd}d| jj|f S )Nz handle=%rÚclosedz<%s %s>)r" Ú __class__Ú__name__)r# r$ r r r Ú__repr__‹ s zPipeHandle.__repr__c C s | j S )N)r" )r# r r r r$ ’ s zPipeHandle.handlec C s | j d krtdƒ‚| j S )NzI/O operatioon on closed pipe)r" r )r# r r r Úfileno– s zPipeHandle.fileno)r c C s | j d k r|| j ƒ d | _ d S )N)r" )r# r r r r r › s zPipeHandle.closec C s* | j d k r&tjd| t| d� | jƒ d S )Nzunclosed %r)Úsource)r" ÚwarningsÚwarnÚResourceWarningr )r# r r r Ú__del__ s zPipeHandle.__del__c C s | S )Nr )r# r r r Ú __enter__¦ s zPipeHandle.__enter__c C s | j ƒ d S )N)r )r# ÚtÚvÚtbr r r Ú__exit__© s zPipeHandle.__exit__N)r( Ú __module__Ú__qualname__Ú__doc__r% r) Úpropertyr$ r* r r r r/ r0 r4 r r r r r ƒ s c s" e Zd ZdZd‡ fdd„ Z‡ ZS )r zˆReplacement for subprocess.Popen using overlapped pipe handles. The stdin, stdout, stderr are None or instances of PipeHandle. Nc s| d } }}d } } }|t kr@tddd�\}} tj|tjƒ}n|}|t krhtdd�\} } tj| dƒ}n|}|t kr�td d�\}}tj|dƒ}n|tkrž|}n|}z–y tƒ j|f|||dœ|—Ž W n4 x$| | |fD ]}|d k rØt j |ƒ qØW ‚ Y n>X | d k �rt| ƒ| _| d k �r"t| ƒ| _ |d k �r6t|ƒ| _W d |t k�rNtj|ƒ |t k�rbtj|ƒ |t k�rvtj|ƒ X d S ) NFT)r r )r r )ÚstdinÚstdoutÚstderr)FT)TF)TF)r r ÚmsvcrtZopen_osfhandler ÚO_RDONLYÚSTDOUTÚsuperr% r r r r9 r: r; r )r# Úargsr9 r: r; ÚkwdsZ stdin_rfdZ stdout_wfdZ stderr_wfdZstdin_whZ stdout_rhZ stderr_rhZstdin_rhZ stdout_whZ stderr_whÚh)r' r r r% µ sH zPopen.__init__)NNN)r( r5 r6 r7 r% Ú __classcell__r r )r' r r ° s )TT)r7 ÚsysÚplatformÚImportErrorr Ú itertoolsr<