Skip to content

Commit 953bac4

Browse files
authored
Merge pull request tencentyun#53 from dt3310321/s3
S3
2 parents d2dbc7a + 3357c98 commit 953bac4

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

qcloud_cos/cos_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def send_request(self, method, url, timeout=30, **kwargs):
149149
timeout = self._conf._timeout
150150
if self._conf._token is not None:
151151
kwargs['headers']['x-cos-security-token'] = self._conf._token
152-
kwargs['headers']['User-Agent'] = 'cos-python-sdk-v5.1.5.1'
152+
kwargs['headers']['User-Agent'] = 'cos-python-sdk-v5.1.5.2'
153153
kwargs['headers'] = format_values(kwargs['headers'])
154154
if 'data' in kwargs:
155155
kwargs['data'] = to_bytes(kwargs['data'])

qcloud_cos/cos_comm.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import base64
77
import os
88
import io
9+
import re
910
import sys
1011
import xml.dom.minidom
1112
import xml.etree.ElementTree
@@ -193,10 +194,12 @@ def format_values(data):
193194
def format_region(region):
194195
"""格式化地域"""
195196
if not isinstance(region, string_types):
196-
raise CosClientError("bucket is not string type")
197+
raise CosClientError("region is not string type")
197198
if not region:
198199
raise CosClientError("region is required not empty!")
199200
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 format is illegal, only digit, letter and - is allowed!")
200203
if region.find(u'cos.') != -1:
201204
return region # 传入cos.ap-beijing-1这样显示加上cos.的region
202205
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':
@@ -230,6 +233,8 @@ def format_bucket(bucket, appid):
230233
raise CosClientError("bucket is not string")
231234
if not bucket:
232235
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) or re.match('^[A-Za-z0-9]$', bucket)):
237+
raise CosClientError("bucket format is illegal, only digit, letter and - is allowed!")
233238
# appid为空直接返回bucket
234239
if not appid:
235240
return to_unicode(bucket)

0 commit comments

Comments
 (0)