%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/paramiko/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/paramiko/__pycache__/sftp_handle.cpython-312.pyc

�

�ec��N�dZddlZddlmZmZddlmZGd�de�Zddlm	Z	y)z7
Abstraction of an SFTP file handle (for server mode).
�N)�SFTP_OP_UNSUPPORTED�SFTP_OK)�ClosingContextManagerc�N�eZdZdZd
d�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)�
SFTPHandlea�
    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.
    c�<�||_d|_i|_d|_y)a"
        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)�_SFTPHandle__flags�_SFTPHandle__name�_SFTPHandle__files�_SFTPHandle__tell)�self�flagss  �6/usr/lib/python3/dist-packages/paramiko/sftp_handle.py�__init__zSFTPHandle.__init__(s ��������������c��t|dd�}|�|j�t|dd�}|�|j�yy)a
        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.
        �readfileN�	writefile)�getattr�close)r
rrs   rrzSFTPHandle.close7sE���4��T�2�����N�N���D�+�t�4�	�� ��O�O��!rc��t|dd�}|�tS	|j�|j�|_||jk7r|j	|�||_|j|�}|xjt|�z
c_|S#t$r0}d|_tj|j�cYd}~Sd}~wwxYw)aG
        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`.
        rN)rrr�tell�seek�read�IOError�
SFTPServer�
convert_errno�errno�len)r
�offset�lengthr�data�es      rrzSFTPHandle.readJs���$�4��T�2����&�&�		5��{�{�"�&�m�m�o�������$��
�
�f�%�$����=�=��(�D�	
���s�4�y� �����	�	5��D�K��+�+�A�G�G�4�4��	5�s�AB�	C	�%C�>C	�C	c��t|dd�}|�tS	|jtjzdk(rH|j
�|j
�|_||j
k7r|j|�||_|j|�|j�|j
�|xj
t|�z
c_tS#t$r0}d|_tj|j�cYd}~Sd}~wwxYw)ak
        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``.
        rNr)rrr	�os�O_APPENDrrr�write�flushrrrrrr)r
r r"rr#s     rr'zSFTPHandle.writels���$�D�+�t�4�	���&�&�	5����r�{�{�*�q�0��;�;�&�"+�.�.�"2�D�K��T�[�[�(��N�N�6�*�"(�D�K��O�O�D�!��O�O���;�;�"��K�K�3�t�9�$�K�����	5��D�K��+�+�A�G�G�4�4��	5�s�B	C�	D	�%D�>D	�D	c��tS)a�
        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
s r�statzSFTPHandle.stat�s
��#�"rc��tS)af
        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
�attrs  r�chattrzSFTPHandle.chattr�s
��#�"rc��||_y)z�
        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
�filess  r�
_set_fileszSFTPHandle._set_files�s����rc�L�|jdd}|jdd|_|S)z^
        Used by the SFTP server code to retrieve a cached directory
        listing.
        N�r1)r
�fnlists  r�_get_next_fileszSFTPHandle._get_next_files�s+��
���c�r�"���|�|�B�C�(����
rc��|jS�N�r
r+s r�	_get_namezSFTPHandle._get_name�s���{�{�rc��||_yr9r:)r
�names  r�	_set_namezSFTPHandle._set_name�s	����rN)r)�__name__�
__module__�__qualname__�__doc__rrrr'r,r/r3r7r;r>�rrrrs;��	�
��& �D$�L#�	#����rr)r)
rBr%�
paramiko.sftprr�
paramiko.utilrr�paramiko.sftp_serverrrCrr�<module>rGs*��&�
�6�/�e�&�e�P,r

Zerion Mini Shell 1.0