HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/gitdb/__pycache__/stream.cpython-310.pyc
o

;j�k�@s.ddlmZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZddlm
Z
mZmZmZmZddlmZmZddlmZdZz
ddlmZd	ZWn	eyUYnwd
ZGdd�de�ZGd
d�de�ZGdd�d�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"Gdd�d�Z#Gdd�d�Z$dS)�)�BytesION)�msb_size�stream_copy�apply_delta_data�connect_deltas�delta_types)�allocate_memory�	LazyMixin�make_sha�write�close)�	NULL_BYTE�
BYTE_SPACE)�force_bytesF)�apply_deltaT)	�DecompressMemMapReader�FDCompressedSha1Writer�DeltaApplyReader�
Sha1Writer�FlexibleSha1Writer�ZippedStoreShaWriterr�FDStream�
NullStreamc@s~eZdZdZdZdZddd�Zdd�Zd	d
�Zdd�Z	e
ddd��Zdd�Zdd�Z
dd�Zeedd�fdd�Zddd�ZdS) ra�Reads data in chunks from a memory map and decompresses it. The client sees
    only the uncompressed data, respective file-like read calls are handling on-demand
    buffered decompression accordingly

    A constraint on the total size of bytes is activated, simulating
    a logical file within a possibly larger physical memory area

    To read efficiently, you clearly don't want to read individual bytes, instead,
    read a few kilobytes at least.

    **Note:** The chunk-size should be carefully selected as it will involve quite a bit
        of string copying due to the way the zlib is implemented. Its very wasteful,
        hence we try to find a good tradeoff between allocation time and number of
        times we actually allocate. An own zlib implementation would be good here
        to better support streamed reading - it would only need to keep the mmap
        and decompress it into chunks, that's all ... )�_m�_zip�_buf�_buflen�_br�_cws�_cwe�_s�_close�_cbr�_phiiNcCsR||_t��|_d|_d|_|dur||_d|_d|_d|_	d|_
d|_||_dS)z|Initialize with mmap for stream reading
        :param m: must be content data - use new if you have object data and no sizeNrF)
r�zlib�
decompressobjrrrr rrrr"r#r!)�self�m�close_on_deletion�size�r*�@/opt/saltstack/salt/lib/python3.10/site-packages/gitdb/stream.py�__init__Es

zDecompressMemMapReader.__init__cCs|dksJ�|��dS)Nr )�_parse_header_info�r&�attrr*r*r+�_set_cache_Usz"DecompressMemMapReader._set_cache_cCs|��dS�N)r�r&r*r*r+�__del__[�zDecompressMemMapReader.__del__cCs~d}||_|�|�}|�t�}|d|��t�\}}t|�}||_d|_|d7}t||d��|_	t
|�||_d|_||fS)z�If this stream contains object data, parse the header info and skip the
        stream to a point where each read will yield object content

        :return: parsed type_string, sizei Nr�T)
r �read�findr
�splitr�intrrr�lenrr#)r&Zmaxb�hdrZhdrend�typr)r*r*r+r-^s

z)DecompressMemMapReader._parse_header_infoFcCs"t||d�}|��\}}|||fS)a�Create a new DecompressMemMapReader instance for acting as a read-only stream
        This method parses the object header from m and returns the parsed
        type and size, as well as the created stream instance.

        :param m: memory map on which to operate. It must be object data ( header + contents )
        :param close_on_deletion: if True, the memory map will be closed once we are
            being deletedr)rr-)r&r'r(�instr<r)r*r*r+�new{s	
zDecompressMemMapReader.newcC�|jS)z8:return: random access compatible data we are working on)rr2r*r*r+�data�szDecompressMemMapReader.datacCs*|jrt|jd�r|j��d|_dSdS)z�Close our underlying stream of compressed bytes if this was allowed during initialization
        :return: True if we closed the underlying stream
        :note: can be called safely
        rFN)r!�hasattrrrr2r*r*r+r�s


�zDecompressMemMapReader.closecCs�|j|jkrJ|jjsJd|_t|jd�r(|jjtjkr'|�t	j
�|jjtjksn|jjsF|jt|j
�krF|�t	j
�|jjsF|jt|j
�ks4|j|_|jS)z�
        :return: number of compressed bytes read. This includes the bytes it
            took to decompress the header ( if there was one )r�status)rr r�unused_datarArBr$ZZ_OKr6�mmap�PAGESIZEr"r:rr2r*r*r+�compressed_bytes_read�s���z,DecompressMemMapReader.compressed_bytes_read�SEEK_SETrcCsZ|dks|ttdd�krtd��t��|_d|_|_|_|_	|j
r+d|_
|`dSdS)zgAllows to reset the stream to restart reading
        :raise ValueError: If offset and whence are not 0rrG�Can only seek to position 0FN)�getattr�os�
ValueErrorr$r%rrrrr"r#r �r&�offset�whencer*r*r+�seek�s
�zDecompressMemMapReader.seek���cCs�|dkr|j|j}n	t||j|j�}|dkrdSd}|jrR|j|kr:|j�|�}|j|8_|j|7_|S|j��}||j8}|j|j7_d|_d|_|jj}|rg|jt	|�|_
|j
||_n|j
}|j|_
|||_|j|j
dkr�|j
d|_|j|j
|j�}|j
t	|�|_|j�||�}t
tdtj�dvr�tjdks�t	|jj�}nt	|jj�t	|jj�}|jt	|�|7_|jt	|�7_|r�||}|r�t	|�t	|�|kr�|j|jkr�||�|t	|��7}|S)Nr5r���ZLIB_RUNTIME_VERSION)z1.2.7z1.2.5�darwin)r r�minrrr6r�unconsumed_tailrr:rr�
decompressrIr$�ZLIB_VERSION�sys�platformrCr")r&r)Zdat�tailZcwsZindataZdcompdatZunused_datalenr*r*r+r6�sN



$	zDecompressMemMapReader.readr1�F)rP)�__name__�
__module__�__qualname__�__doc__�	__slots__Z
max_read_sizer,r0r3r-�classmethodr>r@rrFrIrJrOr6r*r*r*r+r.s
1rc@s�eZdZdZdZdZdd�Zdd�Zdd	�Ze	seZ
neZ
ddd�Zee
d
d
�fdd�Zedd��Zedd��Zedd��Zedd��ZdS)ra�A reader which dynamically applies pack deltas to a base object, keeping the
    memory demands to a minimum.

    The size of the final object is only obtainable once all deltas have been
    applied, unless it is retrieved from a pack index.

    The uncompressed Delta has the following layout (MSB being a most significant
    bit encoded dynamic size):

    * MSB Source Size - the size of the base against which the delta was created
    * MSB Target Size - the size of the resulting data after the delta was applied
    * A list of one byte commands (cmd) which are followed by a specific protocol:

     * cmd & 0x80 - copy delta_data[offset:offset+size]

      * Followed by an encoded offset into the delta data
      * Followed by an encoded size of the chunk to copy

     *  cmd & 0x7f - insert

      * insert cmd bytes from the delta buffer into the output stream

     * cmd == 0 - invalid operation ( or error in delta stream )
    )�_bstream�	_dstreams�
_mm_target�_sizeri���cCs:t|�dks
Jd��|d|_t|dd��|_d|_dS)z�Initialize this instance with a list of streams, the first stream being
        the delta to apply on top of all following deltas, the last stream being the
        base object onto which to apply the deltasr5z+Need at least one delta and one base streamrPNr)r:rc�tuplerdr)r&�stream_listr*r*r+r,hs

zDeltaApplyReader.__init__cCs�t|j�dkr|�|�St|j�}|��dkr!d|_td�|_dS|��|_t|j�|_t|jj	�}t
|jj|j|jj	dt
j�|jj}|�||�|j�d�dS)Nr5r�)r:rd�_set_cache_brute_rZrboundrfrrercr)rr6rrDrEZapplyrO)r&r/Zdcl�bbufrr*r*r+�_set_cache_too_slow_without_crs



z.DeltaApplyReader._set_cache_too_slow_without_ccCslt�}d}|jD]&}|�d�}t|�\}}t||�\}}|�||d�|||f�t||�}q|jj}	|}t|j�dkrCt|	|�}	}t	|	�}
t
|jj|
j|	dtj
�t	|�}d}tt|�t|j��D]I\\}
}}}}t	|j|�}|�|
�t
|j|j|jdtj
�dt�vr�t|
||�nt|
||t|�|j�||
}
}|
�d�|�d�|}qd|
|_||_dS)z*If we are here, we apply the actual deltasriNr5ri�
c_apply_delta)�listrdr6r�append�maxrcr)r:rrrrDrE�zip�reversed�globalsrmrrOrerf)r&r/Zbuffer_info_listZmax_target_sizeZdstream�bufrMZsrc_sizeZtarget_sizeZ	base_sizerkZtbufZfinal_target_size�dbufZddatar*r*r+rj�s:

$





z"DeltaApplyReader._set_cache_brute_rcCsB|j|j}|dks||kr|}|j�|�}|jt|�7_|S)Nr5)rfrrer6r:)r&�countZblr@r*r*r+r6�szDeltaApplyReader.readrGcCs6|dks|ttdd�krtd��d|_|j�d�dS)zhAllows to reset the stream to restart reading

        :raise ValueError: If offset and whence are not 0rrGrHN)rIrJrKrrerOrLr*r*r+rO�szDeltaApplyReader.seekcCs<t|�dkr
td��|djtvrtd|dj��||�S)a
        Convert the given list of streams into a stream which resolves deltas
        when reading from it.

        :param stream_list: two or more stream objects, first stream is a Delta
            to the object that you want to resolve, followed by N additional delta
            streams. The list's last stream must be a non-delta stream.

        :return: Non-Delta OPackStream object whose stream can be used to obtain
            the decompressed resolved data
        :raise ValueError: if the stream list cannot be handled�zNeed at least two streamsrPzNCannot resolve deltas if there is no base object stream, last one was type: %s)r:rK�type_idr�type)�clsrhr*r*r+r>�s
�zDeltaApplyReader.newcC�|jjSr1)rcryr2r*r*r+ry�zDeltaApplyReader.typecCr{r1)rcrxr2r*r*r+rxr|zDeltaApplyReader.type_idcCr?)z3:return: number of uncompressed bytes in the stream)rfr2r*r*r+r)szDeltaApplyReader.sizeN�r)r]r^r_r`raZk_max_memory_mover,rlrj�has_perf_modr0r6rIrJrOrbr>�propertyryrxr)r*r*r*r+rBs(	
"K




rc@s.eZdZdZdZdd�Zdd�Zddd	�Zd
S)rzpSimple stream writer which produces a sha whenever you like as it degests
    everything it is supposed to write�sha1cCst�|_dSr1)r
r�r2r*r*r+r,2r4zSha1Writer.__init__cCs|j�|�t|�S)z{:raise IOError: If not all bytes could be written
        :param data: byte object
        :return: length of incoming data)r��updater:�r&r@r*r*r+r7szSha1Writer.writeFcCs|r|j��S|j��S)z]:return: sha so far
        :param as_hex: if True, sha will be hex-encoded, binary otherwise)r��	hexdigest�digest)r&Zas_hexr*r*r+�shaDs

zSha1Writer.shaNr\)r]r^r_r`rar,rr�r*r*r*r+r,s
rc@s$eZdZdZdZdd�Zdd�ZdS)rzZWriter producing a sha1 while passing on the written bytes to the given
    write function�writercCst�|�||_dSr1)rr,r�)r&r�r*r*r+r,Ts

zFlexibleSha1Writer.__init__cCst�||�|�|�dSr1)rrr�r�r*r*r+rXszFlexibleSha1Writer.writeN)r]r^r_r`rar,rr*r*r*r+rNs
rc@sPeZdZdZdZdd�Zdd�Zdd�Zd	d
�Ze	e
dd�fd
d�Zdd�ZdS)rz=Remembers everything someone writes to it and generates a sha)rtrqcCs$t�|�t�|_t�tj�|_dSr1)rr,rrtr$�compressobj�Z_BEST_SPEEDrqr2r*r*r+r,bs
zZippedStoreShaWriter.__init__cCst|j|�Sr1)rIrtr.r*r*r+�__getattr__gr4z ZippedStoreShaWriter.__getattr__cCs$t�||�}|j�|j�|��|Sr1)rrrtrq�compress)r&r@�alenr*r*r+rjszZippedStoreShaWriter.writecCs|j�|j���dSr1)rtrrq�flushr2r*r*r+rpszZippedStoreShaWriter.closerGrcCs0|dks|ttdd�krtd��|j�d�dS)z`Seeking currently only supports to rewind written data
        Multiple writes are not supportedrrGrHN)rIrJrKrtrOrLr*r*r+rOsszZippedStoreShaWriter.seekcCs
|j��S)zA:return: string value from the current stream position to the end)rt�getvaluer2r*r*r+r�{s
zZippedStoreShaWriter.getvalueN)
r]r^r_r`rar,r�rrrIrJrOr�r*r*r*r+r]srcs<eZdZdZdZed�Z�fdd�Zdd�Zdd	�Z	�Z
S)
rz�Digests data written to it, making the sha available, then compress the
    data and write it to the file descriptor

    **Note:** operates on raw file descriptors
    **Note:** for this to work, you have to use the close-method of this instance)�fdr�rqz+Failed to write all bytes to filedescriptorcs"t���||_t�tj�|_dSr1)�superr,r�r$r�r�rq�r&r���	__class__r*r+r,�s
zFDCompressedSha1Writer.__init__cCs>|j�|�|j�|�}t|j|�}|t|�kr|j�t|�S)zZ:raise IOError: If not all bytes could be written
        :return: length of incoming data)r�r�rqr�rr�r:�exc)r&r@ZcdataZ
bytes_writtenr*r*r+r�szFDCompressedSha1Writer.writecCs.|j��}t|j|�t|�kr|j�t|j�Sr1)rqr�rr�r:r�r)r&�	remainderr*r*r+r�s

zFDCompressedSha1Writer.close)r]r^r_r`ra�IOErrorr�r,rr�
__classcell__r*r*r�r+r�src@sFeZdZdZdZdd�Zdd�Zddd	�Zd
d�Zdd
�Z	dd�Z
dS)rz�A simple wrapper providing the most basic functions on a file descriptor
    with the fileobject interface. Cannot use os.fdopen as the resulting stream
    takes ownership��_fd�_poscCs||_d|_dS�Nrr�r�r*r*r+r,�s
zFDStream.__init__cCs$|jt|�7_t�|j|�dSr1)r�r:rJrr�r�r*r*r+r�szFDStream.writercCs:|dkrtj�|j�}t�|j|�}|jt|�7_|Sr�)rJ�path�getsizeZ	_filepathr6r�r�r:)r&rv�bytesr*r*r+r6�s
z
FDStream.readcCr?r1)r�r2r*r*r+�fileno��zFDStream.filenocCr?r1)r�r2r*r*r+�tell�r�z
FDStream.tellcCst|j�dSr1)rr�r2r*r*r+r�szFDStream.closeNr})r]r^r_r`rar,rr6r�r�rr*r*r*r+r�s
	rc@s0eZdZdZe�Zd
dd�Zdd�Zdd�Zd	S)rzVA stream that does nothing but providing a stream interface.
    Use it like /dev/nullrcCsdS)N�r*)r&r)r*r*r+r6��zNullStream.readcCsdSr1r*r2r*r*r+r�r�zNullStream.closecCst|�Sr1)r:r�r*r*r+r�szNullStream.writeNr})	r]r^r_r`rgrar6rrr*r*r*r+r�s
r)%�iorrDrJrYr$Z	gitdb.funrrrrrZ
gitdb.utilrr	r
rrZgitdb.constr
rZgitdb.utils.encodingrr~Zgitdb_speedups._perfrrm�ImportError�__all__rrrrrrrrr*r*r*r+�<module>s8�k"#("