
    9h              	       n   S SK r S SKrS SKrS SKJr  S SKJr  SrSr S SK	r	S\4S jrS\4S jrS\4S	 jrS\4S
 jrSS\S\\   S\4S jjrS\S\4S jr SS\S\S\S\4S jjrS\S\4S jrS\S\4S jrSS\S\S\4S jjrS\S\4S jrSS\S\\   S\4S jjrS\S\4S jrg! \
 a    Sr	 Nf = f)    N)Optional)Buffer)
i   S   N   A   Pr      Yr      r
   
bccccccBiireturnc                      g)NT r       SC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\aiokafka/codec.pyhas_gzipr      s    r   c                      [         S L$ Ncramjamr   r   r   
has_snappyr          $r   c                      [         S L$ r   r   r   r   r   has_zstdr      r   r   c                      [         S L$ r   r   r   r   r   has_lz4r      r   r   payloadcompresslevelc                     U(       d  Sn[         R                  " 5       n[        R                  " USUS9n UR	                  U 5        UR                  5         UR                  5       $ ! UR                  5         f = f)N	   w)fileobjmoder   )ioBytesIOgzipGzipFilewriteclosegetvalue)r   r   bufgzippers       r   gzip_encoder,   !   s\    
**,C mmCcOGg<<> 	s   A' 'A9c                     [         R                  " U 5      n[        R                  " USS9n UR	                  5       UR                  5         $ ! UR                  5         f = f)Nr)r!   r"   )r#   r$   r%   r&   readr(   )r   r*   r+   s      r   gzip_decoder0   2   sC    
**W
C mmCc2G||~s   A Axerial_compatiblexerial_blocksizec                   ^ ^ [        5       (       d  [        S5      eU(       d  [        R                  R	                  T 5      $ [
        R                  " 5       n[        [        [        5       H.  u  pEUR                  [        R                  " SU-   U5      5        M0     [        T 5      m U U4S j[        S[        T 5      T5       5        Hd  n[        R                  R	                  U5      n[        U5      nUR                  [        R                  " SU5      5        UR                  U5        Mf     UR!                  5       $ )a  Encodes the given data with snappy compression.

If xerial_compatible is set then the stream is encoded in a fashion
compatible with the xerial snappy library.

The block size (xerial_blocksize) controls how frequent the blocking occurs
32k is the default in the xerial library.

The format winds up being:


    +-------------+------------+--------------+------------+--------------+
    |   Header    | Block1 len | Block1 data  | Blockn len | Blockn data  |
    +-------------+------------+--------------+------------+--------------+
    |  16 bytes   |  BE int32  | snappy bytes |  BE int32  | snappy bytes |
    +-------------+------------+--------------+------------+--------------+


It is important to note that the blocksize is the amount of uncompressed
data presented to snappy at each block, whereas the blocklen is the number
of bytes that will be present in the stream; so the length will always be
<= blocksize.

Snappy codec is not available!c              3   2   >#    U  H  nTXT-    v   M     g 7fr   r   ).0ir   r2   s     r   	<genexpr> snappy_encode.<locals>.<genexpr>e   s#      9A 	(()9s   r   !i)r   NotImplementedErrorr   snappycompress_rawr#   r$   zip_XERIAL_V1_FORMAT_XERIAL_V1_HEADERr'   structpack
memoryviewrangelenr)   )	r   r1   r2   outfmtdatchunkblock
block_sizes	   ` `      r   snappy_encoderM   >   s    8 <<!"ABB~~**733
**,C)+<=		&++cCi-. > !Gq#g,(89 ++E2Z
		&++dJ/0		% <<>r   c                     [        U 5      n [        U 5      S:  a*  [        R                  " S[        -   U SS 5      nU[
        :H  $ g)a  Detects if the data given might have been encoded with the blocking mode
of the xerial snappy library.

This mode writes a magic header of the format:
    +--------+--------------+------------+---------+--------+
    | Marker | Magic String | Null / Pad | Version | Compat |
    +--------+--------------+------------+---------+--------+
    |  byte  |   c-string   |    byte    |  int32  | int32  |
    +--------+--------------+------------+---------+--------+
    |  -126  |   'SNAPPY'   |           |         |        |
    +--------+--------------+------------+---------+--------+

The pad appears to be to ensure that SNAPPY is a valid cstring
The version is the version of this format as written by xerial,
in the wild this is currently 1 as such we only support v1.

Compat is there to claim the minimum supported version that
can read a xerial block stream, presently in the wild this is
1.
   r5   NF)rD   rF   rB   unpackr@   rA   )r   headers     r   _detect_xerial_streamrR   q   sE    , !G
7|bs%66E***r   c                    [        5       (       d  [        S5      e[        U 5      (       a  [        R                  " 5       n[        U 5      SS  n[        U5      nSnXC:  a^  [        R                  " SX$S  5      S   nUS-  nXE-   nUR                  [        R                  R                  X$U 5      5        UnXC:  a  M^  UR                  S5        UR                  5       $ [        [        R                  R                  U 5      5      $ )Nr4   rO   r   r;      )r   r<   rR   r#   r$   rD   rF   rB   unpack_fromr'   r   r=   decompress_rawseekr/   bytes)r   rG   bytlengthcursorrL   ends          r   snappy_decoder]      s    <<!"ABBW%%jjl!"#&So++D#g,?BJaKF%CIIgnn33CsODEF o 	xxzW^^227;<<r   levelc                     [        5       (       d  [        S5      e[        R                  R	                  USSS9nUR                  U 5        [        UR                  5       5      $ )NLZ4 codec is not availableF)r^   content_checksumblock_linked)r   r<   r   lz4
CompressorcompressrX   finish)r   r^   
compressors      r   
lz4_encoderh      s]     99!">?? ''e% ( J  ""$%%r   c                     [        5       (       d  [        S5      e[        [        R                  R                  U 5      5      $ )Nr`   )r   r<   rX   r   rc   
decompressr   s    r   
lz4_decoderl      s/    99!">??''011r   c                     [        5       (       d  [        S5      eUc  Sn[        [        R                  R                  XS95      $ )NZstd codec is not available   )r^   )r   r<   rX   r   zstdre   )r   r^   s     r   zstd_encoderq      s>    ::!"?@@} &&w&<==r   c                     [        5       (       d  [        S5      e[        [        R                  R                  U 5      5      $ )Nrn   )r   r<   rX   r   rp   rj   rk   s    r   zstd_decoders      s/    ::!"?@@((122r   r   )Ti   )r   )r%   r#   rB   typingr   typing_extensionsr   rA   r@   r   ImportErrorboolr   r   r   r   intrX   r,   r0   rM   rR   r]   rh   rl   rq   rs   r   r   r   <module>ry      sQ    	   $G   
$ D $     "	 	E 	 NW00(,0GJ0
0f6 d :=6 =e =2& &s &5 &2 25 2	> 	> 	> 	>3 3E 3y  Gs   B) )B43B4