o
    Åîï]2  ã                   @   s  d dl Z zd dlZdZW n ey   dZY nw zd dlZdZW n ey+   dZY nw zd dlmZmZ dZ	W n eyC   dZ	Y nw d dl
mZ eg d¢ƒZedgƒZe e¡ dd	„ Zd
d„ ZG dd„ deƒZdd„ ZG dd„ deƒZG dd„ deƒZG dd„ deƒZdd„ ZdS )é    NTF)ÚZstdCompressorÚZstdDecompressor)Ú_SENSITIVE_COMMANDS)ÚsnappyÚzlibÚzstdÚismasterc                 C   sÈ   z|  d¡}W n ty   t|ƒ}Y nw |d d … D ]F}|tvr/| |¡ t d|f ¡ q|dkr@ts@| |¡ t d¡ q|dkrQtsQ| |¡ t d¡ q|dkrat	sa| |¡ t d¡ q|S )	Nú,zUnsupported compressor: %sr   zuWire protocol compression with snappy is not available. You must install the python-snappy module for snappy support.r   zWWire protocol compression with zlib is not available. The zlib module is not available.r   zwWire protocol compression with zstandard is not available. You must install the zstandard module for zstandard support.)
ÚsplitÚAttributeErrorÚlistÚ_SUPPORTED_COMPRESSORSÚremoveÚwarningsÚwarnÚ_HAVE_SNAPPYÚ
_HAVE_ZLIBÚ
_HAVE_ZSTD)ÚdummyÚvalueÚcompressorsÚ
compressor© r   úM/var/www/html/env/lib/python3.10/site-packages/pymongo/compression_support.pyÚvalidate_compressors,   s4   þ

ÿ
ÿ
ÿ€r   c                 C   sH   zt |ƒ}W n   td| |f ƒ‚|dk s|dkr"td| |f ƒ‚|S )Nz%s must be an integer, not %r.éÿÿÿÿé	   z$%s must be between -1 and 9, not %d.)ÚintÚ	TypeErrorÚ
ValueError)Úoptionr   Úlevelr   r   r   Úvalidate_zlib_compression_levelJ   s   
ÿr"   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚCompressionSettingsc                 C   s   || _ || _d S ©N)r   Úzlib_compression_level)Úselfr   r%   r   r   r   Ú__init__V   s   
zCompressionSettings.__init__c                 C   sB   |r|d }|dkrt ƒ S |dkrt| jƒS |dkrtƒ S d S d S )Nr   r   r   r   )ÚSnappyContextÚZlibContextr%   ÚZstdContext)r&   r   Úchosenr   r   r   Úget_compression_contextZ   s   
ùz+CompressionSettings.get_compression_contextN)Ú__name__Ú
__module__Ú__qualname__r'   r,   r   r   r   r   r#   U   s    r#   c                 C   s"   t  d¡}d | | ¡| ¡ g¡S )z Compress data with zlib level 0.r   ó    )r   ÚcompressobjÚjoinÚcompressÚflush)ÚdataÚcobjr   r   r   Ú_zlib_no_compresse   s   
r7   c                   @   ó   e Zd ZdZedd„ ƒZdS )r(   é   c                 C   s
   t  | ¡S r$   )r   r3   ©r5   r   r   r   r3   n   s   
zSnappyContext.compressN©r-   r.   r/   Úcompressor_idÚstaticmethodr3   r   r   r   r   r(   k   ó    r(   c                   @   s   e Zd ZdZdd„ ZdS )r)   é   c                    s8   ˆ dkr
t j| _d S ˆ dkrt| _d S ‡ fdd„| _d S )Nr   r   c                    s   t  | ˆ ¡S r$   )r   r3   r:   ©r!   r   r   Ú<lambda>~   s    z&ZlibContext.__init__.<locals>.<lambda>)r   r3   r7   )r&   r!   r   r@   r   r'   v   s
   
zZlibContext.__init__N)r-   r.   r/   r<   r'   r   r   r   r   r)   s   s    r)   c                   @   r8   )r*   é   c                 C   s   t ƒ  | ¡S r$   )r   r3   r:   r   r   r   r3   „   s   zZstdContext.compressNr;   r   r   r   r   r*   �   r>   r*   c                 C   sP   |t jkrt t| ƒ¡S |tjkrt | ¡S |tjkr!t	ƒ  | ¡S t
d|f ƒ‚)NzUnknown compressorId %d)r(   r<   r   Ú
uncompressÚbytesr)   r   Ú
decompressr*   r   r   )r5   r<   r   r   r   rE   ‹   s   
	


rE   )r   r   r   ÚImportErrorr   r   Ú	zstandardr   r   r   Úpymongo.monitoringr   Úsetr   Ú_NO_COMPRESSIONÚupdater   r"   Úobjectr#   r7   r(   r)   r*   rE   r   r   r   r   Ú<module>   s>   þþÿ


