Ñò
ðgcJc           @   sˆ   d  Z  d d k l Z d d k Z d d k Z d d k Z d d k Td d k Td d k l	 Z	 d d k
 l Z d e	 f d „  ƒ  YZ d S(	   s   
L{SFTPFile}
iÿÿÿÿ(   t   hexlifyN(   t   *(   t   BufferedFile(   t   SFTPAttributest   SFTPFilec           B   s  e  Z d  Z d Z d d d „ Z d „  Z d „  Z e d „ Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d d „ Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  RS(    sL   
    Proxy object for a file on the remote server, in client mode SFTP.
    i €  t   riÿÿÿÿc         C   sl   t  i |  ƒ | |  _ | |  _ t  i |  | | ƒ t |  _ t |  _ t |  _ h  |  _	 g  |  _
 d  |  _ d  S(   N(   R   t   __init__t   sftpt   handlet	   _set_modet   Falset	   pipelinedt   _prefetchingt   _prefetch_donet   _prefetch_datat   _prefetch_readst   Nonet   _saved_exception(   t   selfR   R   t   modet   bufsize(    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyR   +   s    							c         C   s   |  i  d t ƒ d  S(   Nt   async(   t   _closet   True(   R   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   __del__7   s    c         C   s   |  i  d t ƒ d  S(   NR   (   R   R
   (   R   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   close:   s    c         C   sÓ   |  i  o d  S|  i i t d t |  i ƒ ƒ |  i o |  i i |  ƒ n t i	 |  ƒ yD | o# |  i i
 t d  ƒ t |  i ƒ n |  i i t |  i ƒ Wn. t j
 o n t t i f j
 o n Xd  S(   Ns	   close(%s)(   t   _closedR   t   _logt   DEBUGR    R   R   t   _finish_responsesR   R   t   _async_requestt   typeR   t	   CMD_CLOSEt   _requestt   EOFErrort   IOErrort   sockett   error(   R   R   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyR   =   s    
 
#c         C   sÁ   g  } |  i  D]" } | d | j o | | q q ~ } t | ƒ d j o t S| i d „  ƒ | d \ } } | | | j o t S| | | | j o t S|  i | | | | | | ƒ S(   Ni    c         S   s   t  |  d  | d  ƒ S(   i    (   t   cmp(   t   xt   y(    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   <lambda>\   s    iÿÿÿÿ(   R   t   lenR
   t   sortR   t   _data_in_prefetch_requests(   R   t   offsett   sizet   _[1]t   it   kt
   buf_offsett   buf_size(    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyR,   X   s    9c         C   sŒ   g  } |  i  i ƒ  D] } | | j o | | q q ~ } t | ƒ d j o d St | ƒ } | | } | t |  i  | ƒ j o d S| S(   s  
        if a block of data is present in the prefetch buffers, at the given
        offset, return the offset of the relevant prefetch buffer.  otherwise,
        return None.  this guarantees nothing about the number of bytes
        collected in the prefetch buffer so far.
        i    N(   R   t   keysR*   R   t   max(   R   R-   R/   R0   R1   t   indexR2   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   _data_in_prefetch_buffersg   s    ;
c         C   s  x` t  oX |  i |  i ƒ } | d j	 o Pn |  i p
 |  i o Pn |  i i ƒ  |  i ƒ  q W| d j o t	 |  _
 d S|  i | } |  i | =|  i | } | d j o | |  |  i | <| | } n | t | ƒ j  o& | | |  i |  i | <| |  } n | S(   s£   
        read data out of the prefetch buffer, if possible.  if the data isn't
        in the buffer, return None.  otherwise, behaves like a normal read.
        i    N(   R   R7   t   _realposR   R   R   R   t   _read_responset   _check_exceptionR
   R   R   R*   (   R   R.   R-   t   prefetchR2   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   _read_prefetchx   s,     	
c         C   s›   t  | |  i ƒ } |  i o% |  i | ƒ } | d  j	 o | Sn |  i i t |  i t	 |  i
 ƒ t | ƒ ƒ \ } } | t j o t d ƒ ‚ n | i ƒ  S(   Ns   Expected data(   t   mint   MAX_REQUEST_SIZER   R<   R   R   R!   t   CMD_READR   t   longR8   t   intt   CMD_DATAt	   SFTPErrort
   get_string(   R   R.   t   datat   tt   msg(    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   _read•   s    
	3c         C   s­   t  t | ƒ |  i ƒ } |  i i t d  ƒ t |  i t	 |  i
 ƒ t | |  ƒ ƒ } |  i p |  i i i ƒ  o9 |  i i | ƒ \ } } | t j o t d ƒ ‚ q© n | S(   Ns   Expected status(   R=   R*   R>   R   R   R   R   t	   CMD_WRITER   R@   R8   t   strR   t   sockt
   recv_readyR9   t
   CMD_STATUSRC   (   R   RE   t   chunkt   reqRF   RG   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   _write    s    :c         C   s   |  i  i i | ƒ d S(   sA  
        Set a timeout on read/write operations on the underlying socket or
        ssh L{Channel}.

        @see: L{Channel.settimeout}
        @param timeout: seconds to wait for a pending read/write operation
            before raising C{socket.timeout}, or C{None} for no timeout
        @type timeout: float
        N(   R   RK   t
   settimeout(   R   t   timeout(    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyRQ   «   s    
c         C   s   |  i  i i ƒ  S(   sÁ   
        Returns the timeout in seconds (as a float) associated with the socket
        or ssh L{Channel} used for this file.

        @see: L{Channel.gettimeout}
        @rtype: float
        (   R   RK   t
   gettimeout(   R   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyRS   ·   s    c         C   s   |  i  i i | ƒ d S(   s  
        Set blocking or non-blocking mode on the underiying socket or ssh
        L{Channel}.

        @see: L{Channel.setblocking}
        @param blocking: 0 to set non-blocking mode; non-0 to set blocking
            mode.
        @type blocking: int
        N(   R   RK   t   setblocking(   R   t   blocking(    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyRT   Á   s    
i    c         C   s„   |  i  ƒ  | |  i j o | |  _ |  _ nJ | |  i j o |  i | 7_ |  i |  _ n |  i ƒ  | |  _ |  _ d |  _ d  S(   Nt    (   t   flusht   SEEK_SETR8   t   _post   SEEK_CURt	   _get_sizet   _rbuffer(   R   R-   t   whence(    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   seekÍ   s    
c         C   sH   |  i  i t |  i ƒ \ } } | t j o t d ƒ ‚ n t i | ƒ S(   s  
        Retrieve information about this file from the remote system.  This is
        exactly like L{SFTP.stat}, except that it operates on an already-open
        file.

        @return: an object containing attributes about this file.
        @rtype: SFTPAttributes
        s   Expected attributes(   R   R!   t	   CMD_FSTATR   t	   CMD_ATTRSRC   R   t	   _from_msg(   R   RF   RG   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   statØ   s    	c         C   sU   |  i  i t d t |  i ƒ | f ƒ t ƒ  } | | _ |  i  i t |  i | ƒ d S(   sé   
        Change the mode (permissions) of this file.  The permissions are
        unix-style and identical to those used by python's C{os.chmod}
        function.

        @param mode: new permissions
        @type mode: int
        s   chmod(%s, %r)N(	   R   R   R   R    R   R   t   st_modeR!   t   CMD_FSETSTAT(   R   R   t   attr(    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   chmodæ   s    	&		c         C   sb   |  i  i t d t |  i ƒ | | f ƒ t ƒ  } | | | _ | _ |  i  i t	 |  i | ƒ d S(   s|  
        Change the owner (C{uid}) and group (C{gid}) of this file.  As with
        python's C{os.chown} function, you must pass both arguments, so if you
        only want to change one, use L{stat} first to retrieve the current
        owner and group.

        @param uid: new owner's uid
        @type uid: int
        @param gid: new group id
        @type gid: int
        s   chown(%s, %r, %r)N(
   R   R   R   R    R   R   t   st_uidt   st_gidR!   Rd   (   R   t   uidt   gidRe   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   chownô   s    )	c         C   s‡   | d j o t i ƒ  t i ƒ  f } n |  i i t d t |  i ƒ | f ƒ t ƒ  } | \ | _ | _	 |  i i
 t |  i | ƒ d S(   sm  
        Set the access and modified times of this file.  If
        C{times} is C{None}, then the file's access and modified times are set
        to the current time.  Otherwise, C{times} must be a 2-tuple of numbers,
        of the form C{(atime, mtime)}, which is used to set the access and
        modified times, respectively.  This bizarre API is mimicked from python
        for the sake of consistency -- I apologize.

        @param times: C{None} or a tuple of (access time, modified time) in
            standard internet epoch time (seconds since 01 January 1970 GMT)
        @type times: tuple(int)
        s   utime(%s, %r)N(   R   t   timeR   R   R   R    R   R   t   st_atimet   st_mtimeR!   Rd   (   R   t   timesRe   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   utime  s    &	c         C   sU   |  i  i t d t |  i ƒ | f ƒ t ƒ  } | | _ |  i  i t |  i | ƒ d S(   s  
        Change the size of this file.  This usually extends
        or shrinks the size of the file, just like the C{truncate()} method on
        python file objects.
        
        @param size: the new size of the file
        @type size: int or long
        s   truncate(%s, %r)N(	   R   R   R   R    R   R   t   st_sizeR!   Rd   (   R   R.   Re   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   truncate  s    	&		c   
      C   sa   |  i  i t d |  i | t | ƒ t | ƒ | ƒ \ } } | i ƒ  } | i ƒ  } | i ƒ  }	 |	 S(   s€  
        Ask the server for a hash of a section of this file.  This can be used
        to verify a successful upload or download, or for various rsync-like
        operations.
        
        The file is hashed from C{offset}, for C{length} bytes.  If C{length}
        is 0, the remainder of the file is hashed.  Thus, if both C{offset}
        and C{length} are zero, the entire file is hashed.
        
        Normally, C{block_size} will be 0 (the default), and this method will
        return a byte string representing the requested hash (for example, a
        string of length 16 for MD5, or 20 for SHA-1).  If a non-zero
        C{block_size} is given, each chunk of the file (from C{offset} to
        C{offset + length}) of C{block_size} bytes is computed as a separate
        hash.  The hash results are all concatenated and returned as a single
        string.
        
        For example, C{check('sha1', 0, 1024, 512)} will return a string of
        length 40.  The first 20 bytes will be the SHA-1 of the first 512 bytes
        of the file, and the last 20 bytes will be the SHA-1 of the next 512
        bytes.
        
        @param hash_algorithm: the name of the hash algorithm to use (normally
            C{"sha1"} or C{"md5"})
        @type hash_algorithm: str
        @param offset: offset into the file to begin hashing (0 means to start
            from the beginning)
        @type offset: int or long
        @param length: number of bytes to hash (0 means continue to the end of
            the file)
        @type length: int or long
        @param block_size: number of bytes to hash per result (must not be less
            than 256; 0 means to compute only one hash of the entire segment)
        @type block_size: int
        @return: string of bytes representing the hash of each block,
            concatenated together
        @rtype: str
        
        @note: Many (most?) servers don't support this extension yet.
        
        @raise IOError: if the server doesn't support the "check-file"
            extension, or possibly doesn't support the hash algorithm
            requested
            
        @since: 1.4
        s
   check-file(   R   R!   t   CMD_EXTENDEDR   R@   RD   t   get_remainder(
   R   t   hash_algorithmR-   t   lengtht
   block_sizeRF   RG   t   extt   algRE   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   check'  s    /$c         C   s   | |  _  d S(   sì  
        Turn on/off the pipelining of write operations to this file.  When
        pipelining is on, paramiko won't wait for the server response after
        each write operation.  Instead, they're collected as they come in.
        At the first non-write operation (including L{close}), all remaining
        server responses are collected.  This means that if there was an error
        with one of your later writes, an exception might be thrown from
        within L{close} instead of L{write}.
        
        By default, files are I{not} pipelined.
        
        @param pipelined: C{True} if pipelining should be turned on for this
            file; C{False} otherwise
        @type pipelined: bool
        
        @since: 1.5
        N(   R   (   R   R   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   set_pipelined]  s    c         C   sŽ   |  i  ƒ  i } g  } |  i } xE | | j  o7 t |  i | | ƒ } | i | | f ƒ | | 7} q! Wt | ƒ d j o |  i | ƒ n d S(   s„  
        Pre-fetch the remaining contents of this file in anticipation of
        future L{read} calls.  If reading the entire file, pre-fetching can
        dramatically improve the download speed by avoiding roundtrip latency.
        The file's contents are incrementally buffered in a background thread.
        
        The prefetched data is stored in a buffer until read via the L{read}
        method.  Once data has been read, it's removed from the buffer.  The
        data may be read in a random order (using L{seek}); chunks of the
        buffer that haven't been read will continue to be buffered.

        @since: 1.5.1
        i    N(   Rb   Rq   R8   R=   R>   t   appendR*   t   _start_prefetch(   R   R.   t   chunkst   nRN   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyR;   q  s    	 c         c   s   |  i  i t d t |  i ƒ | f ƒ g  } xŒ | D]„ \ } } |  i | ƒ p |  i | | ƒ o q3 n xK | d j o= t | |  i ƒ } | i	 | | f ƒ | | 7} | | 8} ql Wq3 W|  i
 | ƒ x1 | D]) } |  i | d ƒ |  i | d ƒ VqÏ Wd S(   s*  
        Read a set of blocks from the file by (offset, length).  This is more
        efficient than doing a series of L{seek} and L{read} calls, since the
        prefetch machinery is used to retrieve all the requested blocks at
        once.
        
        @param chunks: a list of (offset, length) tuples indicating which
            sections of the file to read
        @type chunks: list(tuple(long, int))
        @return: a list of blocks read, in the same order as in C{chunks}
        @rtype: list(str)
        
        @since: 1.5.4
        s   readv(%s, %r)i    i   N(   R   R   R   R    R   R7   R,   R=   R>   R|   R}   R^   t   read(   R   R~   t   read_chunksR-   R.   t
   chunk_sizeR'   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   readvŠ  s"    & # 
 c         C   s    y |  i  ƒ  i SWn d SXd  S(   Ni    (   Rb   Rq   (   R   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyR[   ²  s    c         C   s[   t  |  _ t |  _ |  i i | ƒ t i d |  i d | f ƒ } | i	 t  ƒ | i
 ƒ  d  S(   Nt   targett   args(   R   R   R
   R   R   t   extendt	   threadingt   Threadt   _prefetch_threadt	   setDaemont   start(   R   R~   RF   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyR}   ¸  s    		c         C   sF   x? | D]7 \ } } |  i  i |  t |  i t | ƒ t | ƒ ƒ q Wd  S(   N(   R   R   R?   R   R@   RA   (   R   R~   R-   Rv   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyR‰   Á  s     c         C   s¼   | t  j o: y |  i i | ƒ Wn t j
 o } | |  _ n Xd  S| t j o t d ƒ ‚ n | i ƒ  } |  i i	 d ƒ \ } } | |  i
 | <t |  i ƒ d j o t |  _ n d  S(   Ns   Expected datai    (   RM   R   t   _convert_statust	   ExceptionR   RB   RC   RD   R   t   popR   R*   R   R   (   R   RF   RG   R'   RE   R-   Rv   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   _async_responseÇ  s    c         C   s0   |  i  d j	 o |  i  } d |  _  | ‚ n d S(   s.   if there's a saved exception, raise & clear itN(   R   R   (   R   R'   (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyR:   ×  s    		(!   t   __name__t
   __module__t   __doc__R>   R   R   R   R
   R   R,   R7   R<   RH   RP   RQ   RS   RT   R^   Rb   Rf   Rk   Rp   Rr   Rz   R   R{   R;   Rƒ   R[   R}   R‰   R   R:   (    (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyR   "   s:   									
						6		(					(   R’   t   binasciiR    R$   R‡   Rl   t   paramiko.commont   paramiko.sftpt   paramiko.fileR   t   paramiko.sftp_attrR   R   (    (    (    sQ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_file.pyt   <module>   s   

