%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_file.cpython-312.pyc

�

�echP���dZddlmZddlmZddlmZddlZddlZddl	Z	ddl
mZddlm
Z
ddlmZmZdd	lmZmZmZmZmZmZmZmZmZmZdd
lmZGd�de
�Zy)
z
SFTP file object
�)�with_statement)�hexlify)�dequeN)�DEBUG)�BufferedFile)�u�long)
�	CMD_CLOSE�CMD_READ�CMD_DATA�	SFTPError�	CMD_WRITE�
CMD_STATUS�	CMD_FSTAT�	CMD_ATTRS�CMD_FSETSTAT�CMD_EXTENDED)�SFTPAttributesc���eZdZdZdZd d�Zd�Zd�Zd!d�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd"d�Zd�Zd�Zd�Zd�Zd�Zd#d�Zd$d�Zd%d�Zd�Zd�Zd�Zd�Zd�Zd�Z y)&�SFTPFilez�
    Proxy object for a file on the remote server, in client mode SFTP.

    Instances of this class may be used as context managers in the same way
    that built-in Python file objects are.
    i�c��tj|�||_||_tj|||�d|_d|_d|_i|_i|_	tj�|_d|_
t�|_y)NF)r�__init__�sftp�handle�	_set_mode�	pipelined�_prefetching�_prefetch_done�_prefetch_data�_prefetch_extents�	threading�Lock�_prefetch_lock�_saved_exceptionr�_reqs)�selfrr�mode�bufsizes     �4/usr/lib/python3/dist-packages/paramiko/sftp_file.pyrzSFTPFile.__init__=sw�����d�#���	�������t�T�7�3����!���#��� ���!#���'�n�n�.��� $����W��
�c�(�|jd��y)NT��async_��_close�r&s r)�__del__zSFTPFile.__del__Ks�����4�� r*c�(�|jd��y)z!
        Close the file.
        Fr,Nr.r0s r)�closezSFTPFile.closeNs��	
���5��!r*c
�B�|jry|jjtdj	tt
|j����|jr|jj|�tj|�	|r5|jjtd�t|j�y|jjt|j�y#t $rYyt"t$j&f$rYywxYw)Nz	close({}))�_closedr�_logr�formatrrrr�_finish_responsesrr3�_async_request�typer
�_request�EOFError�IOError�socket�error)r&r-s  r)r/zSFTPFile._closeTs����<�<���	�	���u�k�0�0��7�4�;�;�3G�1H�I�J��>�>��I�I�'�'��-����4� �	���	�	�(�(��d��Y����L��	�	�"�"�9�d�k�k�:���	������&�	��	�s�6C8�
*C8�8	D�D�Dc�8�t|jj��D�cgc]
}|d|ks�|��}}t|�dk(ry|j	d���|d\}}||z|kry||z||zk\ry|j||z||z|z
|z
�Scc}w)NrFc��|dS�Nr�)�xs r)�<lambda>z5SFTPFile._data_in_prefetch_requests.<locals>.<lambda>vs
��Q�q�T�r*)�key���T)�listr �values�len�sort�_data_in_prefetch_requests)r&�offset�sizerD�k�
buf_offset�buf_sizes       r)rLz#SFTPFile._data_in_prefetch_requestsps����D�2�2�9�9�;�<�
���!����A�
��
��q�6�Q�;��	���>��"� ��u��
�H��� �F�*���� �F�T�M�1���.�.���!�6�D�=�:�#=��#H�
�	
��
s
�
B�Bc���|jj�D�cgc]
}||ks�	|��}}t|�dk(ryt|�}||z
}|t|j|�k\ry|Scc}w)a
        if a block of data is present in the prefetch buffers, at the given
        offset, return the offset of the relevant prefetch buffer.  otherwise,
        return None.  this guarantees nothing about the number of bytes
        collected in the prefetch buffer so far.
        rN)r�keysrJ�max)r&rM�irO�indexrPs      r)�_data_in_prefetch_buffersz"SFTPFile._data_in_prefetch_buffers�sr���+�+�0�0�2�B�1�a�6�k�Q�B��B��q�6�Q�;���A����e�^�
���T�0�0��7�8�8�����
Cs
�
A+�A+c���	|j|j�}|�nD|js|jrn+|jj�|j
��b|�d|_y|j|}|j|=|j|z
}|dkDr|d||j|<||d}|t|�kr$||d|j|j|z<|d|}|S)z�
        read data out of the prefetch buffer, if possible.  if the data isn't
        in the buffer, return None.  otherwise, behaves like a normal read.
        NFr)
rW�_realposrr5r�_read_response�_check_exceptionrrrJ)r&rNrM�prefetchrPs     r)�_read_prefetchzSFTPFile._read_prefetch�s�����3�3�D�M�M�B�F��!���"�"�d�l�l���I�I�$�$�&��!�!�#���>� %�D����&�&�v�.������'��]�]�V�+�
���>�*2�;�J�*?�D����'��
��,�H��#�h�-��8@����D����
�
�� 4�5�����H��r*c�N�t||j�}|jr|j|�}|�|S|jjt|jt|j�t|��\}}|tk7rtd��|j�S)N�
Expected data)�min�MAX_REQUEST_SIZErr]rr;rrr	rY�intrr
�
get_string)r&rN�data�t�msgs     r)�_readzSFTPFile._read�s����4��.�.�/������&�&�t�,�D��������#�#��d�k�k�4��
�
�#6��D�	�
���3�
��=��O�,�,��~�~��r*c	��tt|�|j�}|jj	td�t|jt|j�|d|�}|jj|�|jr<t|j�dkDr�|jjj�rwt|j�rb|jj�}|jj!|�\}}|t"k7rt%d��t|j�r�b|S)N�dzExpected status)r`rJrarr9r:rrr	rYr%�appendr�sock�
recv_ready�popleftrZrr
)r&rd�chunk�sftp_async_request�reqrerfs       r)�_writezSFTPFile._write�s����C��I�t�4�4�5��!�Y�Y�5�5���J���K�K��������%�L�
��	
�
�
���,�-��~�~���
�
�O�c�!�d�i�i�n�n�&?�&?�&A��d�j�j�/��j�j�(�(�*�����1�1�#�6���3��
�?�#�$5�6�6�	�d�j�j�/��r*c�N�|jjj|�y)a@
        Set a timeout on read/write operations on the underlying socket or
        ssh `.Channel`.

        :param float timeout:
            seconds to wait for a pending read/write operation before raising
            ``socket.timeout``, or ``None`` for no timeout

        .. seealso:: `.Channel.settimeout`
        N)rrk�
settimeout)r&�timeouts  r)rszSFTPFile.settimeout�s��	
�	�	���!�!�'�*r*c�J�|jjj�S)z�
        Returns the timeout in seconds (as a `float`) associated with the
        socket or ssh `.Channel` used for this file.

        .. seealso:: `.Channel.gettimeout`
        )rrk�
gettimeoutr0s r)rvzSFTPFile.gettimeout�s���y�y�~�~�(�(�*�*r*c�N�|jjj|�y)z�
        Set blocking or non-blocking mode on the underiying socket or ssh
        `.Channel`.

        :param int blocking:
            0 to set non-blocking mode; non-0 to set blocking mode.

        .. seealso:: `.Channel.setblocking`
        N)rrk�setblocking)r&�blockings  r)rxzSFTPFile.setblocking�s��	
�	�	���"�"�8�,r*c��y)z�
        Check if the file supports random access.

        :return:
            `True` if the file supports random access. If `False`,
            :meth:`seek` will raise an exception
        TrCr0s r)�seekablezSFTPFile.seekable�s��r*c�(�|j�||jk(r|x|_|_nU||jk(r'|xj|z
c_|j|_n|j�|zx|_|_t
�|_y)zX
        Set the file's current position.

        See `file.seek` for details.
        N)�flush�SEEK_SETrY�_pos�SEEK_CUR�	_get_size�bytes�_rbuffer)r&rM�whences   r)�seekz
SFTPFile.seekso��	
�
�
���T�]�]�"�(.�.�D�M�D�I�
�t�}�}�
$��I�I���I� �I�I�D�M�(,���(8�6�(A�A�D�M�D�I����
r*c��|jjt|j�\}}|tk7rtd��t
j|�S)a
        Retrieve information about this file from the remote system.  This is
        exactly like `.SFTPClient.stat`, except that it operates on an
        already-open file.

        :returns:
            an `.SFTPAttributes` object containing attributes about this file.
        zExpected attributes)rr;rrrr
r�	_from_msg)r&rerfs   r)�statz
SFTPFile.statsF�����#�#�I�t�{�{�;���3��	�>��1�2�2��'�'��,�,r*c��|jjtdjt	|j
�|��t
�}||_|jjt|j
|�y)z�
        Change the mode (permissions) of this file.  The permissions are
        unix-style and identical to those used by Python's `os.chmod`
        function.

        :param int mode: new permissions
        zchmod({}, {!r})N)
rr6rr7rrr�st_moder;r)r&r'�attrs   r)�chmodzSFTPFile.chmod s[��	
�	�	����$�+�+�G�D�K�K�,@�$�G�	
��������	�	���<����d�;r*c��|jjtdjt	|j
�||��t
�}||c|_|_|jjt|j
|�y)aV
        Change the owner (``uid``) and group (``gid``) of this file.  As with
        Python's `os.chown` function, you must pass both arguments, so if you
        only want to change one, use `stat` first to retrieve the current
        owner and group.

        :param int uid: new owner's uid
        :param int gid: new group id
        zchown({}, {!r}, {!r})N)rr6rr7rrr�st_uid�st_gidr;r)r&�uid�gidr�s    r)�chownzSFTPFile.chown/sf��	
�	�	����#�*�*�7�4�;�;�+?��c�J�	
����#&�� ���T�[��	�	���<����d�;r*c�f�|�(tj�tj�f}|jjtdj	t|j�|��t�}|\|_|_	|jjt|j|�y)ad
        Set the access and modified times of this file.  If
        ``times`` is ``None``, then the file's access and modified times are
        set to the current time.  Otherwise, ``times`` must be a 2-tuple of
        numbers, of the form ``(atime, mtime)``, which is used to set the
        access and modified times, respectively.  This bizarre API is mimicked
        from Python for the sake of consistency -- I apologize.

        :param tuple times:
            ``None`` or a tuple of (access time, modified time) in standard
            internet epoch time (seconds since 01 January 1970 GMT)
        Nzutime({}, {!r}))�timerr6rr7rrr�st_atime�st_mtimer;r)r&�timesr�s   r)�utimezSFTPFile.utimeAs}���=��Y�Y�[�$�)�)�+�.�E��	�	����$�+�+�G�D�K�K�,@�%�H�	
����',�$��
�t�}��	�	���<����d�;r*c��|jjtdjt	|j
�|��t
�}||_|jjt|j
|�y)z�
        Change the size of this file.  This usually extends
        or shrinks the size of the file, just like the ``truncate()`` method on
        Python file objects.

        :param size: the new size of the file
        ztruncate({}, {!r})N)
rr6rr7rrr�st_sizer;r)r&rNr�s   r)�truncatezSFTPFile.truncateWs[��	
�	�	����'�.�.�w�t�{�{�/C�T�J�	
��������	�	���<����d�;r*c
���|jjtd|j|t	|�t	|�|�\}}|j�|j�|j
�}|S)a
        Ask the server for a hash of a section of this file.  This can be used
        to verify a successful upload or download, or for various rsync-like
        operations.

        The file is hashed from ``offset``, for ``length`` bytes.
        If ``length`` is 0, the remainder of the file is hashed.  Thus, if both
        ``offset`` and ``length`` are zero, the entire file is hashed.

        Normally, ``block_size`` will be 0 (the default), and this method will
        return a byte string representing the requested hash (for example, a
        string of length 16 for MD5, or 20 for SHA-1).  If a non-zero
        ``block_size`` is given, each chunk of the file (from ``offset`` to
        ``offset + length``) of ``block_size`` bytes is computed as a separate
        hash.  The hash results are all concatenated and returned as a single
        string.

        For example, ``check('sha1', 0, 1024, 512)`` will return a string of
        length 40.  The first 20 bytes will be the SHA-1 of the first 512 bytes
        of the file, and the last 20 bytes will be the SHA-1 of the next 512
        bytes.

        :param str hash_algorithm:
            the name of the hash algorithm to use (normally ``"sha1"`` or
            ``"md5"``)
        :param offset:
            offset into the file to begin hashing (0 means to start from the
            beginning)
        :param length:
            number of bytes to hash (0 means continue to the end of the file)
        :param int block_size:
            number of bytes to hash per result (must not be less than 256; 0
            means to compute only one hash of the entire segment)
        :return:
            `str` of bytes representing the hash of each block, concatenated
            together

        :raises:
            ``IOError`` -- if the server doesn't support the "check-file"
            extension, or possibly doesn't support the hash algorithm requested

        .. note:: Many (most?) servers don't support this extension yet.

        .. versionadded:: 1.4
        z
check-file)rr;rrr	�get_text�
get_remainder)r&�hash_algorithmrM�length�
block_sizererfrds        r)�checkzSFTPFile.checkfse��\���#�#����K�K����L���L��
���3�	��������� � �"���r*c��||_y)a�
        Turn on/off the pipelining of write operations to this file.  When
        pipelining is on, paramiko won't wait for the server response after
        each write operation.  Instead, they're collected as they come in. At
        the first non-write operation (including `.close`), all remaining
        server responses are collected.  This means that if there was an error
        with one of your later writes, an exception might be thrown from within
        `.close` instead of `.write`.

        By default, files are not pipelined.

        :param bool pipelined:
            ``True`` if pipelining should be turned on for this file; ``False``
            otherwise

        .. versionadded:: 1.5
        N)r)r&rs  r)�
set_pipelinedzSFTPFile.set_pipelined�s��$#��r*Nc��|�|j�j}g}|j}||kr7t|j||z
�}|j||f�||z
}||kr�7t
|�dkDr|j|�yy)a
        Pre-fetch the remaining contents of this file in anticipation of future
        `.read` calls.  If reading the entire file, pre-fetching can
        dramatically improve the download speed by avoiding roundtrip latency.
        The file's contents are incrementally buffered in a background thread.

        The prefetched data is stored in a buffer until read via the `.read`
        method.  Once data has been read, it's removed from the buffer.  The
        data may be read in a random order (using `.seek`); chunks of the
        buffer that haven't been read will continue to be buffered.

        :param int file_size:
            When this is ``None`` (the default), this method calls `stat` to
            determine the remote file size. In some situations, doing so can
            cause exceptions or hangs (see `#562
            <https://github.com/paramiko/paramiko/pull/562>`_); as a
            workaround, one may call `stat` explicitly and pass its value in
            via this parameter.

        .. versionadded:: 1.5.1
        .. versionchanged:: 1.16.0
            The ``file_size`` parameter was added (with no default value).
        .. versionchanged:: 1.16.1
            The ``file_size`` parameter was made optional for backwards
            compatibility.
        Nr)r�r�rYr`rarjrJ�_start_prefetch)r&�	file_size�chunks�nrns     r)r\zSFTPFile.prefetch�s���6���	�	��+�+�I����M�M���)�m���-�-�y�1�}�=�E��M�M�1�e�*�%�
��J�A��)�m��v�;��?�� � ��(�r*c#��K�|jjtdjt	|j
�|��g}|D]h\}}|j
|�s|j||�r�*|dkDs�0t||j�}|j||f�||z
}||z}|dkDr�9�j|j|�|D],}|j|d�|j|d����.y�w)a�
        Read a set of blocks from the file by (offset, length).  This is more
        efficient than doing a series of `.seek` and `.read` calls, since the
        prefetch machinery is used to retrieve all the requested blocks at
        once.

        :param chunks:
            a list of ``(offset, length)`` tuples indicating which sections of
            the file to read
        :return: a list of blocks read, in the same order as in ``chunks``

        .. versionadded:: 1.5.4
        zreadv({}, {!r})r�N)rr6rr7rrrWrLr`rarjr�r��read)r&r��read_chunksrMrN�
chunk_sizerDs       r)�readvzSFTPFile.readv�s�����	
�	�	����$�+�+�G�D�K�K�,@�&�I�	
���"�	#�L�F�D��-�-����0�0���>����(� ��t�'<�'<�=�
��"�"�F�J�#7�8��*�$���
�"��	��(�	#�	
���[�)��	"�A��I�I�a��d�O��)�)�A�a�D�/�!�	"�s�A7C8�:8C8�3AC8c�F�	|j�jS#YyxYwrB)r�r�r0s r)r�zSFTPFile._get_sizes#��	��9�9�;�&�&�&��	��s�� c��d|_d|_tj|j|f��}d|_|j
�y)NTF)�target�args)rrr!�Thread�_prefetch_thread�daemon�start)r&r�res   r)r�zSFTPFile._start_prefetch
s<�� ���#������D�$9�$9��	�J�����	���	r*c
��|D]j\}}|jj|t|jt	|�t|��}|j5||f|j|<ddd��ly#1swY�wxYw�N)rr9rrr	rbr#r )r&r�rMr��nums     r)r�zSFTPFile._prefetch_threads|��%�	?�N�F�F��)�)�*�*��h����T�&�\�3�v�;��C��$�$�
?�/5�v�.>��&�&�s�+�
?�
?�		?�
?�
?�s�A1�1A:	c���|tk(r	|jj|�y|t
k7rt
d��|j�}	|j5||jvrW|j|\}}||j|<|j|=t|j�dk(rd|_	ddd�y	ddd��|#t$r}||_Yd}~yd}~wwxYw#1swY�'xYw)Nr_Tr)
rr�_convert_status�	Exceptionr$rr
rcr#r rrJr)r&rerfr��erdrMr�s        r)�_async_responsezSFTPFile._async_responses����
�?�
*��	�	�)�)�#�.�
���=��O�,�,��~�~�����$�$�
��$�0�0�0�%)�%;�%;�C�%@�N�F�F�26�D�'�'��/��.�.�s�3��4�1�1�2�a�7�.2��+��
�
�0�
���
�
*�()��%�%���
*��
�
�s$�C�AC%�	C"�C�C"�%C.c�F�|j�|j}d|_|�y)z.if there's a saved exception, raise & clear itN)r$)r&rDs  r)r[zSFTPFile._check_exception5s+��� � �,��%�%�A�$(�D�!��G�-r*)�rrG)F)r)rrr)Tr�)!�__name__�
__module__�__qualname__�__doc__rarr1r3r/rLrWr]rgrqrsrvrxr{r�r�r�r�r�r�r�r�r\r�r�r�r�r�r[rCr*r)rr1s�������!�"��8
�(�"�< ��,+�+�
-�� � -�
<�<�$<�,
<�:�x#�(&)�P%"�R��?��,r*r)r��
__future__r�binasciir�collectionsrr>r!r��paramiko.commonr�
paramiko.filer�paramiko.py3compatrr	�
paramiko.sftpr
rrr
rrrrrr�paramiko.sftp_attrrrrCr*r)�<module>r�sI��&�&���
���!�&�&����.�I�|�Ir*

Zerion Mini Shell 1.0