U
vù¾f9 ã @ sJ d Z ddlZddlZddlZddlmZ G dd„ deƒZG dd„ dƒZdS )zÙ
Attempt to generalize the "feeder" part of a `.Channel`: an object which can be
read from and closed, but is reading from a buffer fed by another thread. The
read operations are blocking and can have a timeout set.
é N)Úbc @ s e Zd ZdZdS )ÚPipeTimeoutzP
Indicates that a timeout was reached on a read from a `.BufferedPipe`.
N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r r úG/opt/alt/python38/lib/python3.8/site-packages/paramiko/buffered_pipe.pyr s r c @ sd e Zd ZdZdd„ Zdd„ Zddd„Zd d
„ Zdd„ Zd
d„ Z ddd„Z
dd„ Zdd„ Zdd„ Z
dS )ÚBufferedPipezª
A buffer that obeys normal read (with timeout) & close semantics for a
file or socket, but is fed data from another thread. This is used by
`.Channel`.
c C s4 t ¡ | _t | j¡| _d | _t d¡| _d| _d S )NÚBF) Ú threadingÚLockÚ_lockÚ ConditionÚ_cvÚ_eventÚarrayÚ_bufferÚ_closed©Úselfr r r Ú__init__. s
zBufferedPipe.__init__c C s | j |¡ d S ©N)r Ú frombytes©r Údatar r r Ú_buffer_frombytes5 s zBufferedPipe._buffer_frombytesNc C s | j d |… ¡ S r )r Útobytes)r Úlimitr r r Ú_buffer_tobytes8 s zBufferedPipe._buffer_tobytesc C sL | j ¡ z0|| _| js&t| jƒdkr0| ¡ n| ¡ W 5 | j ¡ X dS )a
Set an event on this buffer. When data is ready to be read (or the
buffer has been closed), the event will be set. When no data is
ready, the event will be cleared.
:param threading.Event event: the event to set/clear
r N) r ÚacquireÚreleaser r Úlenr ÚsetÚclear)r Úeventr r r Ú set_event; s
zBufferedPipe.set_eventc C sL | j ¡ z0| jdk r | j ¡ | t|ƒ¡ | j ¡ W 5 | j ¡ X dS )zÑ
Feed new data into this pipe. This method is assumed to be called
from a separate thread, so synchronization is done.
:param data: the data to add, as a ``str`` or ``bytes``
N) r r r! r r# r r r Ú
notify_allr r r r ÚfeedR s
zBufferedPipe.feedc C s: | j ¡ zt| jƒdkr"W ¢dS W ¢dS | j ¡ X dS )ad
Returns true if data is buffered and ready to be read from this
feeder. A ``False`` result does not mean that the feeder has closed;
it means you may need to wait before more data arrives.
:return:
``True`` if a `read` call would immediately return at least one
byte; ``False`` otherwise.
r FTN©r r r! r" r r r r r Ú
read_readyb s
zBufferedPipe.read_readyc C sô t ƒ }| j ¡ zÒt| jƒdkrŒ| jr.|W ¢¸S |dkr