# 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
        """                                      
        @para:            
            access_key:公钥    
            secret_key:私钥                 
            bucket_name: 要上传的空间
            bucket_domain:获取文件url路径时对应的私有域名
        """ 
        self.auth=Auth(access_key,secret_key)
        self.bucket_name = bucket_name
        self.bucket_domain = bucket_domain
        self.bucket_manager = BucketManager(self.auth)
    
    def put_data(self,name,data):
        """
        @def:put_data
        @def_fun: 文件流上传
            空间里的文件名不能重复，所以用_newname生成新文件名                                  
        @para:            
            name: 文件名   
            data: 上传二进制流                      
        @ret:上传后的url路径        
        """               
        #上传到七牛后保存的文件名
        key = self._newname(name)  
        #生成上传 Token，可以指定过期时间等
        token=self.auth.upload_token(self.bucket_name,key) 
        if hasattr(data,'chunks'):
            data = b''.join(c for c in data.chunks())
        ret, info = put_data(token, key, data)  #上传文件流到七牛
        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

        """                                      
        @para:            
            access_key:公钥    
            secret_key:私钥                 
            bucket_name: 要上传的空间
            bucket_domain:获取文件url路径时对应的私有域名
        """ 
        self.auth=Auth(access_key,secret_key)
        self.bucket_name = bucket_name
        self.bucket_domain = bucket_domain
        self.bucket_manager = BucketManager(self.auth)
    
    def put_data(self,name,data):
        """
        @def:put_data
        @def_fun: 文件流上传
            空间里的文件名不能重复，所以用_newname生成新文件名                                  
        @para:            
            name: 文件名   
            data: 上传二进制流                      
        @ret:上传后的url路径        
        """               
        #上传到七牛后保存的文件名
        key = self._newname(name)  
        #生成上传 Token，可以指定过期时间等
        token=self.auth.upload_token(self.bucket_name,key) 
        if hasattr(data,'chunks'):
            data = b''.join(c for c in data.chunks())
        ret, info = put_data(token, key, data)  #上传文件流到七牛
        if ret is None or ret['key'] != key:

            raise QiniuError(info)