Skip to content

Commit

Permalink
fix pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
dt3310321 committed Apr 28, 2018
1 parent e8de48a commit e4d69a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
17 changes: 7 additions & 10 deletions qcloud_cos/cos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

logger = logging.getLogger(__name__)


class CosConfig(object):
"""config类,保存用户相关信息"""
def __init__(self, Appid=None, Region=None, Secret_id=None, Secret_key=None, Token=None, Scheme=None, Timeout=None, Access_id=None, Access_key=None):
Expand Down Expand Up @@ -61,7 +62,6 @@ def __init__(self, Appid=None, Region=None, Secret_id=None, Secret_key=None, Tok
else:
raise CosClientError('SecretId and SecretKey is Required!')


def uri(self, bucket, path=None, scheme=None, region=None):
"""拼接url
Expand Down Expand Up @@ -153,8 +153,8 @@ def send_request(self, method, url, timeout=30, **kwargs):
kwargs['headers'] = format_values(kwargs['headers'])
if 'data' in kwargs:
kwargs['data'] = to_bytes(kwargs['data'])
#try:
for j in range(self._retry):
try:
for j in range(self._retry):
if method == 'POST':
res = self._session.post(url, timeout=timeout, **kwargs)
elif method == 'GET':
Expand All @@ -167,9 +167,9 @@ def send_request(self, method, url, timeout=30, **kwargs):
res = self._session.head(url, timeout=timeout, **kwargs)
if res.status_code < 400: # 2xx和3xx都认为是成功的
return res
#except Exception as e: # 捕获requests抛出的如timeout等客户端错误,转化为客户端错误
#logger.exception('url:%s, exception:%s' % (url, str(e)))
#raise CosClientError(str(e))
except Exception as e: # 捕获requests抛出的如timeout等客户端错误,转化为客户端错误
logger.exception('url:%s, exception:%s' % (url, str(e)))
raise CosClientError(str(e))

if res.status_code >= 400: # 所有的4XX,5XX都认为是COSServiceError
if method == 'HEAD' and res.status_code == 404: # Head 需要处理
Expand Down Expand Up @@ -262,13 +262,11 @@ def get_object(self, Bucket, Key, **kwargs):
params[key] = headers[key]
else:
final_headers[key] = headers[key]

headers = final_headers

if 'versionId' in headers:
params['versionId'] = headers['versionId']
del headers['versionId']

params = format_values(params)

url = self._conf.uri(bucket=Bucket, path=Key)
Expand Down Expand Up @@ -717,7 +715,6 @@ def list_parts(self, Bucket, Key, UploadId, EncodingType='', MaxParts=1000, Part
decodeflag = False
else:
params['encoding-type'] = 'url'

params = format_values(params)
url = self._conf.uri(bucket=Bucket, path=Key)
logger.info("list multipart upload parts, url=:{url} ,headers=:{headers}".format(
Expand Down Expand Up @@ -2180,7 +2177,7 @@ def append_object(self, Bucket, Key, Position, Data, **kwargs):
:return(dict): 上传成功返回的结果,包含ETag等信息.
"""
headers = mapped(kwargs)
params = {'append': '', 'position': Position}
params = {'append': '', 'position': Position}
url = self._conf.uri(bucket=Bucket, path=Key)
logger.info("append object, url=:{url} ,headers=:{headers}".format(
url=url,
Expand Down
2 changes: 0 additions & 2 deletions qcloud_cos/cos_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ def to_bytes(s):
return s


def format_bytes():
"""将需要传输的内容转换为bytes, body以及header的values"""
def get_raw_md5(data):
"""计算md5 md5的输入必须为bytes"""
data = to_bytes(data)
Expand Down

0 comments on commit e4d69a2

Please sign in to comment.