�
=OXc@sbdZddlZddlmZmZddlmZdefd��YZddlm Z dS(s7
Abstraction of an SFTP file handle (for server mode).
i����N(tSFTP_OP_UNSUPPORTEDtSFTP_OK(tClosingContextManagert
SFTPHandlecBskeZdZdd�Zd�Zd�Zd�Zd�Zd�Zd�Z d �Z
d
�Zd�ZRS(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 `stat` or `chattr`.
Instances of this class may be used as context managers.
icCs(||_d|_i|_d|_dS(s
Create a new file handle representing a local file being served over
SFTP. If ``flags`` is passed in, it's used to determine if the file
is open in append mode.
:param int flags: optional flags as passed to `.SFTPServerInterface.open`
N(t_SFTPHandle__flagstNonet_SFTPHandle__namet_SFTPHandle__filest_SFTPHandle__tell(tselftflags((s8/usr/lib/python2.7/site-packages/paramiko/sftp_handle.pyt__init__'s cCsZt|dd�}|dk r+|j�nt|dd�}|dk rV|j�ndS(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 ``self`` named
``readfile`` and/or ``writefile``, and if either or both are present,
their ``close()`` methods are called. This means that if you are
using the default implementations of `read` and `write`, this
method's default implementation should be fine also.
treadfilet writefileN(tgetattrRtclose(R RR
((s8/usr/lib/python2.7/site-packages/paramiko/sftp_handle.pyR5s
cCs�t|dd�}|dkr"tSy\|jdkrF|j�|_n||jkrn|j|�||_n|j|�}Wn)tk
r�}d|_tj |j
�SX|jt|�7_|S(sh
Read up to ``length`` bytes from this file, starting at position
``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 `.SFTP_EOF`.
The default implementation checks for an attribute on ``self`` named
``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 int length: number of bytes to attempt to read.
:return: data read from the file, or an SFTP error code, as a `str`.
RN(RRRRttelltseektreadtIOErrort
SFTPServert
convert_errnoterrnotlen(R toffsettlengthRtdatate((s8/usr/lib/python2.7/site-packages/paramiko/sftp_handle.pyRHs
cCs�t|dd�}|dkr"tSy}|jtj@dkr�|jdkr\|j�|_n||jkr�|j|�||_q�n|j |�|j
�Wn)tk
r�}d|_tj
|j�SX|jdk r�|jt|�7_ntS(s�
Write ``data`` into this file at position ``offset``. Extending the
file past its original end is expected. Unlike Python's normal
``write()`` methods, this method cannot do a partial write: it must
write all of ``data`` or else return an error.
The default implementation checks for an attribute on ``self`` named
``writefile``, and if present, performs the write operation on the
Python file-like object found there. The attribute is named
differently from ``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 str data: data to write into the file.
:return: an SFTP error code like `.SFTP_OK`.
R
iN(RRRRtostO_APPENDRRRtwritetflushRRRRRR(R RRR
R((s8/usr/lib/python2.7/site-packages/paramiko/sftp_handle.pyRks$
cCstS(s�
Return an `.SFTPAttributes` object referring to this open file, or an
error code. This is equivalent to `.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 `.SFTP_PERMISSION_DENIED`).
:rtype: `.SFTPAttributes` or error code
(R(R ((s8/usr/lib/python2.7/site-packages/paramiko/sftp_handle.pytstat�scCstS(se
Change the attributes of this file. The ``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 .SFTPAttributes attr: the attributes to change on this file.
:return: an `int` error code like `.SFTP_OK`.
(R(R tattr((s8/usr/lib/python2.7/site-packages/paramiko/sftp_handle.pytchattr�s 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(R tfiles((s8/usr/lib/python2.7/site-packages/paramiko/sftp_handle.pyt
_set_files�scCs!|jd }|jd|_|S(s^
Used by the SFTP server code to retreive a cached directory
listing.
i(R(R tfnlist((s8/usr/lib/python2.7/site-packages/paramiko/sftp_handle.pyt_get_next_files�s
cCs|jS(N(R(R ((s8/usr/lib/python2.7/site-packages/paramiko/sftp_handle.pyt _get_name�scCs
||_dS(N(R(R tname((s8/usr/lib/python2.7/site-packages/paramiko/sftp_handle.pyt _set_name�s(
t__name__t
__module__t__doc__RRRRR R"R$R&R'R)(((s8/usr/lib/python2.7/site-packages/paramiko/sftp_handle.pyRs
# '
(R(
R,Rt
paramiko.sftpRRt
paramiko.utilRRtparamiko.sftp_serverR(((s8/usr/lib/python2.7/site-packages/paramiko/sftp_handle.pyt<module>s
� |