HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/mercurial/revlogutils/__pycache__/randomaccessfile.cpython-310.pyc
o

�]LbA�@sLddlZddlmZddlmZmZdZed�Zdd�ZGd	d
�d
e	�Z
dS)�N�)�_)�error�utilisCpartial read of revlog %s; expected %d bytes from offset %d, got %dcCs||d@dko|dkS)N�r�)�nrr�H/usr/lib/python3/dist-packages/mercurial/revlogutils/randomaccessfile.py�_is_power_of_twosr
c@sheZdZdZ	ddd�Zdd�Zddd	�Zejdd
d��Z	ejdd
��Z
ddd�Zddd�Zdd�Z
dS)�randomaccessfilezDAccessing arbitrary chuncks of data within a file, with some cachingNcCsNt|�sJ�||_||_||_d|_d|_d|_d|_|r%|\|_|_dSdS�N�r)r
�opener�filename�default_cached_chunk_size�writing_handle�reading_handle�
_cached_chunk�_cached_chunk_position)�selfrrr�
initial_cacherrr	�__init__s�zrandomaccessfile.__init__cCsd|_d|_dSr)rr)rrrr	�clear_cache1s
zrandomaccessfile.clear_cache�rcCs|j|j|d�S)zReturn a file object)�mode)rr)rrrrr	�_open5szrandomaccessfile._openccsl�|dur
|VdS|jr|jVdS|jr|jVdS|���}|VWd�dS1s/wYdS)z%File object suitable for reading dataN)rrr)r�existing_file_obj�fprrr	�
_open_read9s�

"�zrandomaccessfile._open_readc	csx�|jdur7|jdur7|jdur7|���}||_zdVWd|_nd|_wWd�dS1s0wYdSdVdS)z4Context manager that keeps the file open for readingN)rrrr)rrrrr	�readingOs�



"�
zrandomaccessfile.readingcCsh||}|j}|t|j�}||kr-||kr-||kr!||kr!|jS||}t�|j||�S|�|||�S)a�Read a chunk of bytes from the file.

        Accepts an absolute offset, length to read, and an optional existing
        file handle to read from.

        If an existing file handle is passed, it will be seeked and the
        original seek position will NOT be restored.

        Returns a str or buffer of raw byte data.

        Raises if the requested number of bytes could not be read.
        )r�lenrr�buffer�_read_and_update_cache)r�offset�lengthr�end�cache_start�	cache_end�relative_startrrr	�
read_chunk`s
zrandomaccessfile.read_chunkcCs�||jd@}|||j|jd@|}|�|��}|�|�|�|�}Wd�n1s1wY|�||�||}t|�|}	|	|krXt|j|||	f}
t�	|
��||ks`||krgt
�|||�S|S)Nr)rr�seek�read�_add_cached_chunkr �PARTIAL_READ_MSGrr�RevlogErrorrr!)rr#r$r�real_offset�real_length�file_obj�data�relative_offset�got�messagerrr	r"ys&
��
�
z'randomaccessfile._read_and_update_cachecCsL|jt|j�|krt|j�t|�tkr|j|7_dS||_||_dS)z|Add to or replace the cached data chunk.

        Accepts an absolute offset and the data that is at that location.
        N)rr r�_MAX_CACHED_CHUNK_SIZE)rr#r2rrr	r,�s

z"randomaccessfile._add_cached_chunk)N)r)�__name__�
__module__�__qualname__�__doc__rrr�
contextlib�contextmanagerrrr)r"r,rrrr	rs
�



r)r;�i18nr�rrr6r-r
�objectrrrrr	�<module>s�