U
    Jë]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   úec:\users\psant\downloads\hotstarbackend\school\venv\Lib\site-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ÚmsvcrtÚsetmodeÚosÚO_BINARYr   Ú_PollingTimerÚ__init__ÚprotoÚwin32apiÚGetStdHandleÚSTD_INPUT_HANDLEÚ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/   r0   r1   r2   r3   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)Ú	connsLostr1   Ú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   r8   b   s    zStandardIO.writec                 C   s   | j  d |¡¡ d S )Nó    )r'   r8   Újoin)r(   Úseqr   r   r   ÚwriteSequencee   s    zStandardIO.writeSequencec                 C   s   d| _ | j ¡  | j ¡  d S )NT)r1   r%   Úcloser'   r7   r   r   r   r2   h   s    
zStandardIO.loseConnectionc                 C   s   t ƒ S r)   ©r   r7   r   r   r   ÚgetPeerm   s    zStandardIO.getPeerc                 C   s   t ƒ S r)   r>   r7   r   r   r   ÚgetHostp   s    zStandardIO.getHostc                 C   s   | j  ||¡S r)   )r'   ÚregisterProducer)r(   ZproducerZ	streamingr   r   r   rA   u   s    zStandardIO.registerProducerc                 C   s
   | j  ¡ S r)   )r'   ÚunregisterProducerr7   r   r   r   rB   x   s    zStandardIO.unregisterProducerc                 C   s   | j  ¡  d S r)   )r%   ÚstopProducingr7   r   r   r   rC      s    zStandardIO.stopProducingc                 C   s   | j  ¡  d S r)   )r%   ÚpauseProducingr7   r   r   r   rD   „   s    zStandardIO.pauseProducingc                 C   s   | j  ¡  d S r)   )r%   ÚresumeProducingr7   r   r   r   rE   ‡   s    zStandardIO.resumeProducing)N)r   r   r   r1   r6   r   r#   r$   r&   r5   r/   r8   r<   r2   r?   r@   rA   rB   rC   rD   rE   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   
