12
12
from cos_exception import CosClientError
13
13
from cos_exception import CosServiceError
14
14
15
+ SINGLE_UPLOAD_LENGTH = 5 * 1024 * 1024 * 1024 # 单次上传文件最大为5G
15
16
# kwargs中params到http headers的映射
16
17
maplist = {
17
18
'ContentLength' : 'Content-Length' ,
@@ -165,7 +166,7 @@ def format_bucket(bucket, appid):
165
166
if not isinstance (bucket , str ):
166
167
raise CosClientError ("bucket is not str" )
167
168
# appid为空直接返回bucket
168
- if appid == "" :
169
+ if not appid :
169
170
return bucket
170
171
# appid不为空,检查是否以-appid结尾
171
172
if bucket .endswith ("-" + appid ):
@@ -175,7 +176,7 @@ def format_bucket(bucket, appid):
175
176
176
177
def get_copy_source_info (CopySource ):
177
178
"""获取拷贝源的所有信息"""
178
- appid = None
179
+ appid = ""
179
180
if 'Appid' in CopySource .keys ():
180
181
appid = CopySource ['Appid' ]
181
182
if 'Bucket' in CopySource .keys ():
@@ -190,8 +191,6 @@ def get_copy_source_info(CopySource):
190
191
raise CosClientError ('CopySource Need Parameter Region' )
191
192
if 'Key' in CopySource .keys ():
192
193
path = CopySource ['Key' ]
193
- if path and path [0 ] == '/' :
194
- path = path [1 :]
195
194
else :
196
195
raise CosClientError ('CopySource Need Parameter Key' )
197
196
return bucket , path , region
@@ -200,9 +199,20 @@ def get_copy_source_info(CopySource):
200
199
def gen_copy_source_url (CopySource ):
201
200
"""拼接拷贝源url"""
202
201
bucket , path , region = get_copy_source_info (CopySource )
202
+ if path and path [0 ] == '/' :
203
+ path = path [1 :]
203
204
url = "{bucket}.{region}.myqcloud.com/{path}" .format (
204
205
bucket = bucket ,
205
206
region = region ,
206
207
path = path
207
208
)
208
209
return url
210
+
211
+
212
+ def gen_copy_source_range (begin_range , end_range ):
213
+ """拼接bytes=begin-end形式的字符串"""
214
+ range = "bytes={first}-{end}" .format (
215
+ first = begin_range ,
216
+ end = end_range
217
+ )
218
+ return range
0 commit comments