o
    i                     @   s   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ eeZdd	 Zd
d Zdd Zdd Zdd Zdd Zdd ZdeiZdS )z
NOTE: All functions in this module are considered private and are
subject to abrupt breaking changes. Please do not use them directly.

    N)GzipFile)compress)	urlencode)register_feature_id)determine_content_lengthc                 C   sr   t | ||r5|jd D ]+}t|}|dur.td| ||d |d< t|d |  dS td| qdS dS )zAAttempt to compress the request body using the modeled encodings.	encodingsNz%Compressing request with %s encoding.bodyheadersz$Unsupported compression encoding: %s)_should_compress_requestrequest_compressionCOMPRESSION_MAPPINGgetloggerdebug_set_compression_header)configrequest_dictoperation_modelencodingencoder r   H/home/app/Keep/.python/lib/python3.10/site-packages/botocore/compress.pymaybe_compress_request   s   
r   c           	      C   s   | j dur>| jdkr>|jd ur>t|s#t|d }d}t|| dS |jr1| }|j	}d|vS t
|d }| j}||kS dS )NTv2r   z*Body type %s does not support compression.FZrequiresLength)Zdisable_request_compressionZsignature_versionr   _is_compressible_typetyper   r   Zhas_streaming_inputZget_streaming_inputmetadata_get_body_sizeZ"request_min_compression_size_bytes)	r   r   r   Z	body_typeZlog_msgZstreaming_inputZstreaming_metadataZ	body_sizeZmin_sizer   r   r   r
   -   s    


r
   c                 C   sL   | d }t |trt|dddd}|| d< t |tttf}|p%t|dS )Nr   Tutf-8)doseqr   read)
isinstancedictr   encodestrbytes	bytearrayhasattr)r   r   Zis_supported_typer   r   r   r   E   s   
r   c                 C   s$   t | }|d u rtd|  d}|S )NzCUnable to get length of the request body: %s. Skipping compression.r   )r   r   r   )r   sizer   r   r   r   O   s   r   c                 C   s~   t d t| trt| dS t| ttfrt| S t| dr=t| dr9t| dr9|  }t	| }| 
| |S t	| S d S )NZGZIP_REQUEST_COMPRESSIONr   r    seektell)r   r!   r$   gzip_compressr#   r%   r&   r'   r*   _gzip_compress_fileobjr)   )r   current_positioncompressed_objr   r   r   _gzip_compress_body[   s   


r/   c                 C   st   t  }t|dd!}	 | d}|snt|tr|d}|| qW d    n1 s.w   Y  |d |S )Nwb)fileobjmodeTi    r   r   )	ioBytesIOr   r    r!   r$   r#   writer)   )r   r.   gzchunkr   r   r   r,   j   s   




r,   c                 C   s4   |  d}|d u r|| d< d S | d| | d< d S )NzContent-Encoding,)r   )r	   r   Z	ce_headerr   r   r   r   x   s   
r   gzip)__doc__r3   loggingr9   r   r   r+   Zbotocore.compatr   Zbotocore.useragentr   Zbotocore.utilsr   	getLogger__name__r   r   r
   r   r   r/   r,   r   r   r   r   r   r   <module>   s"   

