Ñò
ðgcJc           @   sZ   d  Z  d d k Z d d k Z d d k Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   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   PipeTimeoutc           B   s   e  Z d  Z RS(   sP   
    Indicates that a timeout was reached on a read from a L{BufferedPipe}.
    (   t   __name__t
   __module__t   __doc__(    (    (    sU   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\buffered_pipe.pyR       s   t   BufferedPipec           B   sY   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d	 d „ Z d „  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}.
    c         C   sL   t  i ƒ  |  _ t  i |  i ƒ |  _ d  |  _ t i d ƒ |  _ t	 |  _
 d  S(   Nt   B(   t	   threadingt   Lockt   _lockt	   Conditiont   _cvt   Nonet   _eventt   arrayt   _buffert   Falset   _closed(   t   self(    (    sU   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\buffered_pipe.pyt   __init__,   s
    	c         C   s;   | |  _  t |  i ƒ d j o | i ƒ  n | i ƒ  d S(   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
        i    N(   R   t   lenR   t   sett   clear(   R   t   event(    (    sU   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\buffered_pipe.pyt	   set_event3   s    		c         C   sd   |  i  i ƒ  zB |  i d j	 o |  i i ƒ  n |  i i | ƒ |  i i ƒ  Wd |  i  i	 ƒ  Xd S(   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(
   R   t   acquireR   R   R   R   t
   fromstringR
   t	   notifyAllt   release(   R   t   data(    (    sU   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\buffered_pipe.pyt   feedB   s    c         C   sE   |  i  i ƒ  z# t |  i ƒ d j o t St SWd |  i  i ƒ  Xd S(   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
        i    N(   R   R   R   R   R   t   TrueR   (   R   (    (    sU   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\buffered_pipe.pyt
   read_readyS   s    
c         C   sl  d } |  i  i ƒ  zDt |  i ƒ d j o± |  i o | S| d j o t ƒ  ‚ n x… t |  i ƒ d j oj |  i o_ t i ƒ  } |  i i | ƒ | d j	 o2 | t i ƒ  | 8} | d j o t ƒ  ‚ qÔ qX qX Wn t |  i ƒ | j oF |  i i
 ƒ  } |  i 2|  i d j	 o |  i o |  i i ƒ  qVn |  i |  i
 ƒ  } |  i | 4Wd |  i  i ƒ  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
        t    i    g        N(   R   R   R   R   R   R    t   timeR
   t   waitR   t   tostringR   R   R   (   R   t   nbytest   timeoutt   outt   then(    (    sU   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\buffered_pipe.pyt   reade   s2    
 !c         C   sl   |  i  i ƒ  zJ |  i i ƒ  } |  i 2|  i d j	 o |  i o |  i i ƒ  n | SWd |  i  i ƒ  Xd S(   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(	   R   R   R   R#   R   R   R   R   R   (   R   R&   (    (    sU   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\buffered_pipe.pyt   empty   s    c         C   s]   |  i  i ƒ  z; t |  _ |  i i ƒ  |  i d j	 o |  i i ƒ  n Wd |  i  i	 ƒ  Xd S(   sš   
        Close this pipe object.  Future calls to L{read} after the buffer
        has been emptied will return immediately with an empty string.
        N(
   R   R   R   R   R
   R   R   R   R   R   (   R   (    (    sU   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\buffered_pipe.pyt   close®   s    	c         C   s3   |  i  i ƒ  z t |  i ƒ SWd |  i  i ƒ  Xd S(   s}   
        Return the number of bytes buffered.
        
        @return: number of bytes bufferes
        @rtype: int
        N(   R   R   R   R   R   (   R   (    (    sU   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\buffered_pipe.pyt   __len__¼   s    N(   R   R   R   R   R   R   R   R   R(   R)   R*   R+   (    (    (    sU   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\buffered_pipe.pyR   %   s   				8		(   R   R   R   R!   t   IOErrorR    t   objectR   (    (    (    sU   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\buffered_pipe.pyt   <module>   s
   