ó õùPc@sZdZddlZddlZddlZdefd„ƒYZdefd„ƒYZdS(sÖ 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. iÿÿÿÿNt PipeTimeoutcBseZdZRS(sP Indicates that a timeout was reached on a read from a L{BufferedPipe}. (t__name__t __module__t__doc__(((s1..\python\site-packages\paramiko\buffered_pipe.pyRst BufferedPipecBsYeZdZd„Zd„Zd„Zd„Zd d„Zd„Z d„Z d„Z RS( sª 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}. cCsLtjƒ|_tj|jƒ|_d|_tjdƒ|_t |_ dS(NtB( t threadingtLockt_lockt Conditiont_cvtNonet_eventtarrayt_buffertFalset_closed(tself((s1..\python\site-packages\paramiko\buffered_pipe.pyt__init__,s  cCs9||_t|jƒdkr+|jƒn |jƒdS(s 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 iN(R tlenRtsettclear(Rtevent((s1..\python\site-packages\paramiko\buffered_pipe.pyt set_event3s  cCsb|jjƒz@|jdk r/|jjƒn|jj|ƒ|jjƒWd|jj ƒXdS(sÖ 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 N( RtacquireR R RRt fromstringR t notifyAlltrelease(Rtdata((s1..\python\site-packages\paramiko\buffered_pipe.pytfeedBs cCsC|jjƒz!t|jƒdkr)tStSWd|jjƒXdS(ss 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 iN(RRRRRtTrueR(R((s1..\python\site-packages\paramiko\buffered_pipe.pyt read_readySs cCsZd}|jjƒz2t|jƒdkrÐ|jr8|S|dkrPtƒ‚nx}t|jƒdkrÌ|j rÌtjƒ}|jj|ƒ|dk rS|tjƒ|8}|dkrÉtƒ‚qÉqSqSWnt|jƒ|kr'|jj ƒ}|j2|j dk rD|j rD|j j ƒqDn|j| j ƒ}|j|4Wd|jj ƒX|S(sŠ 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 tigN(RRRRRRttimeR twaitR ttostringR RR(Rtnbytesttimeouttouttthen((s1..\python\site-packages\paramiko\buffered_pipe.pytreades0    "   cCsi|jjƒzG|jjƒ}|j2|jdk rO|j rO|jjƒn|SWd|jjƒXdS(s± 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 N( RRRR#R R RRR(RR&((s1..\python\site-packages\paramiko\buffered_pipe.pytemptys cCs[|jjƒz9t|_|jjƒ|jdk rE|jjƒnWd|jj ƒXdS(sš Close this pipe object. Future calls to L{read} after the buffer has been emptied will return immediately with an empty string. N( RRRRR RR R RR(R((s1..\python\site-packages\paramiko\buffered_pipe.pytclose®s   cCs3|jjƒzt|jƒSWd|jjƒXdS(s} Return the number of bytes buffered. @return: number of bytes bufferes @rtype: int N(RRRRR(R((s1..\python\site-packages\paramiko\buffered_pipe.pyt__len__¼s N( RRRRRRRR R(R)R*R+(((s1..\python\site-packages\paramiko\buffered_pipe.pyR%s     8  (RR RR!tIOErrorRtobjectR(((s1..\python\site-packages\paramiko\buffered_pipe.pyts