# Path: qiniuyun/utils.py
# class QiniuError(IOError):
#     def __init__(self, value):
#         if isinstance("Debuf Info", ResponseInfo):
#             super(QiniuError, self).__init__(
#                 "Qiniu Response Info %s" % value
#             )
#         else:
#             super(QiniuError, self).__init__(value)
# 
# def bucket_lister(manager, bucket_name, prefix=None, marker=None, limit=None):
#     """
#     A generator function for listing keys in a bucket.
#     """
#     eof = False
#     while not eof:
#         ret, eof, info = manager.list(bucket_name, prefix=prefix, limit=limit,
#                                       marker=marker)
#         if ret is None:
#             raise QiniuError(info)
#         if not eof:
#             marker = ret['marker']
# 
#         for item in ret['items']:
#             yield item


from qiniu import Auth,put_file,put_data,BucketManager
from .utils import QiniuError, bucket_lister
from os.path import basename,splitext
from datetime import datetime
            key: 七牛云上的文件名                                    
        @ret:域名加文件名生成的url路径
        '''   
        url='http://{}/{}'.format(self.bucket_domain,key)
        return url 

    def private_download_url(self,url,expires=7200):
        """
        @def:private_download_url
        @def_fun: 生成私有资源下载链接                                       
        @para:            
            url: 私有空间资源的原始URL   
            expires: 下载凭证有效期，默认为7200s                     
        @ret:私有资源的下载链接        
        """               
        return self.auth.private_download_url(url,expires)
                    
    def put_file(self,filePath):
        """
        @def:put_file
        @def_fun: 本地文件上传
            空间里的文件名不能重复，所以用_newname生成新文件名                                  
        @para:            
            filePath: 待上传文件在磁盘中的绝对路径                              
        @ret:上传后的url路径        
        """
        key = self._newname(filePath)  
        token=self.auth.upload_token(self.bucket_name,key) 
        ret, info = put_file(token, key, filePath)  
        if ret is None or ret['key'] != key:

# Path: qiniuyun/utils.py
# class QiniuError(IOError):
#     def __init__(self, value):
#         if isinstance("Debuf Info", ResponseInfo):
#             super(QiniuError, self).__init__(
#                 "Qiniu Response Info %s" % value
#             )
#         else:
#             super(QiniuError, self).__init__(value)
# 
# def bucket_lister(manager, bucket_name, prefix=None, marker=None, limit=None):
#     """
#     A generator function for listing keys in a bucket.
#     """
#     eof = False
#     while not eof:
#         ret, eof, info = manager.list(bucket_name, prefix=prefix, limit=limit,
#                                       marker=marker)
#         if ret is None:
#             raise QiniuError(info)
#         if not eof:
#             marker = ret['marker']
# 
#         for item in ret['items']:
#             yield item


# Path: qiniuyun/qiniustorage.py
from qiniu import Auth,put_file,put_data,BucketManager
from .utils import QiniuError, bucket_lister
from os.path import basename,splitext
from datetime import datetime

            key: 七牛云上的文件名                                    
        @ret:域名加文件名生成的url路径
        '''   
        url='http://{}/{}'.format(self.bucket_domain,key)
        return url 

    def private_download_url(self,url,expires=7200):
        """
        @def:private_download_url
        @def_fun: 生成私有资源下载链接                                       
        @para:            
            url: 私有空间资源的原始URL   
            expires: 下载凭证有效期，默认为7200s                     
        @ret:私有资源的下载链接        
        """               
        return self.auth.private_download_url(url,expires)
                    
    def put_file(self,filePath):
        """
        @def:put_file
        @def_fun: 本地文件上传
            空间里的文件名不能重复，所以用_newname生成新文件名                                  
        @para:            
            filePath: 待上传文件在磁盘中的绝对路径                              
        @ret:上传后的url路径        
        """
        key = self._newname(filePath)  
        token=self.auth.upload_token(self.bucket_name,key) 
        ret, info = put_file(token, key, filePath)  
        if ret is None or ret['key'] != key:

            raise QiniuError(info)