o
    e                     @   sT   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 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)BceClientError)BceServerError)utilsc                 C   s0   |   }|r|jtj|tdj |   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_hookT)read__dict__updatejsonloadsdict_to_python_objectclose)http_responseresponsebody r   QD:\Projects\ConvertPro\env\Lib\site-packages\baidubce/services/cfc/cfc_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}|  }|rFt|}d|v r;t	|d |d |d d}nt	|d	 |d
 dd}|du rSt	| 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codemessageZ	requestId)r   
request_idMessageZCode )r   )statushttpclientOKCONTINUEr   r   r	   r
   r   reasonmetadataZbce_request_idstatus_code)r   r   Zbser   dr   r   r   parse_error,   s   
r"   c                 C   s0   i }|   D ]\}}t|}|||< qt|S )z!

    :param d:
    :return:
    )itemsstrr   ZExpando)r!   attrkvr   r   r   r   N   s
   

r   )__doc__http.clientr   r	   Zbaidubce.exceptionr   r   Zbaidubcer   r   r"   r   r   r   r   r   <module>   s   "