o
    &zh)                     @   s@  d dl Z d dlmZm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 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 ddlmZ ddlmZ zd dlmZ W n eyk   d dlmZ Y nw defddZdefddZ defddZ!defddZ"defddZ#d!defddZ$defdd Z%dS )"    N)loadsdumps)Response   )BadRequestException)ForbiddenException)InternalServerException)NotFoundException)PartialSuccessException)TooManyRequestsException)UnauthorizedException)UnknownException)ResponseMetadata)ResponseMetadataResult)camel_dict_to_snake_dict)JSONDecodeErrorresponsec                 C   s*   z|   }W |S  ty   | j}Y |S w N)jsonr   text)r   resp r   Q/var/www/html/kangema/venv/lib/python3.10/site-packages/imagekitio/utils/utils.pyget_response_json   s   
r   c                 C   s   t | }t|| j| j}|S r   )r   r   status_codeheaders)r   r   response_metadatar   r   r   populate_response_metadata   s   r   c                 C   s   t | }t| }t|tkrt|}t|tkr|d nd}t|tkr-d|v r-|d nd}| jdkr:t|||| jdkrEt	|||| jdkrPt
|||| jdkr[t|||| jdkso| jd	kso| jd
kso| jdkrut|||t|||)Nmessage helpi  i  i  i  i  i  i  i  )r   r   typestrastliteral_evaldictr   r   r   r   r   r   r   r   r   response_meta_dataerror_messageresponse_helpr   r   r   general_api_throw_exception%   s(   
 







r*   c                 C   s   t | }t| }t|tkrt|}t|tkr|d nd}t|tkr)|d nd}| jdkr6t|||| jdkrAt	|||t
|||)Nr   r   r       i  )r   r   r!   r"   r#   r$   r%   r   r
   r	   r   r&   r   r   r   throw_other_exception?   s   


r,   r   c                 C   s<   t tt|  }|di |}t|  | j| j|_|S Nr   )r   r   r   r   r   r   r   r   )r   response_objectres_newur   r   r   convert_to_response_objectN   s   r1   c                 C   s.   t  }t| jdkr|  nd | j| j|_|S )N   )r   r   r   r   r   r   )r   r0   r   r   r   *convert_to_response_metadata_result_objectU   s
   r3   c                 C   s\   g }|   D ]}ttt|}|di |}|| q||}t|   | j| j|_|S r-   )	r   r   r   r   appendr   r   r   r   )r   r.   list_response_objectresponse_listitemr/   r0   r   r   r   convert_to_list_response_object]   s   r8   r   )&r#   r   r   r   requests.modelsr   exceptions.BadRequestExceptionr   exceptions.ForbiddenExceptionr   "exceptions.InternalServerExceptionr   exceptions.NotFoundExceptionr	   "exceptions.PartialSuccessExceptionr
   #exceptions.TooManyRequestsExceptionr    exceptions.UnauthorizedExceptionr   exceptions.UnknownExceptionr   models.results.ResponseMetadatar   %models.results.ResponseMetadataResultr   utils.formatterr   simplejson.errorsr   ImportErrorr   r   r*   r,   r1   r3   r8   r   r   r   r   <module>   s8    