Skip to content

Commit

Permalink
Merge pull request #53 from dt3310321/s3
Browse files Browse the repository at this point in the history
S3
  • Loading branch information
dt3310321 authored Jun 24, 2018
2 parents 5ef7431 + ca3d606 commit fe4e88b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion qcloud_cos/cos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.1'
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'])
Expand Down
7 changes: 6 additions & 1 deletion qcloud_cos/cos_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import base64
import os
import io
import re
import sys
import xml.dom.minidom
import xml.etree.ElementTree
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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) 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)
Expand Down

0 comments on commit fe4e88b

Please sign in to comment.