# Path: qingcloud/qingstor/util.py
# def load_data(data):
#     """ Wrapper to load json data, to be compatible with Python3.
#     Returns: JSON data
# 
#     Keyword arguments:
#     data: might be bytes or str
#     """
#     if type(data) == bytes:
#         return json.loads(data.decode("utf-8"))
#     else:
#         return json.loads(data)


from .util import load_data
                 code=None, message=None, url=None):
        self.status = status
        self.body = body or ''
        self.request_id = request_id
        self.code = code
        self.message = message
        self.url = url

    def __repr__(self):
        return "%s: %s %s\n%s" % (self.__class__.__name__,
                                  self.status, self.code, self.body)

    def __str__(self):
        return "%s: %s %s\n%s" % (self.__class__.__name__,
                                  self.status, self.code, self.body)


def get_response_error(response, body=None):
    if not body:
        body = response.read()
    args = {
        "status": response.status,
        "body": body,
        "request_id": response.getheader("request_id")
    }
    if body:
        try:
            resp = load_data(body)
            args["code"] = resp["code"]
            args["message"] = resp["message"]

# Path: qingcloud/qingstor/util.py
# def load_data(data):
#     """ Wrapper to load json data, to be compatible with Python3.
#     Returns: JSON data
# 
#     Keyword arguments:
#     data: might be bytes or str
#     """
#     if type(data) == bytes:
#         return json.loads(data.decode("utf-8"))
#     else:
#         return json.loads(data)


# Path: qingcloud/qingstor/exception.py
from .util import load_data

                 code=None, message=None, url=None):
        self.status = status
        self.body = body or ''
        self.request_id = request_id
        self.code = code
        self.message = message
        self.url = url

    def __repr__(self):
        return "%s: %s %s\n%s" % (self.__class__.__name__,
                                  self.status, self.code, self.body)

    def __str__(self):
        return "%s: %s %s\n%s" % (self.__class__.__name__,
                                  self.status, self.code, self.body)


def get_response_error(response, body=None):
    if not body:
        body = response.read()
    args = {
        "status": response.status,
        "body": body,
        "request_id": response.getheader("request_id")
    }
    if body:
        try:
            resp = load_data(body)
            args["code"] = resp["code"]
            args["message"] = resp["message"]

            args["url"] = resp["url"]