@@ -42,7 +42,7 @@ class CosConfig(object):
4242
4343 def __init__ (self , Appid = None , Region = None , SecretId = None , SecretKey = None , Token = None , CredentialInstance = None , Scheme = None , Timeout = None ,
4444 Access_id = None , Access_key = None , Secret_id = None , Secret_key = None , Endpoint = None , IP = None , Port = None ,
45- Anonymous = None , UA = None , Proxies = None , Domain = None , ServiceDomain = None , PoolConnections = 10 ,
45+ Anonymous = None , UA = None , Proxies = None , Domain = None , ServiceDomain = None , KeepAlive = True , PoolConnections = 10 ,
4646 PoolMaxSize = 10 , AllowRedirects = False , SignHost = True , EndpointCi = None , EndpointPic = None , EnableOldDomain = True , EnableInternalDomain = True ):
4747 """初始化,保存用户的信息
4848
@@ -65,6 +65,7 @@ def __init__(self, Appid=None, Region=None, SecretId=None, SecretKey=None, Token
6565 :param Proxies(dict): 使用代理来访问COS
6666 :param Domain(string): 使用自定义的域名来访问COS
6767 :param ServiceDomain(string): 使用自定义的域名来访问cos service
68+ :param KeepAlive(bool): 是否使用长连接
6869 :param PoolConnections(int): 连接池个数
6970 :param PoolMaxSize(int): 连接池中最大连接数
7071 :param AllowRedirects(bool): 是否重定向
@@ -87,6 +88,7 @@ def __init__(self, Appid=None, Region=None, SecretId=None, SecretKey=None, Token
8788 self ._proxies = Proxies
8889 self ._domain = Domain
8990 self ._service_domain = ServiceDomain
91+ self ._keep_alive = KeepAlive
9092 self ._pool_connections = PoolConnections
9193 self ._pool_maxsize = PoolMaxSize
9294 self ._allow_redirects = AllowRedirects
@@ -332,6 +334,8 @@ def send_request(self, method, url, bucket, timeout=30, cos_request=True, **kwar
332334 kwargs ['headers' ]['Host' ] = self ._conf ._domain
333335 elif bucket is not None :
334336 kwargs ['headers' ]['Host' ] = self ._conf .get_host (bucket )
337+ if self ._conf ._keep_alive == False :
338+ kwargs ['headers' ]['Connection' ] = 'close'
335339 kwargs ['headers' ] = format_values (kwargs ['headers' ])
336340
337341 file_position = None
@@ -1273,7 +1277,7 @@ def select_object_content(self, Bucket, Key, Expression, ExpressionType, InputSe
12731277 return data
12741278
12751279 # s3 bucket interface begin
1276- def create_bucket (self , Bucket , BucketAZConfig = None , ** kwargs ):
1280+ def create_bucket (self , Bucket , BucketAZConfig = None , BucketArchConfig = None , ** kwargs ):
12771281 """创建一个bucket
12781282
12791283 :param Bucket(string): 存储桶名称. 存储桶名称不支持大写字母,COS 后端会将用户传入的大写字母自动转换为小写字母用于创建存储桶.
@@ -1297,11 +1301,16 @@ def create_bucket(self, Bucket, BucketAZConfig=None, **kwargs):
12971301 """
12981302 headers = mapped (kwargs )
12991303 xml_config = None
1304+ bucket_config = dict ()
13001305 if BucketAZConfig == 'MAZ' :
1301- bucket_config = {'BucketAZConfig' : 'MAZ' }
1306+ bucket_config .update ({'BucketAZConfig' : 'MAZ' })
1307+ if BucketArchConfig == 'OFS' :
1308+ bucket_config .update ({'BucketArchConfig' : 'OFS' })
1309+ if len (bucket_config ) != 0 :
13021310 xml_config = format_xml (data = bucket_config , root = 'CreateBucketConfiguration' )
13031311 headers ['Content-MD5' ] = get_md5 (xml_config )
13041312 headers ['Content-Type' ] = 'application/xml'
1313+
13051314 url = self ._conf .uri (bucket = Bucket )
13061315 logger .info ("create bucket, url=:{url} ,headers=:{headers}" .format (
13071316 url = url ,
@@ -3531,8 +3540,8 @@ def download_file(self, Bucket, Key, DestFilePath, PartSize=20, MAXThread=5, Ena
35313540
35323541 def upload_file (self , Bucket , Key , LocalFilePath , PartSize = 1 , MAXThread = 5 , EnableMD5 = False , progress_callback = None ,
35333542 ** kwargs ):
3534- """小于等于20MB的文件简单上传,大于20MB的文件使用分块上传
35353543
3544+ """
35363545 :param Bucket(string): 存储桶名称.
35373546 :param key(string): 分块上传路径名.
35383547 :param LocalFilePath(string): 本地文件路径名.
@@ -3557,7 +3566,7 @@ def upload_file(self, Bucket, Key, LocalFilePath, PartSize=1, MAXThread=5, Enabl
35573566 )
35583567 """
35593568 file_size = os .path .getsize (LocalFilePath )
3560- if file_size <= 1024 * 1024 * 20 :
3569+ if file_size <= 1024 * 1024 * PartSize :
35613570 with open (LocalFilePath , 'rb' ) as fp :
35623571 rt = self .put_object (Bucket = Bucket , Key = Key , Body = fp , EnableMD5 = EnableMD5 , ** kwargs )
35633572 return rt
@@ -7012,9 +7021,9 @@ def ci_list_workflowexecution(self, Bucket, WorkflowId, Name='', StartCreationTi
70127021 NextToken = to_unicode ('nextToken=' + NextToken )
70137022 )
70147023 if StartCreationTime is not None :
7015- url = u"{url}&{StartCreationTime}" .format (StartCreationTime = to_unicode ('startCreationTime=' + StartCreationTime ))
7024+ url = u"{url}&{StartCreationTime}" .format (url = to_unicode ( url ), StartCreationTime = quote ( to_bytes ( to_unicode ('startCreationTime=' + StartCreationTime )), b'/-_.~=' ))
70167025 if EndCreationTime is not None :
7017- url = u"{url}&{EndCreationTime}" .format (EndCreationTime = to_unicode ('endCreationTime=' + EndCreationTime ))
7026+ url = u"{url}&{EndCreationTime}" .format (url = to_unicode ( url ), EndCreationTime = quote ( to_bytes ( to_unicode ('endCreationTime=' + EndCreationTime )), b'/-_.~=' ))
70187027 logger .info ("ci_list_workflowexecution result, url=:{url} ,headers=:{headers}, params=:{params}" .format (
70197028 url = url ,
70207029 headers = headers ,
@@ -7518,9 +7527,11 @@ def ci_list_doc_jobs(self, Bucket, QueueId, StartCreationTime=None, EndCreationT
75187527 NextToken = to_unicode ('nextToken=' + NextToken )
75197528 )
75207529 if StartCreationTime is not None :
7521- url = u"{url}&{StartCreationTime}" .format (StartCreationTime = to_unicode ('startCreationTime=' + StartCreationTime ))
7530+ url = u"{url}&{StartCreationTime}" .format (url = to_unicode (url ),
7531+ StartCreationTime = quote (to_bytes (to_unicode ('startCreationTime=' + StartCreationTime )), b'/-_.~=' ))
75227532 if EndCreationTime is not None :
7523- url = u"{url}&{EndCreationTime}" .format (EndCreationTime = to_unicode ('endCreationTime=' + EndCreationTime ))
7533+ url = u"{url}&{EndCreationTime}" .format (url = to_unicode (url ),
7534+ EndCreationTime = quote (to_bytes (to_unicode ('endCreationTime=' + EndCreationTime )), b'/-_.~=' ))
75247535 logger .info ("list_doc_jobs result, url=:{url} ,headers=:{headers}, params=:{params}" .format (
75257536 url = url ,
75267537 headers = headers ,
@@ -8130,9 +8141,11 @@ def ci_list_asr_jobs(self, Bucket, QueueId, StartCreationTime=None, EndCreationT
81308141 NextToken = to_unicode ('nextToken=' + NextToken )
81318142 )
81328143 if StartCreationTime is not None :
8133- url = u"{url}&{StartCreationTime}" .format (StartCreationTime = to_unicode ('startCreationTime=' + StartCreationTime ))
8144+ url = u"{url}&{StartCreationTime}" .format (url = to_unicode (url ),
8145+ StartCreationTime = quote (to_bytes (to_unicode ('startCreationTime=' + StartCreationTime )), b'/-_.~=' ))
81348146 if EndCreationTime is not None :
8135- url = u"{url}&{EndCreationTime}" .format (EndCreationTime = to_unicode ('endCreationTime=' + EndCreationTime ))
8147+ url = u"{url}&{EndCreationTime}" .format (url = to_unicode (url ),
8148+ EndCreationTime = quote (to_bytes (to_unicode ('endCreationTime=' + EndCreationTime )), b'/-_.~=' ))
81368149 logger .info ("list_asr_jobs result, url=:{url} ,headers=:{headers}, params=:{params}" .format (
81378150 url = url ,
81388151 headers = headers ,
0 commit comments