o
    #j                     @   sP   d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	 dd Z
dd	 ZdS )
zf
This module provides general http handler functions for processing http responses from BCM services.
    N)compatutils)BceClientError)BceServerErrorc                 C   sB   |   }|rt|}tj|tjd|jd< ||jd< |   dS )a  If the body is not empty, convert it to a python object and set as the value of
    response.body. http_response is always closed if no error occurs.

    :param http_response: the http_response object returned by HTTPConnection.getresponse()
    :type http_response: httplib.HTTPResponse

    :param response: general response object which will be returned to the caller
    :type response: baidubce.BceResponse

    :return: always true
    :rtype bool
    )object_hookresultraw_dataT)	readr   convert_to_stringjsonloadsr   Zdict_to_python_object__dict__close)http_responseresponsebody r   b/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/baidubce/services/bcm/bcm_handler.pyparse_json_list   s   

r   c                 C   s   | j d tjjd krdS | j d tjjd krtd|  }|s1t| j|j	j
d}| j |_|tt|}t|}d|v rK|d durK|d }d}d|v r[|d dur[|d }|j	j
}d	|v rm|d	 durm|d	 }t|||d
}| j |_|)aH  If the body is not empty, convert it to a python object and set as the value of
    response.body. http_response is always closed if no error occurs.

    :param http_response: the http_response object returned by HTTPConnection.getresponse()
    :type http_response: httplib.HTTPResponse

    :param response: general response object which will be returned to the caller
    :type response: baidubce.BceResponse

    :return: false if http status code is 2xx, raise an error otherwise
    :rtype bool

    :raise baidubce.exception.BceClientError: if http status code is NOT 2xx
    d   Fs#   Can not handle 1xx http status code)
request_idmessageN	Exceptioncoder   )r   r   )statushttpclientOKCONTINUEr   r	   r   reasonmetadataZbce_request_idstatus_coder   r   r   r
   str)r   r   r   ZbseZ
error_dictr   r   r   r   r   r   parse_error.   s,   r#   )__doc__http.clientr   r   Zbaidubcer   r   Zbaidubce.exceptionr   r   r   r#   r   r   r   r   <module>   s   