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/utils/__pycache__/compression.cpython-310.pyc
o

�]Lb�d�@s�ddlmZmZddlZddlZddlZddlmZddlm	Z	m
Z
mZddlmZejZe
j
Z
dZd	Ze�d
d�ZGdd
�d
e�ZGdd�de�Ze�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Ze�e��Gdd�de�Ze�e��Gd d!�d!e�Ze�e��Gd"d#�d#e�Z e�e ��Gd$d%�d%e�Z!e�e!��d&d'�Z"e"��#�Z$dS)(�)�absolute_import�print_functionN�)�getattr)�error�i18n�pycompat�)�
stringutilsserversclient�compenginewireprotosupport)�name�serverpriority�clientpriorityc@s&eZdZdd�Zddd�Zdd�ZdS)	�
propertycachecCs||_|j|_dS�N)�func�__name__r)�selfr�r�=/usr/lib/python3/dist-packages/mercurial/utils/compression.py�__init__&szpropertycache.__init__NcCs|�|�}|�||�|Sr)r�
cachevalue)r�obj�type�resultrrr�__get__*s
zpropertycache.__get__cCs||j|j<dSr)�__dict__r)rr�valuerrrr/szpropertycache.cachevaluer)r�
__module__�__qualname__rrrrrrrr%s
rc@szeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Ze	dd
��Z
e	dd��Zdd�Zdd�Z
ddd�Zdd�Zdd�ZdS)�compressormanageraGHolds registrations of various compression engines.

    This class essentially abstracts the differences between compression
    engines to allow new compression formats to be added easily, possibly from
    extensions.

    Compressors are registered against the global instance by calling its
    ``register()`` method.
    cCs"i|_i|_i|_i|_i|_dSr)�_engines�_bundlenames�_bundletypes�_revlogheaders�
_wiretypes�rrrrr?s

zcompressormanager.__init__cCs
|j|Sr�r!�r�keyrrr�__getitem__J�
zcompressormanager.__getitem__cCs
||jvSrr'r(rrr�__contains__Mr+zcompressormanager.__contains__cC�t|j���Sr)�iterr!�keysr&rrr�__iter__Pszcompressormanager.__iter__c	Cs8t|t�sttd���|��}||jvrt�td�|��|��}|rT|\}}||j	vr5t�td�|��||j
vrHt�td�||j
|f��|rO||j	|<||j
|<|��}|ru|j}||jvrpt�td�||j|f��||j|<|�
�}|r�||jvr�t�td�||j|f��|r�||j|<||j|<dS)zxRegister a compression engine with the manager.

        The argument must be a ``compressionengine`` instance.
        s$argument must be a compressionengines(compression engine %s already registereds!bundle name %s already registereds'bundle type %s already registered by %ss5wire protocol compression %s already registered by %ss)revlog header %s already registered by %sN)�
isinstance�compressionengine�
ValueError�_rr!r�Abort�
bundletyper"r#�wireprotosupportr%�revlogheaderr$)	r�enginer�
bundleinfo�
bundlenamer6�wiresupport�wiretyper8rrr�registerSsZ


�

�
��


���
��
zcompressormanager.registercCr-r)�setr"r/r&rrr�supportedbundlenames��z&compressormanager.supportedbundlenamescCr-r)r?r#r/r&rrr�supportedbundletypes�rAz&compressormanager.supportedbundletypescC�2|j|j|}|��st�td�|����|S)z�Obtain a compression engine registered to a bundle name.

        Will raise KeyError if the bundle type isn't registered.

        Will abort if the engine is known but not available.
        �)compression engine %s could not be loaded)r!r"�	availablerr5r4r)rr;r9rrr�
forbundlename���zcompressormanager.forbundlenamecCrC)z�Obtain a compression engine registered to a bundle type.

        Will raise KeyError if the bundle type isn't registered.

        Will abort if the engine is known but not available.
        rD)r!r#rErr5r4r)rr6r9rrr�
forbundletype�rGzcompressormanager.forbundletypeTcsf|ttfvsJ�|tkrdnd��fdd��j��D�}|r%dd�|D�}�fdd�}tt||d��S)	z�Obtain compression engines that support the wire protocol.

        Returns a list of engines in prioritized order, most desired first.

        If ``onlyavailable`` is set, filter out engines that can't be
        loaded.
        sserverprioritysclientprioritycsg|]}�j|�qSrr'��.0�er&rr�
<listcomp>�sz:compressormanager.supportedwireengines.<locals>.<listcomp>cSsg|]}|��r|�qSr)rErIrrrrL�scs|��}dt|��|jfS)N���)r7rr)rK�w)�attrrr�getkey�sz6compressormanager.supportedwireengines.<locals>.getkey)r))�
SERVERROLE�
CLIENTROLEr%�values�list�sorted)r�role�
onlyavailable�enginesrPr)rOrr�supportedwireengines�sz&compressormanager.supportedwireenginescCrC)NrD)r!r%rErr5r4r)rr=r9rrr�forwiretype�s�zcompressormanager.forwiretypecCs|j|j|S)z�Obtain a compression engine registered to a revlog header.

        Will raise KeyError if the revlog header value isn't registered.
        )r!r$)r�headerrrr�forrevlogheader�sz!compressormanager.forrevlogheaderN)T)rrr�__doc__rr*r,r0r>�propertyr@rBrFrHrYrZr\rrrrr 4s 
=


r c@sTeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
d�Z	dd�Z
ddd�ZdS)r2zuBase class for compression engines.

    Compression engines must implement the interface defined by this class.
    cC�t��)z�Returns the name of the compression engine.

        This is the key the engine is registered under.

        This method must be implemented.
        ��NotImplementedErrorr&rrrr��zcompressionengine.namecC�dS)aWhether the compression engine is available.

        The intent of this method is to allow optional compression engines
        that may not be available in all installations (such as engines relying
        on C extensions that may not be present).
        Trr&rrrrE��zcompressionengine.availablecCrc)a�Describes bundle identifiers for this engine.

        If this compression engine isn't supported for bundles, returns None.

        If this engine can be used for bundles, returns a 2-tuple of strings of
        the user-facing "bundle spec" compression name and an internal
        identifier used to denote the compression format within bundles. To
        exclude the name from external usage, set the first element to ``None``.

        If bundle compression is supported, the class must also implement
        ``compressstream`` and `decompressorreader``.

        The docstring of this method is used in the help system to tell users
        about this engine.
        Nrr&rrrr6�szcompressionengine.bundletypecCrc)a�Declare support for this compression format on the wire protocol.

        If this compression engine isn't supported for compressing wire
        protocol payloads, returns None.

        Otherwise, returns ``compenginewireprotosupport`` with the following
        fields:

        * String format identifier
        * Integer priority for the server
        * Integer priority for the client

        The integer priorities are used to order the advertisement of format
        support by server and client. The highest integer is advertised
        first. Integers with non-positive values aren't advertised.

        The priority values are somewhat arbitrary and only used for default
        ordering. The relative order can be changed via config options.

        If wire protocol compression is supported, the class must also implement
        ``compressstream`` and ``decompressorreader``.
        Nrr&rrrr7
sz"compressionengine.wireprotosupportcCrc)aPHeader added to revlog chunks that identifies this engine.

        If this engine can be used to compress revlogs, this method should
        return the bytes used to identify chunks compressed with this engine.
        Else, the method should return ``None`` to indicate it does not
        participate in revlog compression.
        Nrr&rrrr8#szcompressionengine.revlogheaderNcCr_)a�Compress an iterator of chunks.

        The method receives an iterator (ideally a generator) of chunks of
        bytes to be compressed. It returns an iterator (ideally a generator)
        of bytes of chunks representing the compressed output.

        Optionally accepts an argument defining how to perform compression.
        Each engine treats this argument differently.
        r`�r�it�optsrrr�compressstream-s
z compressionengine.compressstreamcCr_)z�Perform decompression on a file object.

        Argument is an object with a ``read(size)`` method that returns
        compressed data. Return value is an object with a ``read(size)`` that
        returns uncompressed data.
        r`�r�fhrrr�decompressorreader9rbz$compressionengine.decompressorreadercCr_)aLObtain an object that can be used to compress revlog entries.

        The object has a ``compress(data)`` method that compresses binary
        data. This method returns compressed binary data or ``None`` if
        the data could not be compressed (too small, not compressible, etc).
        The returned data should have a header uniquely identifying this
        compression format so decompression can be routed to this engine.
        This header should be identified by the ``revlogheader()`` return
        value.

        The object has a ``decompress(data)`` method that decompresses
        data. The method will only be called if ``data`` begins with
        ``revlogheader()``. The method should return the raw, uncompressed
        data or raise a ``StorageError``.

        The object is reusable but is not thread safe.
        r`�rrgrrr�revlogcompressorBsz"compressionengine.revlogcompressorr)rrrr]rrEr6r7r8rhrkrmrrrrr2�s		

	r2c@�$eZdZdd�Zdd�Zdd�ZdS)�_CompressedStreamReadercCs2t|d�r
|j|_n|j|_g|_d|_d|_dS)N�unbufferedreadrF)�safehasattrrp�_reader�read�_pending�_pos�_eofrirrrrXs


z _CompressedStreamReader.__init__cCr_rr`)r�chunkrrr�_decompressasz#_CompressedStreamReader._decompresscCs�g}	|jr^t|jd�||jkr0|jd}|�||j|j|��|j|7_d�|�S|j�d�}|jrM|�||jd��|t|�|j8}n|�|�|t|�8}d|_|js|jrfd�|�S|�d�}|�|�|s}|js}|js}d�|�Sq)NTr�i)	rt�lenru�append�join�poprvrrrx)r�l�buf�newbufrwrrrrsds.


�



�z_CompressedStreamReader.readN)rrrrrxrsrrrrroWs	roc�$eZdZ�fdd�Zdd�Z�ZS)�_GzipCompressedStreamReaderc�tt|��|�t��|_dSr)�superr�r�zlib�
decompressobj�
_decompobjri��	__class__rrr��z$_GzipCompressedStreamReader.__init__cCsl|j�|�}|r|j�|�|j��}z|�d�|��|jdkr(d|_WdSWdStj	y5YdSw)N�xT)
r��
decompressrtr{�copy�flush�unused_datarvr�r)rrwr��drrrrx�s


��z'_GzipCompressedStreamReader._decompress�rrrrrx�
__classcell__rrr�rr���r�cr�)�_BZ2CompressedStreamReadercr�r)r�r�r�bz2�BZ2Decompressorr�rir�rrr�r�z#_BZ2CompressedStreamReader.__init__cCs`|j�|�}|r|j�|�z	|j�d�}|r|j�|�nWdSqty/d|_YdSw�NTry)r�r�rtr{�EOFErrorrv�rrwr�rrrrx�s��z&_BZ2CompressedStreamReader._decompressr�rrr�rr��r�r�cseZdZ�fdd�Z�ZS)�#_TruncatedBZ2CompressedStreamReadercs4tt|��|�|j�d�}|r|j�|�dSdS)N�BZ)r�r�rr�r�rtr{)rrjr�r�rrr�s
�z,_TruncatedBZ2CompressedStreamReader.__init__)rrrrr�rrr�rr��sr�cr�)�_ZstdCompressedStreamReadercs(tt|��|�||_|����|_dSr)r�r�r�_zstd�ZstdDecompressorr�r�)rrj�zstdr�rrr�sz$_ZstdCompressedStreamReader.__init__cCsd|j�|�}|r|j�|�z	|j�d�}|r|j�|�nWdSq|jjy1d|_YdSwr�)r�r�rtr{r��	ZstdErrorrvr�rrrrx�s��z'_ZstdCompressedStreamReader._decompressr�rrr�rr��sr�c@�XeZdZdd�Zdd�Zdd�Zdd�Zdd
d�Zdd
�ZGdd�de	�Z
ddd�Zd	S)�_zlibenginecCrc)N�zlibrr&rrrr��z_zlibengine.namecCrc)z�zlib compression using the DEFLATE algorithm.

        All Mercurial clients should support this format. The compression
        algorithm strikes a reasonable balance between compression ratio
        and size.
        )sgzipsGZrr&rrrr6�rdz_zlibengine.bundletypecC�tddd�S)Nr����compewireprotosupportr&rrrr7��z_zlibengine.wireprotosupportcCrc)Nr�rr&rrrr8�r�z_zlibengine.revlogheaderNcc�H�|pi}t�|�dd��}|D]}|�|�}|r|Vq|��VdS)N�levelrM)r��compressobj�get�compressr��rrfrg�zrw�datarrrrh�s�
�z_zlibengine.compressstreamcC�t|�Sr)r�rirrrrk��z_zlibengine.decompressorreaderc@s&eZdZddd�Zdd�Zdd�ZdS)	z _zlibengine.zlibrevlogcompressorNcCs
||_dSr)�_level)r�levelrrrr�r+z)_zlibengine.zlibrevlogcompressor.__init__cCs�t|�}|dks
J�|dkrdS|dkr0|jdurt�|�}nt�||j�}t|�|kr.|SdS|jdur:t��}ntj|jd�}g}d}||kr_|d}|�|�|||���|}||ksI|�|���ttt|��|krtd�	|�SdS)Nr�,�@B�r�iry)
rzr�r�r�r�r{r��sum�mapr|)rr��insize�
compressedr��parts�pos�pos2rrrr��s2


�
z)_zlibengine.zlibrevlogcompressor.compressc
Cs@zt�|�WStjy}zt�td�t�|���d}~ww)N�revlog decompress error: %s)r�r�r�StorageErrorr4r
�forcebytestr)rr�rKrrrr�s����z+_zlibengine.zlibrevlogcompressor.decompressr�rrrrr�r�rrrr�zlibrevlogcompressor�s
%r�cCs d}|dur|�d�}|�|�S)Ns
zlib.level)r�r��rrgr�rrrrms

z_zlibengine.revlogcompressorr)rrrrr6r7r8rhrk�objectr�rmrrrrr��s	

2r�c@s6eZdZdd�Zdd�Zdd�Zddd	�Zd
d�ZdS)
�
_bz2enginecCrc)Nsbz2rr&rrrr$r�z_bz2engine.namecCrc)a�An algorithm that produces smaller bundles than ``gzip``.

        All Mercurial clients should support this format.

        This engine will likely produce smaller bundles than ``gzip`` but
        will be significantly slower, both during compression and
        decompression.

        If available, the ``zstd`` engine can yield similar or better
        compression at much higher speeds.
        )�bzip2r�rr&rrrr6'�z_bz2engine.bundletypecCr�)Nr�rr�r&rrrr77r�z_bz2engine.wireprotosupportNccr�)Nr��	)r��
BZ2Compressorr�r�r�r�rrrrh:s�
�z_bz2engine.compressstreamcCr�r)r�rirrrrkDr�z_bz2engine.decompressorreaderr)rrrrr6r7rhrkrrrrr�#s

r�c@rn)�_truncatedbz2enginecCrc)Nsbz2truncatedrr&rrrrLr�z_truncatedbz2engine.namecCrc)N)Ns_truncatedBZrr&rrrr6Or�z_truncatedbz2engine.bundletypecCr�r)r�rirrrrkTr�z&_truncatedbz2engine.decompressorreaderN)rrrrr6rkrrrrr�Ksr�c@r�)�_noopenginecCrc)N�nonerr&rrrr\r�z_noopengine.namecCrc)zmNo compression is performed.

        Use this compression engine to explicitly disable compression.
        )r�sUNrr&rrrr6_sz_noopengine.bundletypecCstddd�S)Nr�r�
r�r&rrrr7ir�z_noopengine.wireprotosupportcCrc)N�rr&rrrr8nr�z_noopengine.revlogheaderNcC�|Srrrerrrrhqr�z_noopengine.compressstreamcCr�rrrirrrrktr�z_noopengine.decompressorreaderc@seZdZdd�ZdS)z _noopengine.nooprevlogcompressorcCsdSrr)rr�rrrr�xr�z)_noopengine.nooprevlogcompressor.compressN)rrrr�rrrr�nooprevlogcompressorwsr�cCs|��Sr)r�rlrrrrm{r�z_noopengine.revlogcompressorr)rrrrr6r7r8rhrkr�r�rmrrrrr�[s

r�c@sleZdZdd�Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	ddd�Z
dd�ZGdd�de�Z
ddd�Zd
S)�_zstdenginecCrc)N�zstdrr&rrrr�r�z_zstdengine.namecCs.zddlm}|j|WStyYdSw)Nr)r�)�r��__version__�ImportError)rr�rrr�_module�s�z_zstdengine._modulecCs
t|j�Sr)�boolr�r&rrrrE�r+z_zstdengine.availablecCrc)a�A modern compression algorithm that is fast and highly flexible.

        Only supported by Mercurial 4.1 and newer clients.

        With the default settings, zstd compression is both faster and yields
        better compression than ``gzip``. It also frequently yields better
        compression than ``bzip2`` while operating at much higher speeds.

        If this engine is available and backwards compatibility is not a
        concern, it is likely the best available engine.
        )r�sZSrr&rrrr6�r�z_zstdengine.bundletypecCr�)Nr��2r�r&rrrr7�r�z_zstdengine.wireprotosupportcCrc)N�(rr&rrrr8�r�z_zstdengine.revlogheaderNc	csf�|pi}|�dd�}|�dd�}|j}|j||d���}|D]}|�|�}|r+|Vq|��VdS)Nr��sthreadsr)r��threads)r�r��ZstdCompressorr�r�r�)	rrfrgr�r�r�r�rwr�rrrrh�s�
�z_zstdengine.compressstreamcCst||j�Sr)r�r�rirrrrk�r�z_zstdengine.decompressorreaderc@s&eZdZd	dd�Zdd�Zdd�ZdS)
z _zstdengine.zstdrevlogcompressorr�cCs,|j|d�|_|��|_|j|_|j|_dS)Nr�)r��_cctxr��_dctx�"COMPRESSION_RECOMMENDED_INPUT_SIZE�_compinsize�$DECOMPRESSION_RECOMMENDED_INPUT_SIZE�
_decompinsize)rr�r�rrrr�s
z)_zstdengine.zstdrevlogcompressor.__init__c	Cs�t|�}|dks
J�|dkrdS|dkr$|j�|�}t|�|kr"|SdS|j��}g}d}||krL||j}|�|||��}|rF|�|�|}||ks1|�|���ttt|��|krad�	|�SdS)Nrr�r�ry)
rzr�r�r�r�r{r�r�r�r|)	rr�r�r�r��chunksr�r�rwrrrr��s.


�
z)_zstdengine.zstdrevlogcompressor.compressc	
Cs�t|�}z.|j��}g}d}||kr-||j}|�|||��}|r'|�|�|}||ksd�|�WStyJ}zt�	t
d�t�|���d}~ww)Nrryr�)
rzr�r�r�r�r{r|�	Exceptionrr�r4r
r�)	rr�r��dobjr�r�r�rwrKrrrr��s*


�����z+_zstdengine.zstdrevlogcompressor.decompressN)r�r�rrrr�zstdrevlogcompressor�s

r�cCs@|pi}|�d�}|dur|�d�}|durd}|j|j|d�S)Ns
zstd.levelr�r�r�)r�r�r�r�rrrrm�s

z_zstdengine.revlogcompressorr)rrrrrr�rEr6r7r8rhrkr�r�rmrrrrr��s

@r�cCs�i}Gdd�dt�}tD]:}t|}|��sq|��}|r!|ds"qd|dt�|j�f}|�}t�|�|_|jj|_|j|_	|||d<q|S)z@Obtains a list of available bundle compressions for use in help.c@seZdZdS)z*bundlecompressiontopics.<locals>.docobjectN)rrrrrrr�	docobjectsr�rs
``%s``
    %s)
r��compenginesrEr6r�getdoc�sysstrr]�_origdoc�	_origfunc)�itemsr�rr9�bt�docrrrr�bundlecompressiontopicss 
r�)%�
__future__rrr��collectionsr�rrr�rrr
rqr4rQrR�
namedtupler�r�rr r�r2ror�r�r�r�r�r>r�r�r�r�r�rS�
i18nfunctionsrrrr�<module>sL�*w)\%
$