Ñò
ðgcJc           @   s­   d  Z  d d k Z d d k Z d d k l Z l Z d d k Td d k l Z d d k	 Td d k
 Td d k Th e d 6e d 6Z d e e f d	 „  ƒ  YZ d d
 k l Z d S(   s   
Server-mode SFTP support.
iÿÿÿÿN(   t   MD5t   SHA(   t   *(   t   SubsystemHandlert   sha1t   md5t
   SFTPServerc           B   s­   e  Z d  Z e d „ Z d „  Z d „  Z d „  Z d „  Z e	 e ƒ Z d „  Z
 e	 e
 ƒ Z
 d „  Z e d „ Z d d	 „ Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   sä   
    Server-side SFTP subsystem support.  Since this is a L{SubsystemHandler},
    it can be (and is meant to be) set as the handler for C{"sftp"} requests.
    Use L{Transport.set_subsystem_handler} to activate this class.
    c         O   sŽ   t  i |  ƒ t i |  | | | ƒ | i ƒ  } t i | i ƒ  d ƒ |  _ | i ƒ  |  _	 d |  _
 h  |  _ h  |  _ | | | | Ž |  _ d S(   sâ  
        The constructor for SFTPServer is meant to be called from within the
        L{Transport} as a subsystem handler.  C{server} and any additional
        parameters or keyword parameters are passed from the original call to
        L{Transport.set_subsystem_handler}.

        @param channel: channel passed from the L{Transport}.
        @type channel: L{Channel}
        @param name: name of the requested subsystem.
        @type name: str
        @param server: the server object associated with this channel and
            subsystem
        @type server: L{ServerInterface}
        @param sftp_si: a subclass of L{SFTPServerInterface} to use for handling
            individual requests.
        @type sftp_si: class
        s   .sftpi   N(   t   BaseSFTPt   __init__R   t   get_transportt   utilt
   get_loggert   get_log_channelt   loggert   get_hexdumpt   ultra_debugt   next_handlet
   file_tablet   folder_tablet   server(   t   selft   channelt   nameR   t   sftp_sit   largst   kwargst	   transport(    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyR   0   s    			c         C   s‹   t  t | ƒ t ƒ oC xn | D]4 } t t |  ƒ i | d |  i i ƒ  d | ƒ q Wn/ t t |  ƒ i | d |  i i ƒ  d | ƒ d  S(   Ns   [chan s   ] (   t
   issubclasst   typet   listt   superR   t   _logt   sockt   get_name(   R   t   levelt   msgt   m(    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyR   M   s
     6c   	   
   C   sd  | |  _  |  i t d t | ƒ ƒ |  i ƒ  |  i i ƒ  x#t oy |  i ƒ  \ } } Wni t	 j
 o |  i t d ƒ d  St
 j
 o: } |  i t d t | ƒ ƒ |  i t t i ƒ  ƒ d  SXt | ƒ } | i ƒ  } y |  i | | | ƒ Wq= t
 j
 oW } |  i t d t | ƒ ƒ |  i t t i ƒ  ƒ y |  i | t ƒ Wq[q[Xq= Xq= Wd  S(   Ns!   Started sftp server on channel %ss   EOF -- end of sessions   Exception on channel: s    Exception in server processing: (   R    R   t   DEBUGt   reprt   _send_server_versionR   t   session_startedt   Truet   _read_packett   EOFErrort	   Exceptiont   strR
   t
   tb_stringst   Messaget   get_intt   _processt   _send_statust   SFTP_FAILURE(	   R   R   R   R   t   tt   datat   eR#   t   request_number(    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyt   start_subsystemT   s4    	
 c         C   s~   |  i  i ƒ  t t |  ƒ i ƒ  x! |  i i ƒ  D] } | i ƒ  q0 Wx! |  i i ƒ  D] } | i ƒ  qT Wh  |  _ h  |  _ d  S(   N(	   R   t   session_endedR   R   t   finish_subsystemR   t
   itervaluest   closeR   (   R   t   f(    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyR:   p   s      	c         C   sB   |  t  i j o t S|  t  i j p |  t  i j o t St Sd S(   s  
        Convert an errno value (as from an C{OSError} or C{IOError}) into a
        standard SFTP result code.  This is a convenience function for trapping
        exceptions in server code and returning an appropriate result.

        @param e: an errno code, as from C{OSError.errno}.
        @type e: int
        @return: an SFTP error code like L{SFTP_NO_SUCH_FILE}.
        @rtype: int
        N(   t   errnot   EACCESt   SFTP_PERMISSION_DENIEDt   ENOENTt   ENOTDIRt   SFTP_NO_SUCH_FILER3   (   R6   (    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyt   convert_errno{   s
     c         C   sÍ   t  i d j oZ | i | i @o t i |  | i ƒ n | i | i @o t i |  | i	 | i
 ƒ qj n | i | i @o  t i |  | i | i f ƒ n | i | i @o t |  d ƒ i | i ƒ n d S(   sn  
        Change a file's attributes on the local filesystem.  The contents of
        C{attr} are used to change the permissions, owner, group ownership,
        and/or modification & access time of the file, depending on which
        attributes are present in C{attr}.

        This is meant to be a handy helper function for translating SFTP file
        requests into local file operations.
        
        @param filename: name of the file to alter (should usually be an
            absolute path).
        @type filename: str
        @param attr: attributes to change.
        @type attr: L{SFTPAttributes}
        t   win32s   w+N(   t   syst   platformt   _flagst   FLAG_PERMISSIONSt   ost   chmodt   st_modet   FLAG_UIDGIDt   chownt   st_uidt   st_gidt   FLAG_AMTIMEt   utimet   st_atimet   st_mtimet	   FLAG_SIZEt   opent   truncatet   st_size(   t   filenamet   attr(    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyt   set_file_attr   s    ! c         G   sû   t  ƒ  } | i | ƒ xÈ | D]À } t | ƒ t j o | i | ƒ q t | ƒ t j o | i | ƒ q t | ƒ t j o | i | ƒ q t | ƒ t j o | i	 | ƒ q t
 d t | ƒ d t t | ƒ ƒ ƒ ‚ q W|  i | t | ƒ ƒ d  S(   Ns   unknown type for s    type (   R/   t   add_intR   t   intt   longt	   add_int64R-   t
   add_stringt   SFTPAttributest   _packR,   R&   t   _send_packet(   R   R7   R4   t   argR#   t   item(    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyt	   _response°   s    	 .c         C   sœ   t  t | ƒ t ƒ p |  i | | ƒ d  S| i d |  i ƒ |  i d 7_ | o | |  i | i ƒ  <n | |  i | i ƒ  <|  i	 | t
 | i ƒ  ƒ d  S(   Ns   hx%di   (   R   R   t
   SFTPHandleR2   t	   _set_nameR   R   t	   _get_nameR   Rf   t
   CMD_HANDLE(   R   R7   t   handlet   folder(    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyt   _send_handle_responseÀ   s    c      	   C   sX   | d  j o. y t | } Wq; t j
 o d } q; Xn |  i | t | | d ƒ d  S(   Nt   Unknownt    (   t   Nonet	   SFTP_DESCt
   IndexErrorRf   t
   CMD_STATUS(   R   R7   t   codet   desc(    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyR2   Í   s    c         C   sj   |  i  i | ƒ } t t | ƒ t ƒ o. t ƒ  } | i | ƒ |  i | | t ƒ d  S|  i	 | | ƒ d  S(   N(
   R   t   list_folderR   R   R   Rg   t
   _set_filesRm   R)   R2   (   R   R7   t   patht   respRl   (    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyt   _open_folderÖ   s    	c         C   s¸   | i  ƒ  } t | ƒ d j o |  i | t ƒ d  St ƒ  } | i | ƒ | i t | ƒ ƒ x> | D]6 } | i | i ƒ | i t | ƒ ƒ | i	 | ƒ qd W|  i
 t t | ƒ ƒ d  S(   Ni    (   t   _get_next_filest   lenR2   t   SFTP_EOFR/   R\   R`   RY   R-   Rb   Rc   t   CMD_NAME(   R   R7   Rl   t   flistR#   RZ   (    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyt   _read_folderá   s    	 c         C   sŒ  | i  ƒ  } | i ƒ  } | i ƒ  } | i ƒ  } | i ƒ  } | |  i j o |  i | t d ƒ d  S|  i | } xG | D]( }	 |	 t j o |	 }
 t |	 } Pqx qx W|  i | t d ƒ d  S| d j oK | i	 ƒ  } t
 t | ƒ t ƒ p |  i | | d ƒ d  S| i | } n | d j o
 | } n | d j  o |  i | t d ƒ d  Sd } | } x× | | | j  oÅ t | | | | ƒ } t | d ƒ } d } | i ƒ  } xv | | j  oh | i | | ƒ } t | ƒ t j	 o |  i | | d	 ƒ d  S| i | ƒ | t | ƒ 7} | | 7} qªW| | i ƒ  7} q^Wt ƒ  } | i | ƒ | i d
 ƒ | i |
 ƒ | i | ƒ |  i t t | ƒ ƒ d  S(   Ns   Invalid handles   No supported hash types foundi    s   Unable to stat filei   s   Block size too smallRo   i   s   Unable to hash files
   check-file(   t
   get_stringt   get_listt	   get_int64R0   R   R2   t   SFTP_BAD_MESSAGEt   _hash_classR3   t   statR   R   Ra   RX   t   mint   newt   readR-   t   updateR|   t   digestR/   R\   R`   t	   add_bytesRc   t   CMD_EXTENDED_REPLY(   R   R7   R#   Rk   t   alg_listt   startt   lengtht
   block_sizeR=   t   xt   algnamet   algt   stt   sum_outt   offsett   blocklent   chunklent   countt   hash_objR5   (    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyt   _check_fileï   sh     
	
  	c         C   s¸   | t  @o | t @o t i } n" | t @o t i } n
 t i } | t @o | t i O} n | t @o | t i	 O} n | t
 @o | t i O} n | t @o | t i O} n | S(   s;   convert SFTP-style open() flags to python's os.open() flags(   t   SFTP_FLAG_READt   SFTP_FLAG_WRITERJ   t   O_RDWRt   O_WRONLYt   O_RDONLYt   SFTP_FLAG_APPENDt   O_APPENDt   SFTP_FLAG_CREATEt   O_CREATt   SFTP_FLAG_TRUNCt   O_TRUNCt   SFTP_FLAG_EXCLt   O_EXCL(   R   t   pflagst   flags(    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyt   _convert_pflags*  s    	c         C   sŸ  |  i  t d t | ƒ | t j oV | i ƒ  } |  i | i ƒ  ƒ } t i | ƒ } |  i	 | |  i
 i | | | ƒ ƒ n!| t j o’ | i ƒ  } | |  i j o |  i | =|  i | t ƒ d  S| |  i j o0 |  i | i ƒ  |  i | =|  i | t ƒ d  S|  i | t d ƒ n‚| t j oÊ | i ƒ  } | i ƒ  } | i ƒ  }	 | |  i j o |  i | t d ƒ d  S|  i | i | |	 ƒ }
 t |
 ƒ t j o> t |
 ƒ d j o |  i | t ƒ qí|  i | t |
 ƒ q›|  i | |
 ƒ n«| t j os | i ƒ  } | i ƒ  } | i ƒ  }
 | |  i j o |  i | t d ƒ d  S|  i | |  i | i | |
 ƒ ƒ n+| t j o, | i ƒ  } |  i | |  i
 i | ƒ ƒ nò| t  j o; | i ƒ  } | i ƒ  } |  i | |  i
 i! | | ƒ ƒ nª| t" j o> | i ƒ  } t i | ƒ } |  i | |  i
 i# | | ƒ ƒ n_| t$ j o, | i ƒ  } |  i | |  i
 i% | ƒ ƒ n&| t& j o! | i ƒ  } |  i' | | ƒ d  S| t( j oU | i ƒ  } | |  i j o |  i | t d ƒ d  S|  i | } |  i) | | ƒ n–| t* j o_ | i ƒ  } |  i
 i+ | ƒ } t, t | ƒ t ƒ o |  i | t- | ƒ q›|  i | | ƒ n*| t. j o_ | i ƒ  } |  i
 i/ | ƒ } t, t | ƒ t ƒ o |  i | t- | ƒ q›|  i | | ƒ n¾| t0 j oˆ | i ƒ  } | |  i j o |  i | t d ƒ d  S|  i | i+ ƒ  } t, t | ƒ t ƒ o |  i | t- | ƒ q›|  i | | ƒ n)| t1 j o> | i ƒ  } t i | ƒ } |  i | |  i
 i2 | | ƒ ƒ nÞ| t3 j og | i ƒ  } t i | ƒ } | |  i j o |  i | t d ƒ d  S|  i | |  i | i2 | ƒ ƒ nj| t4 j oh | i ƒ  } |  i
 i5 | ƒ } t | ƒ t j o# |  i | t6 d | d t ƒ  ƒ q›|  i | | ƒ nõ | t7 j o; | i ƒ  } | i ƒ  } |  i | |  i
 i8 | | ƒ ƒ n­ | t9 j oA | i ƒ  } |  i
 i: | ƒ } |  i | t6 d | d t ƒ  ƒ n_ | t; j oA | i ƒ  } | d j o |  i< | | ƒ q›|  i | t= ƒ n |  i | t= ƒ d  S(   Ns   Request: %ss   Invalid handlei    i   Ro   s
   check-file(>   R   R%   t	   CMD_NAMESt   CMD_OPENR   R¬   R0   Ra   t	   _from_msgRm   R   RV   t	   CMD_CLOSER   R2   t   SFTP_OKR   R<   R„   t   CMD_READRƒ   R‰   R   R-   R|   R}   Rf   t   CMD_DATAt	   CMD_WRITEt   writet
   CMD_REMOVEt   removet
   CMD_RENAMEt   renamet	   CMD_MKDIRt   mkdirt	   CMD_RMDIRt   rmdirt   CMD_OPENDIRRz   t   CMD_READDIRR€   t   CMD_STATR†   R   t	   CMD_ATTRSt	   CMD_LSTATt   lstatt	   CMD_FSTATt   CMD_SETSTATt   chattrt   CMD_FSETSTATt   CMD_READLINKt   readlinkR~   t   CMD_SYMLINKt   symlinkt   CMD_REALPATHt   canonicalizet   CMD_EXTENDEDRœ   t   SFTP_OP_UNSUPPORTED(   R   R4   R7   R#   Rx   R«   RZ   Rk   R—   R   R5   t   oldpatht   newpathRl   Ry   t   target_patht   rpatht   tag(    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyR1   <  sè    &

' ## #$###N(   t   __name__t
   __module__t   __doc__t   SFTPServerInterfaceR   R   R8   R:   RD   t   staticmethodR[   Rf   t   FalseRm   Rp   R2   Rz   R€   Rœ   R¬   R1   (    (    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyR   )   s"   										;	(   Rg   (   R×   RJ   R>   t   Crypto.HashR    R   t   paramiko.commont   paramiko.serverR   t   paramiko.sftpt   paramiko.sftp_sit   paramiko.sftp_attrR…   R   R   t   paramiko.sftp_handleRg   (    (    (    sS   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\sftp_server.pyt   <module>   s   




ÿ ”