File: //usr/local/CyberCP/lib64/python3.10/site-packages/paramiko/__pycache__/sftp_handle.cpython-310.pyc
o
�h � @ sH d Z ddlZddlmZmZ ddlmZ G dd� de�Zddlm Z dS )z7
Abstraction of an SFTP file handle (for server mode).
� N)�SFTP_OP_UNSUPPORTED�SFTP_OK)�ClosingContextManagerc @ sb e Zd ZdZddd�Zdd� Zdd� Zd d
� Zdd� Zd
d� Z dd� Z
dd� Zdd� Zdd� Z
dS )�
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.
r c C s || _ d| _i | _d| _dS )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�flags� r �G/usr/local/CyberCP/lib/python3.10/site-packages/paramiko/sftp_handle.py�__init__( s
zSFTPHandle.__init__c C s@ t | dd�}|dur|�� t | dd�}|dur|�� dS dS )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
r r r r r
r 7 s �zSFTPHandle.closec
C s� t | dd�}|du rtS z| jdu r|�� | _|| jkr$|�|� || _|�|�}W n tyE } zd| _t�|j �W Y d}~S d}~ww | jt
|�7 _|S )a5
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: the `bytes` read, or an error code `int`.
r N)r r r �tell�seek�read�IOError�
SFTPServer�
convert_errno�errno�len)r
�offset�lengthr �data�er r r
r J s"