o
    Òó·iÐ  ã                   @  sš   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZ ddlmZ eƒ ZeejƒG dd	„ d	ƒƒZeejejejejƒG d
d„ dƒƒZdS )zÚStandard input/out/err support.

Future Plans::

    support for stderr, perhaps
    Rewrite to use the reactor instead of an ad-hoc mechanism for connecting
        protocols to transport.

Maintainer: James Y Knight
é    )Úannotations)Úimplementer)Ú
interfacesÚprocess)Ú	IProtocolÚIReactorFDSet)ÚLogger)ÚFailurec                   @  s   e Zd ZdS )ÚPipeAddressN)Ú__name__Ú
__module__Ú__qualname__© r   r   úbC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/internet/_posixstdio.pyr
      s    r
   c                   @  sÖ   e Zd ZdZdZdZdZ			d>d?dd„Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zd@d d!„ZdAd$d%„Zd&d'„ ZdBd(d)„ZdBd*d+„Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ ZdS )CÚ
StandardIONFr   é   Úprotor   ÚstdinÚintÚstdoutÚreactorúIReactorFDSet | Nonec                 C  sX   |d u r
ddl m} || _t || d|¡| _t || d|¡| _| j ¡  | j 	| ¡ d S )Nr   )r   ÚwriteÚread)
Útwisted.internetr   Úprotocolr   ZProcessWriterÚ_writerZProcessReaderÚ_readerÚstartReadingZmakeConnection)Úselfr   r   r   r   r   r   r   Ú__init__*   s   
zStandardIO.__init__c                 C  ó   | j d ur| j  ¡  d S d S ©N)r   ÚloseConnection©r   r   r   r   ÚloseWriteConnection=   ó   
ÿzStandardIO.loseWriteConnectionc                 C  ó   | j d ur| j  |¡ d S d S r"   )r   r   ©r   Údatar   r   r   r   A   ó   
ÿzStandardIO.writec                 C  r'   r"   )r   ÚwriteSequencer(   r   r   r   r+   E   r*   zStandardIO.writeSequencec                 C  s6   d| _ | jd ur| j ¡  | jd ur| j ¡  d S d S )NT)Údisconnectingr   r#   r   ÚstopReadingr$   r   r   r   r#   I   s   


þzStandardIO.loseConnectionc                 C  ó   t ƒ S r"   ©r
   r$   r   r   r   ÚgetPeerR   ó   zStandardIO.getPeerc                 C  r.   r"   r/   r$   r   r   r   ÚgetHostU   r1   zStandardIO.getHostÚfdÚstrr)   ÚbytesÚreturnÚNonec                 C  s   | j  |¡ d S r"   )r   ZdataReceived)r   r3   r)   r   r   r   ÚchildDataReceivedY   s   zStandardIO.childDataReceivedÚreasonr	   c                 C  s.   | j rd S |dkr|  |¡ d S |  |¡ d S )Nr   )ÚdisconnectedÚ_readConnectionLostÚ_writeConnectionLost)r   r3   r9   r   r   r   ÚchildConnectionLost\   s
   zStandardIO.childConnectionLostc                 C  s”   d| _ | j}| j}| j}d  | _| _d | _|d ur!|j s!| |¡ |d ur-|j s-| |¡ t d¡� | |¡ W d   ƒ d S 1 sCw   Y  d S )NTz#while calling stdio connectionLost:)r:   r   r   r   ÚconnectionLostÚ_logÚfailuresHandled)r   r9   r   r   r   r   r   r   r>   d   s   

"ÿzStandardIO.connectionLostc                 C  s|   d | _ | jr|  |¡ d S t | jd ¡}|r:t d¡�}| ¡  W d   ƒ n1 s*w   Y  |j	r<|  |j
¡ d S d S d S )Nz(while calling stdio writeConnectionLost:)r   r,   r>   r   ÚIHalfCloseableProtocolr   r?   r@   ÚwriteConnectionLostÚfailedÚfailure)r   r9   ÚpZwclr   r   r   r<   w   s    
ÿ
ýúzStandardIO._writeConnectionLostc                 C  sr   d | _ t | jd ¡}|r2t d¡�}| ¡  W d   ƒ n1 s w   Y  |jr0|  |j	¡ d S d S |  |¡ d S )Nz'while calling stdio readConnectionLost:)
r   r   rA   r   r?   r@   ÚreadConnectionLostrC   r>   rD   )r   r9   rE   Zrclr   r   r   r;   †   s   
ÿÿzStandardIO._readConnectionLostc                 C  s(   | j d u r| ¡  d S | j  ||¡ d S r"   )r   ÚstopProducingÚregisterProducer)r   ZproducerZ	streamingr   r   r   rH   ’   s   
zStandardIO.registerProducerc                 C  r!   r"   )r   ÚunregisterProducerr$   r   r   r   rI   ˜   r&   zStandardIO.unregisterProducerc                 C  s   |   ¡  d S r"   )r#   r$   r   r   r   rG   �   s   zStandardIO.stopProducingc                 C  r!   r"   )r   ÚpauseProducingr$   r   r   r   rJ       r&   zStandardIO.pauseProducingc                 C  r!   r"   )r   ÚresumeProducingr$   r   r   r   rK   ¤   r&   zStandardIO.resumeProducingc                 C  ó   |   ¡  dS )z3Compatibility only, don't use. Call pauseProducing.N)rJ   r$   r   r   r   r-   ¨   ó   zStandardIO.stopReadingc                 C  rL   )z4Compatibility only, don't use. Call resumeProducing.N)rK   r$   r   r   r   r   ¬   rM   zStandardIO.startReadingc                 C  ó   t ƒ ‚r"   ©ÚNotImplementedError©r   r9   r   r   r   rF   °   ó   zStandardIO.readConnectionLostc                 C  rN   r"   rO   rQ   r   r   r   rB   ´   rR   zStandardIO.writeConnectionLost)r   r   N)r   r   r   r   r   r   r   r   )r3   r4   r)   r5   r6   r7   )r3   r4   r9   r	   r6   r7   )r9   r	   r6   r7   )r   r   r   r   r   r:   r,   r    r%   r   r+   r#   r0   r2   r8   r=   r>   r<   r;   rH   rI   rG   rJ   rK   r-   r   rF   rB   r   r   r   r   r      s:    û	



r   N)Ú__doc__Ú
__future__r   Zzope.interfacer   r   r   r   Ztwisted.internet.interfacesr   r   Ztwisted.loggerr   Ztwisted.python.failurer	   r?   ZIAddressr
   Z
ITransportZ	IProducerZ	IConsumerZIHalfCloseableDescriptorr   r   r   r   r   Ú<module>   s"   
ü