Buffered pipes

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.

class paramiko.buffered_pipe.BufferedPipe

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 L{Channel}.

__len__()

Return the number of bytes buffered.

@return: number of bytes bufferes @rtype: int

__weakref__

list of weak references to the object (if defined)

close()

Close this pipe object. Future calls to L{read} after the buffer has been emptied will return immediately with an empty string.

empty()

Clear out the buffer and return all data that was in it.

@return: any data that was in the buffer prior to clearing it out @rtype: str

feed(data)

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 @type data: str

read(nbytes, timeout=None)

Read data from the pipe. The return value is a string representing the data received. The maximum amount of data to be received at once is specified by C{nbytes}. If a string of length zero is returned, the pipe has been closed.

The optional C{timeout} argument can be a nonnegative float expressing seconds, or C{None} for no timeout. If a float is given, a C{PipeTimeout} will be raised if the timeout period value has elapsed before any data arrives.

@param nbytes: maximum number of bytes to read @type nbytes: int @param timeout: maximum seconds to wait (or C{None}, the default, to

wait forever)

@type timeout: float @return: data @rtype: str

@raise PipeTimeout: if a timeout was specified and no data was ready
before that timeout
read_ready()

Returns true if data is buffered and ready to be read from this feeder. A C{False} result does not mean that the feeder has closed; it means you may need to wait before more data arrives.

@return: C{True} if a L{read} call would immediately return at least
one byte; C{False} otherwise.

@rtype: bool

set_event(event)

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 event: the event to set/clear @type event: Event

exception paramiko.buffered_pipe.PipeTimeout

Indicates that a timeout was reached on a read from a L{BufferedPipe}.

__weakref__

list of weak references to the object (if defined)