ó =OXc@spdZddlZddlZddlZddlmZmZdefd„ƒYZde fd„ƒYZ dS(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ÿÿÿÿN(tPY2tbt PipeTimeoutcBseZdZRS(sP Indicates that a timeout was reached on a read from a `.BufferedPipe`. (t__name__t __module__t__doc__(((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pyRst BufferedPipecBsŒeZdZd„Zer3d„Zd d„Znd„Zd d„Zd„Zd„Z d„Z d d „Z d „Z d „Z d „ZRS(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 `.Channel`. cCsLtjƒ|_tj|jƒ|_d|_tjdƒ|_t |_ dS(NtB( t threadingtLockt_lockt Conditiont_cvtNonet_eventtarrayt_buffertFalset_closed(tself((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pyt__init__-s  cCs|jj|ƒdS(N(Rt fromstring(Rtdata((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pyt_buffer_frombytes5scCs|j| jƒS(N(Rttostring(Rtlimit((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pyt_buffer_tobytes8scCs|jj|ƒdS(N(Rt frombytes(RR((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pyR;scCs|j| jƒS(N(Rttobytes(RR((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pyR>scCsd|jjƒzB||_|js7t|jƒdkrD|jƒn |jƒWd|jjƒXdS(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 threading.Event event: the event to set/clear iN( R tacquireRRtlenRtsettcleartrelease(Rtevent((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pyt set_eventAs   cCse|jjƒzC|jdk r/|jjƒn|jt|ƒƒ|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, as a `str` or `bytes` N( R RRR RRRR t notifyAllR!(RR((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pytfeedXs cCsC|jjƒz!t|jƒdkr)tStSWd|jjƒXdS(sl 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. iN(R RRRRtTrueR!(R((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pyt read_readyhs cCsVtƒ}|jjƒz+t|jƒdkrÓ|jr;|S|dkrStƒ‚nx}t|jƒdkrÏ|j rÏtjƒ}|jj |ƒ|dk rV|tjƒ|8}|dkrÌtƒ‚qÌqVqVWnt|jƒ|kr'|j ƒ}|j2|j dk r@|j r@|j j ƒq@n|j |ƒ}|j|4Wd|jjƒX|S(sq 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 ``nbytes``. If a string of length zero is returned, the pipe has been closed. The optional ``timeout`` argument can be a nonnegative float expressing seconds, or ``None`` for no timeout. If a float is given, a `.PipeTimeout` will be raised if the timeout period value has elapsed before any data arrives. :param int nbytes: maximum number of bytes to read :param float timeout: maximum seconds to wait (or ``None``, the default, to wait forever) :return: the read data, as a `bytes` :raises PipeTimeout: if a timeout was specified and no data was ready before that timeout igN(tbytesR RRRRRttimeR twaitR RRR R!(Rtnbytesttimeouttouttthen((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pytreadzs0     "    cCsf|jjƒzD|jƒ}|j2|jdk rL|j rL|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, as a `str` N( R RRRRR RR R!(RR-((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pytempty°s  cCs[|jjƒz9t|_|jjƒ|jdk rE|jjƒnWd|jj ƒXdS(s™ Close this pipe object. Future calls to `read` after the buffer has been emptied will return immediately with an empty string. N( R RR&RR R$RR RR!(R((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pytcloseÂs   cCs3|jjƒzt|jƒSWd|jjƒXdS(sq Return the number of bytes buffered. :return: number (`int`) of bytes buffered N(R RRRR!(R((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pyt__len__Ðs N(RRRRRRR RR#R%R'R/R0R1R2(((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pyR&s        6  ( RRRR)tparamiko.py3compatRRtIOErrorRtobjectR(((s:/usr/lib/python2.7/site-packages/paramiko/buffered_pipe.pyts