o
    Òó·i¥  ã                   @   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   úbC:\Users\psant\Downloads\PAF backend\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u 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   ó   | j  |¡ d S ©N)r   r#   ©r(   Údatar   r   r   r#   D   ó   zStandardIO.dataReceivedc                 C   óh   t  d¡�}t | j¡r| j ¡  W d   ƒ n1 sw   Y  |  ¡  |js0| js2|  	¡  d S d S d S )Nzread connection lost)
Ú_logÚfailuresHandledr   Ú
providedByr   r$   ÚcheckConnLostÚ	succeededÚdisconnectingÚloseConnection©r(   Úopr   r   r   r$   G   ó   
€þÿzStandardIO.readConnectionLostc                 C   r.   )Nzwrite connection lost)
r/   r0   r   r1   r   r&   r2   r3   r4   r5   r6   r   r   r   r&   O   r8   zStandardIO.writeConnectionLostr   c                 C   s>   |  j d7  _ | j dkrd| _d| _| j ttjƒ¡ d S d S )Nr   r   T)Ú	connsLostr4   Údisconnectedr   ZconnectionLostr   r   ZCONNECTION_DONE©r(   r   r   r   r2   Y   s   
ýzStandardIO.checkConnLostc                 C   r)   r*   )r'   Úwriter+   r   r   r   r<   b   r-   zStandardIO.writec                 C   s   | j  d |¡¡ d S )Nó    )r'   r<   Újoin)r(   Úseqr   r   r   ÚwriteSequencee   s   zStandardIO.writeSequencec                 C   s   d| _ | j ¡  | j ¡  d S )NT)r4   r%   Úcloser'   r;   r   r   r   r5   h   s   
zStandardIO.loseConnectionc                 C   ó   t ƒ S r*   ©r   r;   r   r   r   ÚgetPeerm   ó   zStandardIO.getPeerc                 C   rB   r*   rC   r;   r   r   r   ÚgetHostp   rE   zStandardIO.getHostc                 C   s   | j  ||¡S r*   )r'   ÚregisterProducer)r(   ZproducerZ	streamingr   r   r   rG   u   ó   zStandardIO.registerProducerc                 C   s
   | j  ¡ S r*   )r'   ÚunregisterProducerr;   r   r   r   rI   x   s   
zStandardIO.unregisterProducerc                 C   ó   | j  ¡  d S r*   )r%   ÚstopProducingr;   r   r   r   rK      rH   zStandardIO.stopProducingc                 C   rJ   r*   )r%   ÚpauseProducingr;   r   r   r   rL   „   rH   zStandardIO.pauseProducingc                 C   rJ   r*   )r%   ÚresumeProducingr;   r   r   r   rM   ‡   rH   zStandardIO.resumeProducingr*   )r   r   r   r4   r:   r   r#   r$   r&   r9   r2   r<   r@   r5   rD   rF   rG   rI   rK   rL   rM   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   
