o
    EDi                     @   s  d dl Z d dlmZ d dlmZ d dlZd dlZd dlZzd dlZW n e	y-   dZY nw ddgZ
er9e
d e
ddg i ZG d	d
 d
ZG dd dedddZG dd dedddZG dd deddZG dd deddZe ZdedefddZdS )    N)abstractmethod)Unionlz4zstdbrgzipdeflatec                   @   sB   e Zd ZddedefddZedeee	f fddZ
d	d
 ZdS )
CompressorTtagthread_safec                 C   s   |r|  n| t |< d S N)comp_map)clsr
   r    r   ^/var/www/Datamplify/venv/lib/python3.10/site-packages/clickhouse_connect/driver/compression.py__init_subclass__   s   zCompressor.__init_subclass__returnc                 C   s   |S r   r   selfblockr   r   r   compress_block   s   zCompressor.compress_blockc                 C   s   d S r   r   r   r   r   r   flush    s   zCompressor.flushN)T)__name__
__module____qualname__strboolr   r   r   bytes	bytearrayr   r   r   r   r   r   r	      s
    r	   c                   @   s0   e Zd ZddedefddZdd Zd	d
 ZdS )GzipCompressor      levelwbitsc                 C   s   t j||d| _d S )N)r#   r$   )zlibcompressobjzlib_obj)r   r#   r$   r   r   r   __init__%   s   zGzipCompressor.__init__c                 C   s   | j |S r   )r'   compressr   r   r   r   r   (   s   zGzipCompressor.compress_blockc                 C   s
   | j  S r   )r'   r   r   r   r   r   r   +      
zGzipCompressor.flushN)r!   r"   )r   r   r   intr(   r   r   r   r   r   r   r    $   s    r    F)r
   r   c                   @   s   e Zd Zdd Zdd ZdS )Lz4Compressorc                 C   s   t j | _d S r   )r   frameLZ4FrameCompressorcompr   r   r   r   r(   0   s   zLz4Compressor.__init__c                 C   s.   | j t|}|| j |7 }|| j   S r   )r/   beginlenr)   r   )r   r   outputr   r   r   r   3   s   zLz4Compressor.compress_blockN)r   r   r   r(   r   r   r   r   r   r,   /   s    r,   c                   @      e Zd Zdd ZdS )ZstdCompressorc                 C   
   t |S r   )	zstandardr)   r   r   r   r   r   :   r*   zZstdCompressor.compress_blockNr   r   r   r   r   r   r   r   r4   9       r4   )r
   c                   @   r3   )BrotliCompressorc                 C   r5   r   )brotlir)   r   r   r   r   r   ?   r*   zBrotliCompressor.compress_blockNr7   r   r   r   r   r9   >   r8   r9   compressionr   c                 C   s0   | st S t|  }z| W S  ty   | Y S w r   )null_compressorr   	TypeError)r;   r/   r   r   r   get_compressorF   s   r>   )r%   abcr   typingr   r   	lz4.framer6   r:   ImportErroravailable_compressionappendextendr   r	   r    r,   r4   r9   r<   r   r>   r   r   r   r   <module>   s.    

