o
    er                     @   sp   d Z ddlZddlmZ ddlm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
 Zdd ZdS )zf
This module provides general http handler functions for processing http responses from BCE services.
    N)str)bytes)utils)compat)BceClientError)BceServerErrorc                 C   sF   |   }|rt|}|jtj|tjdj ||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raw_dataT)
readr   convert_to_string__dict__updatejsonloadsr   Zdict_to_python_objectclose)http_responseresponsebody r   ED:\Projects\ConvertPro\env\Lib\site-packages\baidubce/http/handler.py
parse_json   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d}|  }|r9tt	
|}t|d |d |d d}|du rFt| j|jj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 codeNmessagecodeZ	requestId)r   
request_id)r   )statushttpclientOKCONTINUEr   r
   r   r   r   r   r   reasonmetadataZbce_request_idstatus_code)r   r   Zbser   dr   r   r   parse_error0   s   r$   )__doc__http.clientr   builtinsr   r   r   Zbaidubcer   r   Zbaidubce.exceptionr   r   r   r$   r   r   r   r   <module>   s   