Ñò
ðgcJc           @   s0   d  Z  d d k l Z d e f d „  ƒ  YZ d S(   s   
BufferedFile.
iÿÿÿÿ(   t   StringIOt   BufferedFilec           B   s  e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 d Z
 d Z d Z d	 Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d  d „ Z d  d „ Z d  d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d „ Z  d „  Z! d „  Z" RS(!   sc   
    Reusable base class to implement python-style file buffering around a
    simpler stream.
    i    i    i   i   i   i   i    i@   i€   c         C   sb   d  |  _ d |  _ |  i |  _ t ƒ  |  _ d |  _ t |  _	 t |  _
 d |  _ |  _ d |  _ d  S(   Ni    t    (   t   Nonet   newlinest   _flagst   _DEFAULT_BUFSIZEt   _bufsizeR    t   _wbuffert   _rbuffert   Falset   _at_trailing_crt   _closedt   _post   _realpost   _size(   t   self(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt   __init__.   s    					c         C   s   |  i  ƒ  d  S(   N(   t   close(   R   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt   __del__=   s    c         C   s   |  i  o t d ƒ ‚ n |  S(   s6  
        Returns an iterator that can be used to iterate over the lines in this
        file.  This iterator happens to return the file itself, since a file is
        its own iterator.

        @raise ValueError: if the file is closed.
        
        @return: an interator.
        @rtype: iterator
        s   I/O operation on closed file(   R   t
   ValueError(   R   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt   __iter__@   s    
c         C   s   |  i  ƒ  t |  _ d S(   sN   
        Close the file.  Future read and write operations will fail.
        N(   t   flusht   TrueR   (   R   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyR   O   s    
c         C   s&   |  i  |  i i ƒ  ƒ t ƒ  |  _ d S(   s{   
        Write out any data in the write buffer.  This may do nothing if write
        buffering is not turned on.
        N(   t
   _write_allR   t   getvalueR    (   R   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyR   V   s    c         C   s!   |  i  ƒ  } | p
 t ‚ n | S(   sH  
        Returns the next line from the input, or raises L{StopIteration} when
        EOF is hit.  Unlike python file objects, it's okay to mix calls to
        C{next} and L{readline}.

        @raise StopIteration: when the end of the file is reached.

        @return: a line read from the file.
        @rtype: str
        (   t   readlinet   StopIteration(   R   t   line(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt   next_   s    
c      	   C   sn  |  i  o t d ƒ ‚ n |  i |  i @p t d ƒ ‚ n | d j p | d j  oÆ |  i } d |  _ |  i t | ƒ 7_ x— t o y |  i	 |  i
 ƒ } Wn t j
 o d } n X| d j p t | ƒ d j o Pn | | 7} |  i t | ƒ 7_ |  i t | ƒ 7_ q W| S| t |  i ƒ j o7 |  i |  } |  i | |  _ |  i t | ƒ 7_ | SxÍ t |  i ƒ | j  o¶ | t |  i ƒ } |  i |  i @o t |  i | ƒ } n y |  i	 | ƒ } Wn t j
 o d } n X| d j p t | ƒ d j o Pn |  i | 7_ |  i t | ƒ 7_ qkW|  i |  } |  i | |  _ |  i t | ƒ 7_ | S(   sž  
        Read at most C{size} bytes from the file (less if we hit the end of the
        file first).  If the C{size} argument is negative or omitted, read all
        the remaining data in the file.

        @param size: maximum number of bytes to read
        @type size: int
        @return: data read from the file, or an empty string if EOF was
            encountered immediately
        @rtype: str
        s   File is closeds   File is not open for readingi    R   N(   R   t   IOErrorR   t	   FLAG_READR   R	   R   t   lenR   t   _readR   t   EOFErrorR   t   FLAG_BUFFEREDt   maxR   (   R   t   sizet   resultt   new_datat	   read_size(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt   reado   sT    
		  
  c   	   
   C   s2  |  i  o t d ƒ ‚ n |  i |  i @p t d ƒ ‚ n |  i } x¼t o´|  i oj |  i |  i @oY t | ƒ d j oF | d d j o | d } |  i	 d ƒ n |  i	 d ƒ t
 |  _ n | d	 j	 oe | d j oX t | ƒ | j o1 | | |  _ | |  } |  i t | ƒ 7_ | S| t | ƒ } n
 |  i } d | j p |  i |  i @o d | j o Pn y |  i | ƒ } Wn t j
 o d	 } n X| d	 j p t | ƒ d j o# d |  _ |  i t | ƒ 7_ | S| | 7} |  i t | ƒ 7_ qG W| i d ƒ } |  i |  i @oD | i d ƒ } | d j o$ | | j  p | d j  o
 | } qgn | d } | | d j o2 | t | ƒ j  o | | d j o | d 7} n | | |  _ | | | !} | |  d } t |  i ƒ d j o | d j o t |  _ n |  i	 | ƒ |  i t | ƒ 7_ | S(
   s  
        Read one entire line from the file.  A trailing newline character is
        kept in the string (but may be absent when a file ends with an
        incomplete line).  If the size argument is present and non-negative, it
        is a maximum byte count (including the trailing newline) and an
        incomplete line may be returned.  An empty string is returned only when
        EOF is encountered immediately.

        @note: Unlike stdio's C{fgets()}, the returned string contains null
        characters (C{'\0'}) if they occurred in the input.

        @param size: maximum length of returned string.
        @type size: int
        @return: next line of the file, or an empty string if the end of the
            file has been reached.
        @rtype: str
        s   File is closeds   File not open for readingi    s   
i   s   
s   R   N(   R   R   R   R   R	   R   R   t   FLAG_UNIVERSAL_NEWLINER    t   _record_newlineR
   R   R   R   R!   R"   R   t   find(	   R   R%   R   t   nR'   t   post   rpost   xpost   lf(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyR   ¥   sb    
	 .

	+ 	
'
5#c         C   s   g  } d } xl t  od |  i ƒ  } t | ƒ d j o Pn | i | ƒ | t | ƒ 7} | d j	 o | | j o Pq q W| S(   sÚ  
        Read all remaining lines using L{readline} and return them as a list.
        If the optional C{sizehint} argument is present, instead of reading up
        to EOF, whole lines totalling approximately sizehint bytes (possibly
        after rounding up to an internal buffer size) are read.

        @param sizehint: desired maximum number of bytes to read.
        @type sizehint: int
        @return: list of lines read from the file.
        @rtype: list
        i    N(   R   R   R    t   appendR   (   R   t   sizehintt   linest   bytesR   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt	   readlinesô   s     
c         C   s   t  d ƒ ‚ d S(   s¹  
        Set the file's current position, like stdio's C{fseek}.  Not all file
        objects support seeking.

        @note: If a file is opened in append mode (C{'a'} or C{'a+'}), any seek
            operations will be undone at the next write (as the file position
            will move back to the end of the file).
        
        @param offset: position to move to within the file, relative to
            C{whence}.
        @type offset: int
        @param whence: type of movement: 0 = absolute; 1 = relative to the
            current position; 2 = relative to the end of the file.
        @type whence: int

        @raise IOError: if the file doesn't support random access.
        s   File does not support seeking.N(   R   (   R   t   offsett   whence(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt   seek  s    c         C   s   |  i  S(   sý   
        Return the file's current position.  This may not be accurate or
        useful if the underlying file doesn't support random access, or was
        opened in append mode.

        @return: file position (in bytes).
        @rtype: int
        (   R   (   R   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt   tell   s    	c         C   s1  |  i  o t d ƒ ‚ n |  i |  i @p t d ƒ ‚ n |  i |  i @p |  i | ƒ d S|  i i | ƒ |  i |  i @o‡ | i	 d ƒ } | d j of |  i i
 ƒ  } | t | ƒ t | ƒ 7} |  i | | d  ƒ t ƒ  |  _ |  i i | | d ƒ n d S|  i i ƒ  |  i j o |  i ƒ  n d S(   s@  
        Write data to the file.  If write buffering is on (C{bufsize} was
        specified and non-zero), some or all of the data may not actually be
        written yet.  (Use L{flush} or L{close} to force buffered data to be
        written out.)

        @param data: data to write.
        @type data: str
        s   File is closeds   File not open for writingNs   
i    i   (   R   R   R   t
   FLAG_WRITER#   R   R   t   writet   FLAG_LINE_BUFFEREDt   rfindR   R    R    R:   R   R   (   R   t   datat   last_newline_post   wbuf(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyR<   +  s(    

c         C   s"   x | D] } |  i  | ƒ q Wd S(   sb  
        Write a sequence of strings to the file.  The sequence can be any
        iterable object producing strings, typically a list of strings.  (The
        name is intended to match L{readlines}; C{writelines} does not add line
        separators.)

        @param sequence: an iterable sequence of strings.
        @type sequence: sequence
        N(   R<   (   R   t   sequenceR   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt
   writelinesM  s    
 c         C   s   |  S(   s¶   
        Identical to C{iter(f)}.  This is a deprecated file interface that
        predates python iterator support.

        @return: an iterator.
        @rtype: iterator
        (    (   R   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt
   xreadlines[  s    c         C   s   t  ƒ  ‚ d S(   s‰   
        I{(subclass override)}
        Read data from the stream.  Return C{None} or raise C{EOFError} to
        indicate EOF.
        N(   R"   (   R   R%   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyR!   i  s    c         C   s   t  d ƒ ‚ d S(   sL   
        I{(subclass override)}
        Write data into the stream.
        s   write not implementedN(   R   (   R   R?   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt   _writeq  s    c         C   s   d S(   so  
        I{(subclass override)}
        Return the size of the file.  This is called from within L{_set_mode}
        if the file is opened in append mode, so the file position can be
        tracked and L{seek} and L{tell} will work correctly.  If the file is
        a stream that can't be randomly accessed, you don't need to override
        this method,
        i    (    (   R   (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt	   _get_sizex  s    	t   riÿÿÿÿc         C   s¶  |  i  |  _ | d j  o
 d } n | d j o |  i |  i |  i BO_ nk | d j o2 | |  _ |  i |  i O_ |  i |  i M_ n, | d j o |  i |  i |  i BM_ n d | j p d | j o |  i |  i O_ n d | j p d | j o |  i |  i O_ n d | j o? |  i |  i |  i BO_ |  i ƒ  |  _	 |  i	 |  _
 |  _ n d | j o |  i |  i O_ n d | j o |  i |  i O_ d	 |  _ n d	 S(
   sM   
        Subclasses call this method to initialize the BufferedFile.
        i    i   RG   t   +t   wt   at   bt   UN(   R   R   R   R#   R=   R   R;   t   FLAG_APPENDRF   R   R   R   t   FLAG_BINARYR*   R   R   (   R   t   modet   bufsize(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt	   _set_mode‡  s0    
	c         C   s   x† t  | ƒ d j or |  i | ƒ } | | } |  i |  i @o& |  i | 7_ |  i |  _ |  _ q |  i | 7_ |  i | 7_ q Wd  S(   Ni    (   R    RE   R   RM   R   R   R   R   (   R   R?   t   count(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyR   ¯  s     
c         C   s™   |  i  |  i @p d  S|  i d  j o | |  _ nc t |  i ƒ t j o& |  i | j o |  i | f |  _ n' | |  i j o |  i | f 7_ n d  S(   N(   R   R*   R   R   t   typet   str(   R   t   newline(    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyR+   ½  s    &N(#   t   __name__t
   __module__t   __doc__R   t   SEEK_SETt   SEEK_CURt   SEEK_ENDR   R;   RM   RN   R#   R=   R*   R   R   R   R   R   R   R   R)   R   R6   R9   R:   R<   RC   RD   R!   RE   RF   RQ   R   R+   (    (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyR      s@   							6O		"					(	N(   RX   t	   cStringIOR    t   objectR   (    (    (    sL   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\file.pyt   <module>   s   