HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberPanel/lib64/python3.10/site-packages/paramiko/__pycache__/file.cpython-310.pyc
o

�hwJ�@sLddlmZddlmZmZmZmZmZddlm	Z	m
Z
Gdd�de	�ZdS)�)�BytesIO)�linefeed_byte_value�crlf�cr_byte�
linefeed_byte�
cr_byte_value)�ClosingContextManager�uc@seZdZdZdZdZdZdZdZdZ	dZ
dZdZd	Z
d
Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd@d d!�Zd@d"d#�Zd@d$d%�ZdAd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Z e!d0d1��Z"d2d3�Z#d4d5�Z$d6d7�Z%dBd:d;�Z&d<d=�Z'd>d?�Z(dS)C�BufferedFilezc
    Reusable base class to implement Python-style file buffering around a
    simpler stream.
    i r����� �@�cCsFd|_d|_|j|_t�|_t�|_d|_d|_	d|_
|_d|_dS)NrF)
�newlines�_flags�_DEFAULT_BUFSIZE�_bufsizer�_wbuffer�bytes�_rbuffer�_at_trailing_cr�_closed�_pos�_realpos�_size��self�r �C/usr/local/CyberPanel/lib/python3.10/site-packages/paramiko/file.py�__init__3s
zBufferedFile.__init__cCs|��dS�N)�closerr r r!�__del__BszBufferedFile.__del__cCs|jrtd��|S)z�
        Returns an iterator that can be used to iterate over the lines in this
        file.  This iterator happens to return the file itself, since a file is
        its own iterator.

        :raises: ``ValueError`` -- if the file is closed.
        zI/O operation on closed file)r�
ValueErrorrr r r!�__iter__EszBufferedFile.__iter__cCs|��d|_dS)zN
        Close the file.  Future read and write operations will fail.
        TN)�flushrrr r r!r$Qs
zBufferedFile.closecCs|�|j���t�|_dS)z{
        Write out any data in the write buffer.  This may do nothing if write
        buffering is not turned on.
        N)�
_write_allr�getvaluerrr r r!r(XszBufferedFile.flushcCs|��}|st�|S)a�
        Returns the next line from the input, or raises ``StopIteration``
        when EOF is hit.  Unlike python file objects, it's okay to mix
        calls to `.next` and `.readline`.

        :raises: ``StopIteration`` -- when the end of the file is reached.

        :returns:
            a line (`str`, or `bytes` if the file was opened in binary mode)
            read from the file.
        )�readline�
StopIteration)r�liner r r!�__next__aszBufferedFile.__next__cC�|j|j@|jkS)z�
        Check if the file can be read from.

        :returns:
            `True` if the file can be read from. If `False`, `read` will raise
            an exception.
        )r�	FLAG_READrr r r!�readabler�zBufferedFile.readablecCr/)z�
        Check if the file can be written to.

        :returns:
            `True` if the file can be written to. If `False`, `write` will
            raise an exception.
        )r�
FLAG_WRITErr r r!�writable|r2zBufferedFile.writablecC�dS)z�
        Check if the file supports random access.

        :returns:
            `True` if the file supports random access. If `False`, `seek` will
            raise an exception.
        Fr rr r r!�seekable�szBufferedFile.seekablecCs&|�t|��}||dt|��<t|�S)z�
        Read up to ``len(buff)`` bytes into ``bytearray`` *buff* and return the
        number of bytes read.

        :returns:
            The number of bytes read.
        N)�read�len)r�buff�datar r r!�readinto�szBufferedFile.readintoNcCs�|jrtd��|j|j@std��|dus|dkrgt|j�}t�|_|jt|�7_	z|�	|j
�}Wnty?d}Ynw|dusJt|�dkrO	t|�S|�|�|j
t|�7_
|jt|�7_q,|t|j�kr�|jd|�}|j|d�|_|jt|�7_|St|j�|kr�|t|j�}|j|j@r�t|j|�}z|�	|�}Wnty�d}Ynw|dus�t|�dkr�n|j|7_|j
t|�7_
t|j�|ks�|jd|�}|j|d�|_|jt|�7_|S)a�
        Read at most ``size`` bytes from the file (less if we hit the end of
        the file first).  If the ``size`` argument is negative or omitted,
        read all the remaining data in the file.

        .. note::
            ``'b'`` mode flag is ignored (``self.FLAG_BINARY`` in
            ``self._flags``), because SSH treats all files as binary, since we
            have no idea what encoding the file is in, or even if the file is
            text data.

        :param int size: maximum number of bytes to read
        :returns:
            data read from the file (as bytes), or an empty string if EOF was
            encountered immediately
        �File is closedzFile is not open for readingNr)r�IOErrorrr0�	bytearrayrrrr8�_readr�EOFError�extendr�
FLAG_BUFFERED�maxr)r�size�result�new_data�	read_sizer r r!r7�sX
�
����zBufferedFile.readc
Cs�|jrtd��|j|j@std��|j}d}	|jr@|j|j@r@t|�dkr@|dtkr8|dd�}|�	t
�n|�	t�d|_|dure|dkret|�|kr^||d�|_|d|�}d}n]|t|�}n|j}t
|vsv|j|j@rwt|vrwnDz|�|�}Wnty�d}Ynw|dus�t|�dkr�t�|_|jt|�7_|j|j@r�|St|�S||7}|jt|�7_q|�t
�}|j|j@r�|�t�}|dkr�||ks�|dkr�|}|dkr�|jt|�7_|j|j@r�|St|�S|d}||tk�r|t|�k�r||tk�r|d7}|�r||d�|j|_n||d�|_|||�}	|d|�t
}t|j�dk�rC|	tk�rCd|_n|�	|	�|jt|�7_|j|j@�rZ|St|�S)	a�
        Read one entire line from the file.  A trailing newline character is
        kept in the string (but may be absent when a file ends with an
        incomplete line).  If the size argument is present and non-negative, it
        is a maximum byte count (including the trailing newline) and an
        incomplete line may be returned.  An empty string is returned only when
        EOF is encountered immediately.

        .. note::
            Unlike stdio's ``fgets``, the returned string contains null
            characters (``'\0'``) if they occurred in the input.

        :param int size: maximum length of returned string.
        :returns:
            next line of the file, or an empty string if the end of the
            file has been reached.

            If the file was opened in binary (``'b'``) mode: bytes are returned
            Else: the encoding of the file is assumed to be UTF-8 and character
            strings (`str`) are returned
        r<zFile not open for readingFTrrN���)rr=rr0rr�FLAG_UNIVERSAL_NEWLINEr8r�_record_newlinerrrrr?r@rr�FLAG_BINARYr	r�findr)
rrDr-�	truncated�nrF�pos�rpos�xpos�lfr r r!r+�s��
�

���
)

zBufferedFile.readlinecCsRg}d}	|��}t|�dkr	|S|�|�|t|�7}|dur(||kr(	|Sq)a�
        Read all remaining lines using `readline` and return them as a list.
        If the optional ``sizehint`` argument is present, instead of reading up
        to EOF, whole lines totalling approximately sizehint bytes (possibly
        after rounding up to an internal buffer size) are read.

        :param int sizehint: desired maximum number of bytes to read.
        :returns: list of lines read from the file.
        rTN)r+r8�append)r�sizehint�lines�
byte_countr-r r r!�	readlines@s

��zBufferedFile.readlinescC�td��)a�
        Set the file's current position, like stdio's ``fseek``.  Not all file
        objects support seeking.

        .. note::
            If a file is opened in append mode (``'a'`` or ``'a+'``), any seek
            operations will be undone at the next write (as the file position
            will move back to the end of the file).

        :param int offset:
            position to move to within the file, relative to ``whence``.
        :param int whence:
            type of movement: 0 = absolute; 1 = relative to the current
            position; 2 = relative to the end of the file.

        :raises: ``IOError`` -- if the file doesn't support random access.
        zFile does not support seeking.�r=)r�offset�whencer r r!�seekVszBufferedFile.seekcC�|jS)z�
        Return the file's current position.  This may not be accurate or
        useful if the underlying file doesn't support random access, or was
        opened in append mode.

        :returns: file position (`number <int>` of bytes).
        )rrr r r!�telljszBufferedFile.tellcCs�t|t�r
|�d�}|jrtd��|j|j@std��|j|j@s(|�|�dS|j	�
|�|j|j@ri|�t
�}|dkrg|j	��}|t|�t|�7}|�|d|d��t�|_	|j	�
||dd��dS|j	��|jkru|��dS)a8
        Write data to the file.  If write buffering is on (``bufsize`` was
        specified and non-zero), some or all of the data may not actually be
        written yet.  (Use `flush` or `close` to force buffered data to be
        written out.)

        :param data: ``str``/``bytes`` data to write
        zutf-8r<zFile not open for writingNrr)�
isinstance�str�encoderr=rr3rBr)r�write�FLAG_LINE_BUFFERED�rfindrr*r8rr^rr()rr:�last_newline_pos�wbufr r r!rbts,
	



zBufferedFile.writecCs|D]}|�|�qdS)a?
        Write a sequence of strings to the file.  The sequence can be any
        iterable object producing strings, typically a list of strings.  (The
        name is intended to match `readlines`; `writelines` does not add line
        separators.)

        :param sequence: an iterable sequence of strings.
        N)rb)r�sequencer-r r r!�
writelines�s	zBufferedFile.writelinescCs|S)z
        Identical to ``iter(f)``.  This is a deprecated file interface that
        predates Python iterator support.
        r rr r r!�
xreadlines�szBufferedFile.xreadlinescCr]r#)rrr r r!�closed�szBufferedFile.closedcCst��)z�
        (subclass override)
        Read data from the stream.  Return ``None`` or raise ``EOFError`` to
        indicate EOF.
        )r@)rrDr r r!r?�szBufferedFile._readcCrX)zI
        (subclass override)
        Write data into the stream.
        zwrite not implementedrY)rr:r r r!�_write�szBufferedFile._writecCr5)ai
        (subclass override)
        Return the size of the file.  This is called from within `_set_mode`
        if the file is opened in append mode, so the file position can be
        tracked and `seek` and `tell` will work correctly.  If the file is
        a stream that can't be randomly accessed, you don't need to override
        this method,
        rr rr r r!�	_get_size�s	zBufferedFile._get_size�rrHcCs:|j|_|dkr
d}|dkr|j|j|jBO_n)|dkr3||_|j|jO_|j|jM_n|dkrC|j|j|jBM_d|vsKd|vrS|j|jO_d|vs[d|vrc|j|jO_d|vr~|j|j|jBO_|��|_	|j	|_
|_d|vr�|j|jO_d|vr�|j|j
O_d	|_d	Sd	S)
zM
        Subclasses call this method to initialize the BufferedFile.
        rrrm�+�w�a�b�UN)rrrrBrcr0r3�FLAG_APPENDrlrrrrKrIr)r�mode�bufsizer r r!�	_set_mode�s2

�zBufferedFile._set_modecCs�t|�}t|�dkr>|�|�}||d�}|j|j@r*|j|7_|j|_|_n|j|7_|j|7_t|�dks
dS)Nr)�
memoryviewr8rkrrsrrr)r�raw_datar:�countr r r!r)�s
�	zBufferedFile._write_allcCsl|j|j@sdS|jdur||_dS|j|kr%t|jt�r%|j|f|_dS||jvr4|j|f7_dSdSr#)rrIrr_r)r�newliner r r!rJs


�zBufferedFile._record_newliner#)r)rmrH))�__name__�
__module__�__qualname__�__doc__r�SEEK_SET�SEEK_CUR�SEEK_ENDr0r3rsrKrBrcrIr"r%r'r$r(r.r1r4r6r;r7r+rWr\r^rbrhri�propertyrjr?rkrlrvr)rJr r r r!r
sN	




;
i

$



(r
N)�ior�paramiko.commonrrrrr�
paramiko.utilrr	r
r r r r!�<module>s