U
    ª€ljÐ  ã                   @  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   ú@/tmp/pip-unpacked-wheel-aghyhbke/twisted/internet/_posixstdio.pyr
      s   r
   c                   @  sö   e Zd ZdZdZdZdZd:ddd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dœdd„Zddddœdd „Zd!d"„ Zddd#œd$d%„Zddd#œd&d'„Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ ZdS );Ú
StandardIONFr   é   r   ÚintzIReactorFDSet | None)ÚprotoÚstdinÚstdoutÚreactorc                 C  sX   |d k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  s   | j d k	r| j  ¡  d S ©N)r   ÚloseConnection©r   r   r   r   ÚloseWriteConnection=   s    
zStandardIO.loseWriteConnectionc                 C  s   | j d k	r| j  |¡ d S r    )r   r   ©r   Údatar   r   r   r   A   s    
zStandardIO.writec                 C  s   | j d k	r| j  |¡ d S r    )r   ÚwriteSequencer$   r   r   r   r&   E   s    
zStandardIO.writeSequencec                 C  s2   d| _ | jd k	r| j ¡  | jd k	r.| j ¡  d S )NT)Údisconnectingr   r!   r   ÚstopReadingr"   r   r   r   r!   I   s
    


zStandardIO.loseConnectionc                 C  s   t ƒ S r    ©r
   r"   r   r   r   ÚgetPeerR   s    zStandardIO.getPeerc                 C  s   t ƒ S r    r)   r"   r   r   r   ÚgetHostU   s    zStandardIO.getHostÚstrÚbytesÚNone)Úfdr%   Úreturnc                 C  s   | j  |¡ d S r    )r   ZdataReceived)r   r/   r%   r   r   r   ÚchildDataReceivedY   s    zStandardIO.childDataReceivedr	   )r/   Úreasonr0   c                 C  s,   | j r
d S |dkr|  |¡ n
|  |¡ d S )Nr   )ÚdisconnectedÚ_readConnectionLostÚ_writeConnectionLost)r   r/   r2   r   r   r   ÚchildConnectionLost\   s
    zStandardIO.childConnectionLostc              	   C  s~   d| _ | j}| j}| j}d  | _| _d | _|d k	rB|j sB| |¡ |d k	rZ|j sZ| |¡ t d¡� | |¡ W 5 Q R X d S )NTz#while calling stdio connectionLost:)r3   r   r   r   ÚconnectionLostÚ_logÚfailuresHandled)r   r2   r   r   r   r   r   r   r7   d   s    

zStandardIO.connectionLost)r2   r0   c              	   C  s`   d | _ | jr|  |¡ d S t | jd ¡}|r\t d¡�}| ¡  W 5 Q R X |j	r\|  |j
¡ d S )Nz(while calling stdio writeConnectionLost:)r   r'   r7   r   ÚIHalfCloseableProtocolr   r8   r9   ÚwriteConnectionLostÚfailedÚfailure)r   r2   ÚpZwclr   r   r   r5   w   s    
ÿzStandardIO._writeConnectionLostc              	   C  sX   d | _ t | jd ¡}|rJt d¡�}| ¡  W 5 Q R X |jrT|  |j	¡ n
|  |¡ d S )Nz'while calling stdio readConnectionLost:)
r   r   r:   r   r8   r9   ÚreadConnectionLostr<   r7   r=   )r   r2   r>   Zrclr   r   r   r4   †   s    zStandardIO._readConnectionLostc                 C  s&   | j d kr| ¡  n| j  ||¡ d S r    )r   ÚstopProducingÚregisterProducer)r   ZproducerZ	streamingr   r   r   rA   ’   s    

zStandardIO.registerProducerc                 C  s   | j d k	r| j  ¡  d S r    )r   ÚunregisterProducerr"   r   r   r   rB   ˜   s    
zStandardIO.unregisterProducerc                 C  s   |   ¡  d S r    )r!   r"   r   r   r   r@   �   s    zStandardIO.stopProducingc                 C  s   | j d k	r| j  ¡  d S r    )r   ÚpauseProducingr"   r   r   r   rC       s    
zStandardIO.pauseProducingc                 C  s   | j d k	r| j  ¡  d S r    )r   ÚresumeProducingr"   r   r   r   rD   ¤   s    
zStandardIO.resumeProducingc                 C  s   |   ¡  dS )z3Compatibility only, don't use. Call pauseProducing.N)rC   r"   r   r   r   r(   ¨   s    zStandardIO.stopReadingc                 C  s   |   ¡  dS )z4Compatibility only, don't use. Call resumeProducing.N)rD   r"   r   r   r   r   ¬   s    zStandardIO.startReadingc                 C  s
   t ƒ ‚d S r    ©ÚNotImplementedError©r   r2   r   r   r   r?   °   s    zStandardIO.readConnectionLostc                 C  s
   t ƒ ‚d S r    rE   rG   r   r   r   r;   ´   s    zStandardIO.writeConnectionLost)r   r   N)r   r   r   r   r   r3   r'   r   r#   r   r&   r!   r*   r+   r1   r6   r7   r5   r4   rA   rB   r@   rC   rD   r(   r   r?   r;   r   r   r   r   r      s8      û	r   N)Ú__doc__Ú
__future__r   Zzope.interfacer   r   r   r   Ztwisted.internet.interfacesr   r   Ztwisted.loggerr   Ztwisted.python.failurer	   r8   ZIAddressr
   Z
ITransportZ	IProducerZ	IConsumerZIHalfCloseableDescriptorr   r   r   r   r   Ú<module>   s    
ü