o
    ¯b„  ã                   @   st   d Z ddlmZ ddlmZmZmZ ddlmZm	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
é    )Úimplementer)ÚerrorÚ
interfacesÚprocess)ÚfailureÚlogc                   @   s   e Zd ZdS )ÚPipeAddressN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú>/usr/lib/python3/dist-packages/twisted/internet/_posixstdio.pyr      s    r   c                   @   sÆ   e Zd ZdZdZdZdZd/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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 )0Ú
StandardIONFr   é   c                 C   sX   |d u r
ddl m} || _t || d|¡| _t || d|¡| _| j ¡  | j 	| ¡ d S )Nr   )ÚreactorÚwriteÚread)
Útwisted.internetr   Úprotocolr   ÚProcessWriterÚ_writerÚProcessReaderÚ_readerÚstartReadingÚmakeConnection)ÚselfÚprotoÚstdinÚstdoutr   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   ÚloseWriteConnection3   ó   
ÿzStandardIO.loseWriteConnectionc                 C   ó   | j d ur| j  |¡ d S d S r!   )r   r   ©r   Údatar   r   r   r   7   ó   
ÿzStandardIO.writec                 C   r&   r!   )r   ÚwriteSequencer'   r   r   r   r*   ;   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"   ?   s   


þzStandardIO.loseConnectionc                 C   ó   t ƒ S r!   ©r   r#   r   r   r   ÚgetPeerH   ó   zStandardIO.getPeerc                 C   r.   r!   r/   r#   r   r   r   ÚgetHostK   r1   zStandardIO.getHostc                 C   s   | j  |¡ d S r!   )r   ÚdataReceived)r   Úfdr(   r   r   r   ÚchildDataReceivedO   s   zStandardIO.childDataReceivedc                 C   sJ   | j rd S |jjtjkr|dkr|  |¡ d S |  |¡ d S |  |¡ d S )Nr   )ÚdisconnectedÚvalueÚ	__class__r   ÚConnectionDoneÚ_readConnectionLostÚ_writeConnectionLostÚconnectionLost)r   r4   Úreasonr   r   r   ÚchildConnectionLostR   s   zStandardIO.childConnectionLostc                 C   sˆ   d| _ | j}| j}| j}d  | _| _d | _|d ur!|j s!| |¡ |d ur-|j s-| |¡ z| |¡ W d S  tyC   t ¡  Y d S w r+   )r6   r   r   r   r<   ÚBaseExceptionr   Úerr)r   r=   r   r   r   r   r   r   r<   _   s   

ÿzStandardIO.connectionLostc                 C   sj   d | _ | jr|  |¡ d S t | jd ¡}|r3z| ¡  W d S  ty2   t 	¡  |  t
 ¡ ¡ Y d S w d S r!   )r   r,   r<   r   ÚIHalfCloseableProtocolr   ÚwriteConnectionLostr?   r   r@   r   ÚFailure©r   r=   Úpr   r   r   r;   t   s   
þýzStandardIO._writeConnectionLostc                 C   s`   d | _ t | jd ¡}|r)z| ¡  W d S  ty(   t ¡  |  t	 
¡ ¡ Y d S w |  |¡ d S r!   )r   r   rA   r   ÚreadConnectionLostr?   r   r@   r<   r   rC   rD   r   r   r   r:   ‚   s   þzStandardIO._readConnectionLostc                 C   s(   | j d u r| ¡  d S | j  ||¡ d S r!   )r   ÚstopProducingÚregisterProducer)r   ÚproducerÚ	streamingr   r   r   rH   �   s   
zStandardIO.registerProducerc                 C   r    r!   )r   ÚunregisterProducerr#   r   r   r   rK   •   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   rL   �   r%   zStandardIO.pauseProducingc                 C   r    r!   )r   ÚresumeProducingr#   r   r   r   rM   ¡   r%   zStandardIO.resumeProducingc                 C   ó   |   ¡  dS )z3Compatibility only, don't use. Call pauseProducing.N)rL   r#   r   r   r   r-   ¥   ó   zStandardIO.stopReadingc                 C   rN   )z4Compatibility only, don't use. Call resumeProducing.N)rM   r#   r   r   r   r   ©   rO   zStandardIO.startReadingc                 C   ó   t ƒ ‚r!   ©ÚNotImplementedError©r   r=   r   r   r   rF   ­   ó   zStandardIO.readConnectionLostc                 C   rP   r!   rQ   rS   r   r   r   rB   ±   rT   zStandardIO.writeConnectionLost)r   r   N)r	   r
   r   r   r   r6   r,   r   r$   r   r*   r"   r0   r2   r5   r>   r<   r;   r:   rH   rK   rG   rL   rM   r-   r   rF   rB   r   r   r   r   r      s4    
	r   N)Ú__doc__Úzope.interfacer   r   r   r   r   Útwisted.pythonr   r   ÚIAddressr   Ú
ITransportÚ	IProducerÚ	IConsumerÚIHalfCloseableDescriptorr   r   r   r   r   Ú<module>   s   ü