U
    Â“«j¥  ã                   @   sª   d Z ddlZddlZddlmZ ddlZddlmZmZ ddl	m
Z
mZmZmZmZ ddlmZ ddlmZ eƒ Zee
ƒG dd	„ d	ƒƒZeeeeƒG d
d„ dejƒƒZdS )zM
Windows-specific implementation of the L{twisted.internet.stdio} interface.
é    N)Úimplementer)Ú_pollingfileÚmain)ÚIAddressÚ	IConsumerÚIHalfCloseableProtocolÚIPushProducerÚ
ITransport)ÚLogger)ÚFailurec                   @   s   e Zd ZdS )ÚWin32PipeAddressN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú@/tmp/pip-unpacked-wheel-59kc99xd/twisted/internet/_win32stdio.pyr      s   r   c                   @   s’   e Zd ZdZdZd"dd„Zdd„ Zdd„ Zd	d
„ ZdZ	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ ZdS )#Ú
StandardIOFNc                 C   s¬   |dkrddl m} tdddƒD ]}t |tj¡ q tj 	| |¡ || _
t tj¡}t tj¡}t || j| j¡| _t || j¡| _|  | j¡ |  | j¡ | j
 | ¡ dS )zƒ
        Start talking to standard IO with the given protocol.

        Also, put it stdin/stdout/stderr into binary mode.
        Nr   )Úreactoré   é   )Útwisted.internetr   ÚrangeÚmsvcrtZsetmodeÚosÚO_BINARYr   Ú_PollingTimerÚ__init__ÚprotoÚwin32apiZGetStdHandleZSTD_INPUT_HANDLEZSTD_OUTPUT_HANDLEZ_PollableReadPipeÚdataReceivedÚreadConnectionLostÚstdinZ_PollableWritePipeÚwriteConnectionLostÚstdoutZ_addPollableResourceZmakeConnection)Úselfr   r   ZstdfdZhstdinZhstdoutr   r   r   r   '   s"      ÿzStandardIO.__init__c                 C   s   | j  |¡ d S ©N)r   r   ©r$   Údatar   r   r   r   D   s    zStandardIO.dataReceivedc              	   C   sL   t  d¡�}t | j¡r"| j ¡  W 5 Q R X |  ¡  |jsH| jsH|  	¡  d S )Nzread connection lost)
Ú_logÚfailuresHandledr   Ú
providedByr   r    ÚcheckConnLostÚ	succeededÚdisconnectingÚloseConnection©r$   Úopr   r   r   r    G   s    zStandardIO.readConnectionLostc              	   C   sL   t  d¡�}t | j¡r"| j ¡  W 5 Q R X |  ¡  |jsH| jsH|  	¡  d S )Nzwrite connection lost)
r(   r)   r   r*   r   r"   r+   r,   r-   r.   r/   r   r   r   r"   O   s    zStandardIO.writeConnectionLostr   c                 C   s:   |  j d7  _ | j dkr6d| _d| _| j ttjƒ¡ d S )Nr   r   T)Ú	connsLostr-   Údisconnectedr   ZconnectionLostr   r   ZCONNECTION_DONE©r$   r   r   r   r+   Y   s
    
zStandardIO.checkConnLostc                 C   s   | j  |¡ d S r%   )r#   Úwriter&   r   r   r   r4   b   s    zStandardIO.writec                 C   s   | j  d |¡¡ d S )Nó    )r#   r4   Újoin)r$   Úseqr   r   r   ÚwriteSequencee   s    zStandardIO.writeSequencec                 C   s   d| _ | j ¡  | j ¡  d S )NT)r-   r!   Úcloser#   r3   r   r   r   r.   h   s    
zStandardIO.loseConnectionc                 C   s   t ƒ S r%   ©r   r3   r   r   r   ÚgetPeerm   s    zStandardIO.getPeerc                 C   s   t ƒ S r%   r:   r3   r   r   r   ÚgetHostp   s    zStandardIO.getHostc                 C   s   | j  ||¡S r%   )r#   ÚregisterProducer)r$   ZproducerZ	streamingr   r   r   r=   u   s    zStandardIO.registerProducerc                 C   s
   | j  ¡ S r%   )r#   ÚunregisterProducerr3   r   r   r   r>   x   s    zStandardIO.unregisterProducerc                 C   s   | j  ¡  d S r%   )r!   ÚstopProducingr3   r   r   r   r?      s    zStandardIO.stopProducingc                 C   s   | j  ¡  d S r%   )r!   ÚpauseProducingr3   r   r   r   r@   „   s    zStandardIO.pauseProducingc                 C   s   | j  ¡  d S r%   )r!   ÚresumeProducingr3   r   r   r   rA   ‡   s    zStandardIO.resumeProducing)N)r   r   r   r-   r2   r   r   r    r"   r1   r+   r4   r8   r.   r;   r<   r=   r>   r?   r@   rA   r   r   r   r   r   "   s$   
	r   )Ú__doc__r   r   Zzope.interfacer   r   r   r   r   Ztwisted.internet.interfacesr   r   r   r   r	   Ztwisted.loggerr
   Ztwisted.python.failurer   r(   r   r   r   r   r   r   r   Ú<module>   s   
