HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/filebuffer.cpython-310.pyc
o

�N�g��@sBdZddlZddlZddlmZGdd�de�ZGdd�d�ZdS)z�
    :codeauthor: Pedro Algarvio (pedro@algarvio.me)


    salt.utils.filebuffer
    ~~~~~~~~~~~~~~~~~~~~~

    This utility allows parsing a file in chunks.
�N)�
SaltExceptionc@seZdZdZdS)�InvalidFileModezM
    An invalid file mode was used to open the file passed to the buffer
    N)�__name__�
__module__�__qualname__�__doc__�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/filebuffer.pyrsrc@sJeZdZdZddd�Zedd��Zd	d
�Zdd�ZeZ	d
d�Z
dd�ZdS)�BufferedReadera�
    This object allows iterating through the contents of a file keeping
    X configurable bytes in memory which can be used to, for example,
    do regex search/matching on more than a single line.

    So, **an imaginary, non accurate**, example could be:

        1 - Initiate the BufferedReader filling it to max_in_men:
            br = [1, 2, 3]

        2 - next chunk(pop chunk_size from the left, append chunk_size to the
        right):
            br = [2, 3, 4]


    :type  path: str
    :param path: The file path to be read

    :type  max_in_mem: int
    :param max_in_mem: The maximum bytes kept in memory while iterating through
                       the file. Default 256KB.

    :type  chunk_size: int
    :param chunk_size: The size of each consequent read chunk. Default 32KB.

    :type  mode: str
    :param mode: The mode the file should be opened. **Only read modes**.

    ����rcCsHd|vsd|vrtd��||_tjj�|j|�|_||_||_d|_	dS)N�a�wz(Cannot open file in write or append mode)
rZ_BufferedReader__path�salt�utils�filesZfopen�_BufferedReader__file�_BufferedReader__max_in_mem�_BufferedReader__chunk_size�_BufferedReader__buffered)�self�pathZ
max_in_memZ
chunk_size�moderrr	�__init__5s
zBufferedReader.__init__cCs|jS�N)r�rrrr	�bufferedAszBufferedReader.bufferedcC�|Srrrrrr	�__iter__F�zBufferedReader.__iter__cCsz|jdur|j|j}d|_nd}|j|jd�|_|j�|j|�}tjj�|�}|s3|j�	�t
�|j|7_|jS)z�
        Return the next iteration by popping `chunk_size` from the left and
        appending `chunk_size` to the right if there's info on the file left
        to be read.
        N��)rrrr�readrrZstringutilsZto_str�close�
StopIteration)rZ
multiplier�datarrr	�nextIs

zBufferedReader.nextcCrrrrrrr	�	__enter__hr zBufferedReader.__enter__cCs|jjdur
|j��dSdS)NF)r�closedr$)r�exc_type�	exc_value�	tracebackrrr	�__exit__ks�zBufferedReader.__exit__N)rrr
)rrrrr�propertyrrr'�__next__r(r-rrrr	r
s

r
)rZsalt.utils.filesrZsalt.utils.stringutilsZsalt.exceptionsrrr
rrrr	�<module>s