From e4d69a2b1b534f9d74f374ca1cfe2a0e4dc57dee Mon Sep 17 00:00:00 2001 From: tiedu Date: Sat, 28 Apr 2018 21:53:20 +0800 Subject: [PATCH] fix pep8 --- qcloud_cos/cos_client.py | 17 +++++++---------- qcloud_cos/cos_comm.py | 2 -- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/qcloud_cos/cos_client.py b/qcloud_cos/cos_client.py index 413ff74d..08c4a3d9 100644 --- a/qcloud_cos/cos_client.py +++ b/qcloud_cos/cos_client.py @@ -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): @@ -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 @@ -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': @@ -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 需要处理 @@ -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) @@ -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( @@ -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, diff --git a/qcloud_cos/cos_comm.py b/qcloud_cos/cos_comm.py index 748e3955..70f8c563 100644 --- a/qcloud_cos/cos_comm.py +++ b/qcloud_cos/cos_comm.py @@ -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)