From 13960bb2491a3e49dba96f0941af7f8e01593419 Mon Sep 17 00:00:00 2001 From: tiedu Date: Sun, 24 Jun 2018 16:43:35 +0800 Subject: [PATCH 1/4] Update cos_comm.py check bucket and region format --- qcloud_cos/cos_comm.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qcloud_cos/cos_comm.py b/qcloud_cos/cos_comm.py index 70f8c563..4bd146c5 100644 --- a/qcloud_cos/cos_comm.py +++ b/qcloud_cos/cos_comm.py @@ -6,6 +6,7 @@ import base64 import os import io +import re import sys import xml.dom.minidom import xml.etree.ElementTree @@ -193,10 +194,12 @@ def format_values(data): def format_region(region): """格式化地域""" if not isinstance(region, string_types): - raise CosClientError("bucket is not string type") + raise CosClientError("region is not string type") if not region: raise CosClientError("region is required not empty!") region = to_unicode(region) + if not re.match('^[A-Za-z0-9][A-Za-z0-9\-]+[A-Za-z0-9]$', region): + raise CosClientError("region format is illegal, only digit, letter and - is allowed!") if region.find(u'cos.') != -1: return region # 传入cos.ap-beijing-1这样显示加上cos.的region 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): raise CosClientError("bucket is not string") if not bucket: raise CosClientError("bucket is required not empty") + if not re.match('^[A-Za-z0-9][A-Za-z0-9\-]+[A-Za-z0-9]$', bucket): + raise CosClientError("bucket format is illegal, only digit, letter and - is allowed!") # appid为空直接返回bucket if not appid: return to_unicode(bucket) From 01489fe4665b328370f7361f0965cb26edb136ca Mon Sep 17 00:00:00 2001 From: tiedu Date: Sun, 24 Jun 2018 16:48:28 +0800 Subject: [PATCH 2/4] Update cos_client.py --- qcloud_cos/cos_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcloud_cos/cos_client.py b/qcloud_cos/cos_client.py index 6a0bdcc3..a8150287 100644 --- a/qcloud_cos/cos_client.py +++ b/qcloud_cos/cos_client.py @@ -149,7 +149,7 @@ def send_request(self, method, url, timeout=30, **kwargs): timeout = self._conf._timeout if self._conf._token is not None: kwargs['headers']['x-cos-security-token'] = self._conf._token - kwargs['headers']['User-Agent'] = 'cos-python-sdk-v5.1.5.0' + kwargs['headers']['User-Agent'] = 'cos-python-sdk-v5.1.5.2' kwargs['headers'] = format_values(kwargs['headers']) if 'data' in kwargs: kwargs['data'] = to_bytes(kwargs['data']) From b013d099483b02a58c97efc525cba3904b80e09d Mon Sep 17 00:00:00 2001 From: tiedu Date: Sun, 24 Jun 2018 17:02:11 +0800 Subject: [PATCH 3/4] Update cos_comm.py --- qcloud_cos/cos_comm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qcloud_cos/cos_comm.py b/qcloud_cos/cos_comm.py index 4bd146c5..13eab770 100644 --- a/qcloud_cos/cos_comm.py +++ b/qcloud_cos/cos_comm.py @@ -199,7 +199,7 @@ def format_region(region): raise CosClientError("region is required not empty!") region = to_unicode(region) if not re.match('^[A-Za-z0-9][A-Za-z0-9\-]+[A-Za-z0-9]$', region): - raise CosClientError("region format is illegal, only digit, letter and - is allowed!") + raise CosClientError("region:%s format is illegal, only digit, letter and - is allowed!" % region) if region.find(u'cos.') != -1: return region # 传入cos.ap-beijing-1这样显示加上cos.的region 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': @@ -234,7 +234,7 @@ def format_bucket(bucket, appid): if not bucket: raise CosClientError("bucket is required not empty") if not re.match('^[A-Za-z0-9][A-Za-z0-9\-]+[A-Za-z0-9]$', bucket): - raise CosClientError("bucket format is illegal, only digit, letter and - is allowed!") + raise CosClientError("bucket:%s format is illegal, only digit, letter and - is allowed!" % bucket) # appid为空直接返回bucket if not appid: return to_unicode(bucket) From 643db67ae7f329bfcaf3b1cacfa93240c66c354d Mon Sep 17 00:00:00 2001 From: tiedu Date: Sun, 24 Jun 2018 17:33:53 +0800 Subject: [PATCH 4/4] Update cos_comm.py fix re rule --- qcloud_cos/cos_comm.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qcloud_cos/cos_comm.py b/qcloud_cos/cos_comm.py index 13eab770..dd1c3c37 100644 --- a/qcloud_cos/cos_comm.py +++ b/qcloud_cos/cos_comm.py @@ -198,8 +198,8 @@ def format_region(region): if not region: raise CosClientError("region is required not empty!") region = to_unicode(region) - if not re.match('^[A-Za-z0-9][A-Za-z0-9\-]+[A-Za-z0-9]$', region): - raise CosClientError("region:%s format is illegal, only digit, letter and - is allowed!" % region) + if not re.match('^[A-Za-z0-9][A-Za-z0-9.\-]*[A-Za-z0-9]$', region): + raise CosClientError("region format is illegal, only digit, letter and - is allowed!") if region.find(u'cos.') != -1: return region # 传入cos.ap-beijing-1这样显示加上cos.的region 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): raise CosClientError("bucket is not string") if not bucket: raise CosClientError("bucket is required not empty") - if not re.match('^[A-Za-z0-9][A-Za-z0-9\-]+[A-Za-z0-9]$', bucket): - raise CosClientError("bucket:%s format is illegal, only digit, letter and - is allowed!" % bucket) + 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)): + raise CosClientError("bucket format is illegal, only digit, letter and - is allowed!") # appid为空直接返回bucket if not appid: return to_unicode(bucket)