File: //usr/local/CyberCP/lib/python3.10/site-packages/paramiko/__pycache__/buffered_pipe.cpython-310.pyc
o
�h9 � @ 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 �I/usr/local/CyberCP/lib/python3.10/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 sd | j �� z&|| _| jst| j�dkr|�� n|�� W | j �� dS W | j �� dS | j �� w )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 �acquirer r �lenr �set�clear�release)r �eventr r r � set_event; s
�zBufferedPipe.set_eventc C sT | j �� z| jdur| j�� | �t|�� | j�� W | j �� dS | j �� w )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"