# Path: qingcloud/qingstor/multipart.py
# class MultiPartUpload(object):
# 
#     def __init__(self, bucket, key_name, upload_id):
#         """
#         @param bucket - The name of the bucket
#         @param key_name - The name of the object
#         @param upload_id - ID for the initiated multipart upload
#         """
#         self.bucket = bucket
#         self.key_name = key_name
#         self.upload_id = upload_id
# 
#     def upload_part_from_file(self, fp, part_number):
#         """ Upload multipart from a file
# 
#         Keyword arguments:
#         fp - a file-like object
#         part_number - The number of the multipart
#         """
#         params = {
#             "upload_id": self.upload_id,
#             "part_number": str(part_number),
#         }
#         response = self.bucket.connection.make_request(
#             "PUT", self.bucket.name, self.key_name, data=fp, params=params)
#         if response.status == 201:
#             part = Part(self.bucket.name, self.key_name, part_number)
#             return part
#         else:
#             err = get_response_error(response)
#             raise err
# 
#     def get_all_parts(self):
#         """ Retrieve all multiparts of an object that uploaded.
#         """
#         params = {
#             "upload_id": self.upload_id,
#         }
#         response = self.bucket.connection.make_request(
#             "GET", self.bucket.name, self.key_name, params=params)
#         if response.status == 200:
#             parts = []
#             resp = load_data(response.read())
#             for item in resp["object_parts"]:
#                 part = Part(self.bucket.name, self.key_name,
#                             item["part_number"])
#                 part.size = item["size"]
#                 part.created = item["created"]
#                 parts.append(part)
#             return parts
#         else:
#             err = get_response_error(response)
#             raise err
# 
#     def cancel_upload(self):
#         """Abort the multipart upload.
#         """
#         return self.bucket.cancel_multipart_upload(
#             self.key_name, self.upload_id
#         )
# 
#     def complete_upload(self, parts):
#         """Complete the multipart upload.
#         """
#         return self.bucket.complete_multipart_upload(
#             self.key_name, self.upload_id, parts
#         )
# 
# Path: qingcloud/qingstor/exception.py
# 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"]
#         except ValueError:
#             pass
#     return QSResponseError(**args)
# 
# 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)


import hashlib
import json
from base64 import b64encode
from .key import Key
from .acl import ACL
from .multipart import MultiPartUpload
from .exception import get_response_error
from .util import load_data
        if prefix:
            params["prefix"] = prefix
        if delimiter:
            params["delimiter"] = delimiter
        if marker:
            params["marker"] = marker
        if limit:
            params["limit"] = str(limit)
        response = self.connection.make_request(
            "GET", self.name, params=params)
        if response.status == 200:
            resp = load_data(response.read())
            result_set = []
            for k in resp["keys"]:
                key = Key(self, k["key"])
                key.content_type = k["mime_type"]
                result_set.append(key)
            return result_set
        else:
            err = get_response_error(response)
            raise err

    def delete(self):
        """ Delete the bucket
        """
        response = self.connection.make_request(
            "DELETE", self.name, num_retries=6)
        if response.status == 204:
            return True
        else:

# Path: qingcloud/qingstor/multipart.py
# class MultiPartUpload(object):
# 
#     def __init__(self, bucket, key_name, upload_id):
#         """
#         @param bucket - The name of the bucket
#         @param key_name - The name of the object
#         @param upload_id - ID for the initiated multipart upload
#         """
#         self.bucket = bucket
#         self.key_name = key_name
#         self.upload_id = upload_id
# 
#     def upload_part_from_file(self, fp, part_number):
#         """ Upload multipart from a file
# 
#         Keyword arguments:
#         fp - a file-like object
#         part_number - The number of the multipart
#         """
#         params = {
#             "upload_id": self.upload_id,
#             "part_number": str(part_number),
#         }
#         response = self.bucket.connection.make_request(
#             "PUT", self.bucket.name, self.key_name, data=fp, params=params)
#         if response.status == 201:
#             part = Part(self.bucket.name, self.key_name, part_number)
#             return part
#         else:
#             err = get_response_error(response)
#             raise err
# 
#     def get_all_parts(self):
#         """ Retrieve all multiparts of an object that uploaded.
#         """
#         params = {
#             "upload_id": self.upload_id,
#         }
#         response = self.bucket.connection.make_request(
#             "GET", self.bucket.name, self.key_name, params=params)
#         if response.status == 200:
#             parts = []
#             resp = load_data(response.read())
#             for item in resp["object_parts"]:
#                 part = Part(self.bucket.name, self.key_name,
#                             item["part_number"])
#                 part.size = item["size"]
#                 part.created = item["created"]
#                 parts.append(part)
#             return parts
#         else:
#             err = get_response_error(response)
#             raise err
# 
#     def cancel_upload(self):
#         """Abort the multipart upload.
#         """
#         return self.bucket.cancel_multipart_upload(
#             self.key_name, self.upload_id
#         )
# 
#     def complete_upload(self, parts):
#         """Complete the multipart upload.
#         """
#         return self.bucket.complete_multipart_upload(
#             self.key_name, self.upload_id, parts
#         )
# 
# Path: qingcloud/qingstor/exception.py
# 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"]
#         except ValueError:
#             pass
#     return QSResponseError(**args)
# 
# 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/bucket.py
import hashlib
import json
from base64 import b64encode
from .key import Key
from .acl import ACL
from .multipart import MultiPartUpload
from .exception import get_response_error
from .util import load_data

        if prefix:
            params["prefix"] = prefix
        if delimiter:
            params["delimiter"] = delimiter
        if marker:
            params["marker"] = marker
        if limit:
            params["limit"] = str(limit)
        response = self.connection.make_request(
            "GET", self.name, params=params)
        if response.status == 200:
            resp = load_data(response.read())
            result_set = []
            for k in resp["keys"]:
                key = Key(self, k["key"])
                key.content_type = k["mime_type"]
                result_set.append(key)
            return result_set
        else:
            err = get_response_error(response)
            raise err

    def delete(self):
        """ Delete the bucket
        """
        response = self.connection.make_request(
            "DELETE", self.name, num_retries=6)
        if response.status == 204:
            return True
        else:

            raise get_response_error(response)