Repository URL to install this package:
|
Version:
3.3.30 ▾
|
ó
°EYc @ sb d Z d d l Z d d l m Z m Z d d l m Z d e f d YZ d d l m Z d S( s7
Abstraction of an SFTP file handle (for server mode).
iÿÿÿÿN( t SFTP_OP_UNSUPPORTEDt SFTP_OK( t ClosingContextManagert
SFTPHandlec B sk e Z d Z d d Z d Z d Z d Z d Z d Z d Z 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 `stat` or `chattr`.
Instances of this class may be used as context managers.
i c C s( | | _ d | _ i | _ d | _ d S( 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__flagst Nonet _SFTPHandle__namet _SFTPHandle__filest _SFTPHandle__tell( t selft flags( ( sI /home/tvault/.virtenv/lib/python2.7/site-packages/paramiko/sftp_handle.pyt __init__' s c C sZ t | d d } | d k r+ | j n t | d d } | d k rV | j n d S( 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.
t readfilet writefileN( t getattrR t close( R R R
( ( sI /home/tvault/.virtenv/lib/python2.7/site-packages/paramiko/sftp_handle.pyR 6 s
c C sà t | d d } | d k r" t Sy\ | j d k rF | j | _ n | | j k rn | j | | | _ n | j | } Wn) t k
r© } d | _ t j | j
SX| j t | 7_ | S( sG
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.
:param int length: number of bytes to attempt to read.
:return: data read from the file, or an SFTP error code, as a `str`.
R N( R R R R t tellt seekt readt IOErrort
SFTPServert
convert_errnot errnot len( R t offsett lengthR t datat e( ( sI /home/tvault/.virtenv/lib/python2.7/site-packages/paramiko/sftp_handle.pyR I s
c C sö t | d d } | d k r" t Sy} | j t j @d k r | j d k r\ | j | _ n | | j k r | j | | | _ q n | j | | j
Wn) t k
rÊ } d | _ t j
| j SX| j d k rò | j t | 7_ n t S( sk
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.
:param str data: data to write into the file.
:return: an SFTP error code like ``SFTP_OK``.
R
i N( R R R R t ost O_APPENDR R R t writet flushR R R R R R ( R R R R
R ( ( sI /home/tvault/.virtenv/lib/python2.7/site-packages/paramiko/sftp_handle.pyR k s$
c C s t S( 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 ( ( sI /home/tvault/.virtenv/lib/python2.7/site-packages/paramiko/sftp_handle.pyt stat s c C s t S( sf
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 t attr( ( sI /home/tvault/.virtenv/lib/python2.7/site-packages/paramiko/sftp_handle.pyt chattr s c C s
| | _ d S( 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 t files( ( sI /home/tvault/.virtenv/lib/python2.7/site-packages/paramiko/sftp_handle.pyt
_set_files« s c C s! | j d } | j d | _ | S( s^
Used by the SFTP server code to retrieve a cached directory
listing.
i ( R ( R t fnlist( ( sI /home/tvault/.virtenv/lib/python2.7/site-packages/paramiko/sftp_handle.pyt _get_next_files³ s
c C s | j S( N( R ( R ( ( sI /home/tvault/.virtenv/lib/python2.7/site-packages/paramiko/sftp_handle.pyt _get_name¼ s c C s
| | _ d S( N( R ( R t name( ( sI /home/tvault/.virtenv/lib/python2.7/site-packages/paramiko/sftp_handle.pyt _set_name¿ s (
t __name__t
__module__t __doc__R R R R R R" R$ R&