Пример #1
0
    async def delete_bucket(self):
        """删除一个Bucket。只有没有任何文件,也没有任何未完成的分片上传的Bucket才能被删除。

        :return: :class:`RequestResult <oss2.models.RequestResult>`

        ":raises: 如果试图删除一个非空Bucket,则抛出 :class:`BucketNotEmpty <oss2.exceptions.BucketNotEmpty>`
        """
        resp = await self.__do_bucket('DELETE')
        return models.RequestResult(resp)
Пример #2
0
    async def delete_object(self, key):
        """删除一个文件。

        :param str key: 文件名

        :return: :class:`RequestResult <oss2.models.RequestResult>`
        """
        resp = await self.__do_object('DELETE', key)
        return models.RequestResult(resp)
Пример #3
0
    async def delete_live_channel(self, channel_name):
        """删除推流直播频道

        :param str channel_name: 要删除的live channel的名称
        """
        resp = await self.__do_object('DELETE',
                                      channel_name,
                                      params={Bucket.LIVE: ''})
        return models.RequestResult(resp)
Пример #4
0
    async def put_bucket_acl(self, permission):
        """设置Bucket的ACL。

        :param str permission: 新的ACL,可以是oss2.BUCKET_ACL_PRIVATE、oss2.BUCKET_ACL_PUBLIC_READ或
            oss2.BUCKET_ACL_PUBLIC_READ_WRITE
        """
        resp = await self.__do_bucket('PUT',
                                      headers={'x-oss-acl': permission},
                                      params={Bucket.ACL: ''})
        return models.RequestResult(resp)
Пример #5
0
    async def put_bucket_referer(self, input):
        """为Bucket设置防盗链。

        :param input: :class:`BucketReferer <oss2.models.BucketReferer>` 对象或其他
        """
        data = self.__convert_data(models.BucketReferer,
                                   xml_utils.to_put_bucket_referer, input)
        resp = await self.__do_bucket('PUT',
                                      data=data,
                                      params={Bucket.REFERER: ''})
        return models.RequestResult(resp)
Пример #6
0
    async def put_bucket_website(self, input):
        """为Bucket配置静态网站托管功能。

        :param input: :class:`BucketWebsite <oss2.models.BucketWebsite>`
        """
        data = self.__convert_data(models.BucketWebsite,
                                   xml_utils.to_put_bucket_website, input)
        resp = await self.__do_bucket('PUT',
                                      data=data,
                                      params={Bucket.WEBSITE: ''})
        return models.RequestResult(resp)
Пример #7
0
    async def put_bucket_logging(self, input):
        """设置Bucket的访问日志功能。

        :param input: :class:`BucketLogging <oss2.models.BucketLogging>` 对象或其他
        """
        data = self.__convert_data(models.BucketLogging,
                                   xml_utils.to_put_bucket_logging, input)
        resp = await self.__do_bucket('PUT',
                                      data=data,
                                      params={Bucket.LOGGING: ''})
        return models.RequestResult(resp)
Пример #8
0
    async def put_bucket_lifecycle(self, input):
        """设置生命周期管理的配置。

        :param input: :class:`BucketLifecycle <oss2.models.BucketLifecycle>` 对象或其他
        """
        data = self.__convert_data(models.BucketLifecycle,
                                   xml_utils.to_put_bucket_lifecycle, input)
        resp = await self.__do_bucket('PUT',
                                      data=data,
                                      params={Bucket.LIFECYCLE: ''})
        return models.RequestResult(resp)
Пример #9
0
    async def put_bucket_cors(self, input):
        """设置Bucket的CORS。

        :param input: :class:`BucketCors <oss2.models.BucketCors>` 对象或其他
        """
        data = self.__convert_data(models.BucketCors,
                                   xml_utils.to_put_bucket_cors, input)
        resp = await self.__do_bucket('PUT',
                                      data=data,
                                      params={Bucket.CORS: ''})
        return models.RequestResult(resp)
Пример #10
0
    async def abort_multipart_upload(self, key, upload_id):
        """取消分片上传。

        :param str key: 待上传的文件名,这个文件名要和 :func:`init_multipart_upload` 的文件名一致。
        :param str upload_id: 分片上传ID

        :return: :class:`RequestResult <oss2.models.RequestResult>`
        """
        resp = await self.__do_object('DELETE',
                                      key,
                                      params={'uploadId': upload_id})
        return models.RequestResult(resp)
Пример #11
0
    async def put_live_channel_status(self, channel_name, status):
        """更改live channel的status,仅能在“enabled”和“disabled”两种状态中更改

        param str channel_name: 要更改status的live channel的名称
        param str status: live channel的目标status
        """
        resp = await self.__do_object('PUT',
                                      channel_name,
                                      params={
                                          Bucket.LIVE: '',
                                          Bucket.STATUS: status
                                      })
        return models.RequestResult(resp)
Пример #12
0
    async def put_object_acl(self, key, permission):
        """设置文件的ACL。

        :param str key: 文件名
        :param str permission: 可以是oss2.OBJECT_ACL_DEFAULT、oss2.OBJECT_ACL_PRIVATE、oss2.OBJECT_ACL_PUBLIC_READ或
            oss2.OBJECT_ACL_PUBLIC_READ_WRITE。

        :return: :class:`RequestResult <oss2.models.RequestResult>`
        """
        resp = await self.__do_object('PUT',
                                      key,
                                      params={'acl': ''},
                                      headers={'x-oss-object-acl': permission})
        return models.RequestResult(resp)
Пример #13
0
    async def put_symlink(self, target_key, symlink_key, headers=None):
        """创建Symlink。

        :param str target_key: 目标文件,目标文件不能为符号连接
        :param str symlink_key: 符号连接类文件,其实质是一个特殊的文件,数据指向目标文件

        :return: :class:`RequestResult <oss2.models.RequestResult>`
        """
        headers = headers or {}
        headers['x-oss-symlink-target'] = urlquote(target_key, '')
        resp = await self.__do_object('PUT',
                                      symlink_key,
                                      headers=headers,
                                      params={Bucket.SYMLINK: ''})
        return models.RequestResult(resp)
Пример #14
0
    async def create_bucket(self, permission=None, input=None):
        """创建新的Bucket。

        :param str permission: 指定Bucket的ACL。可以是oss2.BUCKET_ACL_PRIVATE(推荐、缺省)、oss2.BUCKET_ACL_PUBLIC_READ或是
            oss2.BUCKET_ACL_PUBLIC_READ_WRITE。

        :param input: :class:`BucketCreateConfig <oss2.models.BucketCreateConfig>` object
        """
        if permission:
            headers = {'x-oss-acl': permission}
        else:
            headers = None

        data = self.__convert_data(models.BucketCreateConfig,
                                   xml_utils.to_put_bucket_config, input)
        resp = await self.__do_bucket('PUT', headers=headers, data=data)
        return models.RequestResult(resp)
Пример #15
0
    async def post_vod_playlist(self,
                                channel_name,
                                playlist_name,
                                start_time=0,
                                end_time=0):
        """根据指定的playlist name以及startTime和endTime生成一个点播的播放列表

        param str channel_name: 要生成点播列表的live channel的名称
        param str playlist_name: 要生成点播列表m3u8文件的名称
        param int start_time: 点播的起始时间,Unix Time格式,可以使用int(time.time())获取
        param int end_time: 点播的结束时间,Unix Time格式,可以使用int(time.time())获取
        """
        key = channel_name + "/" + playlist_name
        resp = await self.__do_object('POST',
                                      key,
                                      params={
                                          Bucket.VOD: '',
                                          'startTime': str(start_time),
                                          'endTime': str(end_time)
                                      })
        return models.RequestResult(resp)
Пример #16
0
    async def restore_object(self, key):
        """restore an object
            如果是第一次针对该object调用接口,返回RequestResult.status = 202;
            如果已经成功调用过restore接口,且服务端仍处于解冻中,抛异常RestoreAlreadyInProgress(status=409)
            如果已经成功调用过restore接口,且服务端解冻已经完成,再次调用时返回RequestResult.status = 200,且会将object的可下载时间延长一天,最多延长7天。
            如果object不存在,则抛异常NoSuchKey(status=404);
            对非Archive类型的Object提交restore,则抛异常OperationNotSupported(status=400)

            也可以通过调用head_object接口来获取meta信息来判断是否可以restore与restore的状态
            代码示例::
            >>> meta = await bucket.head_object(key)
            >>> if meta.resp.headers['x-oss-storage-class'] == oss2.BUCKET_STORAGE_CLASS_ARCHIVE:
            >>>     bucket.restore_object(key)
            >>>         while True:
            >>>             meta = await bucket.head_object(key)
            >>>             if meta.resp.headers['x-oss-restore'] == 'ongoing-request="true"':
            >>>                 time.sleep(5)
            >>>             else:
            >>>                 break
        :param str key: object name
        :return: :class:`RequestResult <oss2.models.RequestResult>`
        """
        resp = await self.__do_object('POST', key, params={'restore': ''})
        return models.RequestResult(resp)
Пример #17
0
 async def delete_bucket_logging(self):
     """关闭Bucket的访问日志功能。"""
     resp = await self.__do_bucket('DELETE', params={Bucket.LOGGING: ''})
     return models.RequestResult(resp)
Пример #18
0
 async def delete_bucket_lifecycle(self):
     """删除生命周期管理配置。如果Lifecycle没有设置,也返回成功。"""
     resp = await self.__do_bucket('DELETE', params={Bucket.LIFECYCLE: ''})
     return models.RequestResult(resp)
Пример #19
0
 async def delete_bucket_cors(self):
     """删除Bucket的CORS配置。"""
     resp = await self.__do_bucket('DELETE', params={Bucket.CORS: ''})
     return models.RequestResult(resp)
Пример #20
0
 async def delete_bucket_website(self):
     """关闭Bucket的静态网站托管功能。"""
     resp = await self.__do_bucket('DELETE', params={Bucket.WEBSITE: ''})
     return models.RequestResult(resp)