U
    
W[„  ã                   @   sª   d Z ddlmZmZ ddlZddlZddlZddlmZ ddl	m
Z
mZmZmZmZ ddlmZmZ ddlmZ eeƒG dd	„ d	eƒƒ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.
é    )Úabsolute_importÚdivisionN)Úimplementer)ÚIHalfCloseableProtocolÚ
ITransportÚ	IConsumerÚIPushProducerÚIAddress)Ú_pollingfileÚmain)ÚFailurec                   @   s   e Zd ZdS )ÚWin32PipeAddressN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú>/usr/lib/python3/dist-packages/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ÚosZ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   >   s    zStandardIO.dataReceivedc                 C   s"   t  | j¡r| j ¡  |  ¡  d S r%   )r   Ú
providedByr   r    ÚcheckConnLost©r$   r   r   r   r    B   s    
zStandardIO.readConnectionLostc                 C   s"   t  | j¡r| j ¡  |  ¡  d S r%   )r   r(   r   r"   r)   r*   r   r   r   r"   H   s    
zStandardIO.writeConnectionLostr   c                 C   s:   |  j d7  _ | j dkr6d| _d| _| j ttjƒ¡ d S )Nr   r   T)Ú	connsLostÚdisconnectingÚdisconnectedr   ZconnectionLostr   r   ZCONNECTION_DONEr*   r   r   r   r)   P   s
    
zStandardIO.checkConnLostc                 C   s   | j  |¡ d S r%   )r#   Úwriter&   r   r   r   r.   Y   s    zStandardIO.writec                 C   s   | j  d |¡¡ d S )Nó    )r#   r.   Újoin)r$   Úseqr   r   r   ÚwriteSequence]   s    zStandardIO.writeSequencec                 C   s   d| _ | j ¡  | j ¡  d S )NT)r,   r!   Úcloser#   r*   r   r   r   ÚloseConnectiona   s    
zStandardIO.loseConnectionc                 C   s   t ƒ S r%   ©r   r*   r   r   r   ÚgetPeerg   s    zStandardIO.getPeerc                 C   s   t ƒ S r%   r5   r*   r   r   r   ÚgetHostk   s    zStandardIO.getHostc                 C   s   | j  ||¡S r%   )r#   ÚregisterProducer)r$   ZproducerZ	streamingr   r   r   r8   p   s    zStandardIO.registerProducerc                 C   s
   | j  ¡ S r%   )r#   ÚunregisterProducerr*   r   r   r   r9   t   s    zStandardIO.unregisterProducerc                 C   s   | j  ¡  d S r%   )r!   ÚstopProducingr*   r   r   r   r:   {   s    zStandardIO.stopProducingc                 C   s   | j  ¡  d S r%   )r!   ÚpauseProducingr*   r   r   r   r;   €   s    zStandardIO.pauseProducingc                 C   s   | j  ¡  d S r%   )r!   ÚresumeProducingr*   r   r   r   r<   „   s    zStandardIO.resumeProducing)N)r   r   r   r,   r-   r   r   r    r"   r+   r)   r.   r2   r4   r6   r7   r8   r9   r:   r;   r<   r   r   r   r   r      s$   
	r   )Ú__doc__Z
__future__r   r   r   r   r   Zzope.interfacer   Ztwisted.internet.interfacesr   r   r   r   r	   r   r
   r   Ztwisted.python.failurer   Úobjectr   r   r   r   r   r   r   Ú<module>   s   
