
    h                    "   d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	 d dl
mZ h dZe	j                  e	j                  hZej!                  e       ddZddZdd	Zdd
ZddZ G d d      Z G d d      Z G d d      Z G d d      ZddZy)    )annotationsN)AnyIterableOptionalUnion)HelloCompat)_SENSITIVE_COMMANDS>   zlibzstdsnappyc                 ,    	 dd l } y# t        $ r Y yw xY wNr   TF)r   ImportError)r   s    f/var/www/html/retail-simulation-api/retail/lib/python3.12/site-packages/pymongo/compression_support.py_have_snappyr      s         	c                 ,    	 dd l } y# t        $ r Y yw xY wr   )r
   r   )r
   s    r   
_have_zlibr   $   s     r   c                 ,    	 dd l } y# t        $ r Y yw xY wr   )	zstandardr   )r   s    r   
_have_zstdr   -   s     r   c                ,   	 |j                  d      }|d d  D ]  }|t        vr,|j	                  |       t        j                  d| d       7|dk(  r3t               s)|j	                  |       t        j                  dd       o|dk(  r3t               s)|j	                  |       t        j                  dd       |d	k(  st               r|j	                  |       t        j                  d
d        |S # t        $ r t        |      }Y w xY w)N,zUnsupported compressor:    )
stacklevelr   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warnr   r   r   )dummyvaluecompressors
compressors       r   validate_compressorsr'   6   s   "kk#&
 "!n
33z*MM4ZLAaP8#LNz*MMP
 6!*,z*MM4
 6!*,z*MMO) %2 ;  "5k"s   C< <DDc                    	 t        |      }|dk  s|dkD  rt        d| |fz        |S # t        $ r t        |  d|d      d w xY w)Nz must be an integer, not .	   z$%s must be between -1 and 9, not %d.)int	Exception	TypeError
ValueError)optionr$   levels      r   validate_zlib_compression_levelr2   Z   sh    RE
 rzUQY?65/QRRL	  R6(";E9AFGTQRs	   ) Ac                  $    e Zd ZddZ	 	 	 	 ddZy)CompressionSettingsc                     || _         || _        y N)r%   zlib_compression_level)selfr%   r7   s      r   __init__zCompressionSettings.__init__e   s    &&<#    c                    |r>|d   }|dk(  r
t               S |dk(  rt        | j                        S |dk(  r
t               S y y )Nr   r   r
   r   )SnappyContextZlibContextr7   ZstdContext)r8   r%   chosens      r   get_compression_contextz+CompressionSettings.get_compression_contexti   sO      ^F!$&6!"4#>#>??6!"}$r:   N)r%   	list[str]r7   r,   )r%   zOptional[list[str]]returnz4Union[SnappyContext, ZlibContext, ZstdContext, None])__name__
__module____qualname__r9   r@    r:   r   r4   r4   d   s    =.	=r:   r4   c                  "    e Zd ZdZedd       Zy)r<      c                ,    dd l }|j                  |       S Nr   )r   compress)datar   s     r   rK   zSnappyContext.compress{   s    t$$r:   NrL   bytesrB   rN   rC   rD   rE   compressor_idstaticmethodrK   rF   r:   r   r<   r<   x   s    M% %r:   r<   c                       e Zd ZdZddZddZy)r=   r   c                    || _         y r6   )r1   )r8   r1   s     r   r9   zZlibContext.__init__   s	    
r:   c                B    dd l }|j                  || j                        S rJ   )r
   rK   r1   )r8   rL   r
   s      r   rK   zZlibContext.compress   s    }}T4::..r:   N)r1   r,   rM   )rC   rD   rE   rP   r9   rK   rF   r:   r   r=   r=      s    M/r:   r=   c                  "    e Zd ZdZedd       Zy)r>      c                H    dd l }|j                         j                  |       S rJ   )r   ZstdCompressorrK   )rL   r   s     r   rK   zZstdContext.compress   s!     	'')22488r:   NrM   rO   rF   r:   r   r>   r>      s    M9 9r:   r>   c                >   |t         j                  k(  rdd l}|j                  t	        |             S |t
        j                  k(  rdd l}|j                  |       S |t        j                  k(  r#dd l	}|j                         j                  |       S t        d|fz        )Nr   zUnknown compressorId %d)r<   rP   r   
uncompressrN   r=   r
   
decompressr>   r   ZstdDecompressorr/   )rL   rP   r   r
   r   s        r   r[   r[      s    333
 	  t--	+33	3t$$	+33	3 	))+66t<<2m5EEFFr:   )rB   bool)r#   r   r$   zUnion[str, Iterable[str]]rB   rA   )r0   strr$   r   rB   r,   )rL   rN   rP   r,   rB   rN   )
__future__r   r!   typingr   r   r   r   pymongo.hellor   pymongo.helpersr	   r   CMD
LEGACY_CMD_NO_COMPRESSIONupdater   r   r   r'   r2   r4   r<   r=   r>   r[   rF   r:   r   <module>rg      s    #  1 1 % /3 ??K$:$:;   * +!H (% %	/ 	/	9 	9Gr:   