Skip to content

Commit 15f06bf

Browse files
authored
Update cos_comm.py
fix re rule
1 parent e6659e5 commit 15f06bf

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

qcloud_cos/cos_comm.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ def format_region(region):
198198
if not region:
199199
raise CosClientError("region is required not empty!")
200200
region = to_unicode(region)
201-
if not re.match('^[A-Za-z0-9][A-Za-z0-9\-]+[A-Za-z0-9]$', region):
202-
raise CosClientError("region:%s format is illegal, only digit, letter and - is allowed!" % region)
201+
if not re.match('^[A-Za-z0-9][A-Za-z0-9.\-]*[A-Za-z0-9]$', region):
202+
raise CosClientError("region format is illegal, only digit, letter and - is allowed!")
203203
if region.find(u'cos.') != -1:
204204
return region # 传入cos.ap-beijing-1这样显示加上cos.的region
205205
if region == u'cn-north' or region == u'cn-south' or region == u'cn-east' or region == u'cn-south-2' or region == u'cn-southwest' or region == u'sg':
@@ -233,8 +233,8 @@ def format_bucket(bucket, appid):
233233
raise CosClientError("bucket is not string")
234234
if not bucket:
235235
raise CosClientError("bucket is required not empty")
236-
if not re.match('^[A-Za-z0-9][A-Za-z0-9\-]+[A-Za-z0-9]$', bucket):
237-
raise CosClientError("bucket:%s format is illegal, only digit, letter and - is allowed!" % bucket)
236+
if not (re.match('^[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]$', bucket) or re.match('^[A-Za-z0-9]$', bucket)):
237+
raise CosClientError("bucket format is illegal, only digit, letter and - is allowed!")
238238
# appid为空直接返回bucket
239239
if not appid:
240240
return to_unicode(bucket)

0 commit comments

Comments
 (0)