Pc@sPdZddlZddlTddlTdefdYZddlmZdS(s7 Abstraction of an SFTP file handle (for server mode). iN(t*t SFTPHandlecBskeZdZddZdZdZdZdZdZdZ d Z d Z d Z RS( s^ Abstract object representing a handle to an open file (or folder) in an SFTP server implementation. Each handle has a string representation used by the client to refer to the underlying file. Server implementations can (and should) subclass SFTPHandle to implement features of a file handle, like L{stat} or L{chattr}. icCs(||_d|_i|_d|_dS(s2 Create a new file handle representing a local file being served over SFTP. If C{flags} is passed in, it's used to determine if the file is open in append mode. @param flags: optional flags as passed to L{SFTPServerInterface.open} @type flags: int N(t_SFTPHandle__flagstNonet_SFTPHandle__namet_SFTPHandle__filest_SFTPHandle__tell(tselftflags((s/..\python\site-packages\paramiko\sftp_handle.pyt__init__&s   cCsZt|dd}|dk r+|jnt|dd}|dk rV|jndS(s$ When a client closes a file, this method is called on the handle. Normally you would use this method to close the underlying OS level file object(s). The default implementation checks for attributes on C{self} named C{readfile} and/or C{writefile}, and if either or both are present, their C{close()} methods are called. This means that if you are using the default implementations of L{read} and L{write}, this method's default implementation should be fine also. treadfilet writefileN(tgetattrRtclose(RR R ((s/..\python\site-packages\paramiko\sftp_handle.pyR 5s    cCst|dd}|dkr"tSy\|jdkrF|j|_n||jkrn|j|||_n|j|}Wn)tk r}d|_tj |j SX|jt |7_|S(s Read up to C{length} bytes from this file, starting at position C{offset}. The offset may be a python long, since SFTP allows it to be 64 bits. If the end of the file has been reached, this method may return an empty string to signify EOF, or it may also return L{SFTP_EOF}. The default implementation checks for an attribute on C{self} named C{readfile}, and if present, performs the read operation on the python file-like object found there. (This is meant as a time saver for the common case where you are wrapping a python file object.) @param offset: position in the file to start reading from. @type offset: int or long @param length: number of bytes to attempt to read. @type length: int @return: data read from the file, or an SFTP error code. @rtype: str R N( R RtSFTP_OP_UNSUPPORTEDRttelltseektreadtIOErrort SFTPServert convert_errnoterrnotlen(RtoffsettlengthR tdatate((s/..\python\site-packages\paramiko\sftp_handle.pyRHs    cCst|dd}|dkr"tSy}|jtj@dkr|jdkr\|j|_n||jkr|j|||_qn|j ||j Wn)t k r}d|_t j |jSX|jdk r|jt|7_ntS(s Write C{data} into this file at position C{offset}. Extending the file past its original end is expected. Unlike python's normal C{write()} methods, this method cannot do a partial write: it must write all of C{data} or else return an error. The default implementation checks for an attribute on C{self} named C{writefile}, and if present, performs the write operation on the python file-like object found there. The attribute is named differently from C{readfile} to make it easy to implement read-only (or write-only) files, but if both attributes are present, they should refer to the same file. @param offset: position in the file to start reading from. @type offset: int or long @param data: data to write into the file. @type data: str @return: an SFTP error code like L{SFTP_OK}. R iN(R RRRtostO_APPENDRRRtwritetflushRRRRRtSFTP_OK(RRRR R((s/..\python\site-packages\paramiko\sftp_handle.pyRms$    cCstS(s Return an L{SFTPAttributes} object referring to this open file, or an error code. This is equivalent to L{SFTPServerInterface.stat}, except it's called on an open file instead of a path. @return: an attributes object for the given file, or an SFTP error code (like L{SFTP_PERMISSION_DENIED}). @rtype: L{SFTPAttributes} I{or error code} (R(R((s/..\python\site-packages\paramiko\sftp_handle.pytstats cCstS(s Change the attributes of this file. The C{attr} object will contain only those fields provided by the client in its request, so you should check for the presence of fields before using them. @param attr: the attributes to change on this file. @type attr: L{SFTPAttributes} @return: an error code like L{SFTP_OK}. @rtype: int (R(Rtattr((s/..\python\site-packages\paramiko\sftp_handle.pytchattrs cCs ||_dS(s Used by the SFTP server code to cache a directory listing. (In the SFTP protocol, listing a directory is a multi-stage process requiring a temporary handle.) N(R(Rtfiles((s/..\python\site-packages\paramiko\sftp_handle.pyt _set_filesscCs!|jd }|jd|_|S(s^ Used by the SFTP server code to retreive a cached directory listing. i(R(Rtfnlist((s/..\python\site-packages\paramiko\sftp_handle.pyt_get_next_filess cCs|jS(N(R(R((s/..\python\site-packages\paramiko\sftp_handle.pyt _get_namescCs ||_dS(N(R(Rtname((s/..\python\site-packages\paramiko\sftp_handle.pyt _set_names( t__name__t __module__t__doc__R R RRR R"R$R&R'R)(((s/..\python\site-packages\paramiko\sftp_handle.pyRs   % (   (R(R,Rtparamiko.commont paramiko.sftptobjectRtparamiko.sftp_serverR(((s/..\python\site-packages\paramiko\sftp_handle.pyts