Skip to content

Commit

Permalink
upload 3.19.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
chewaiwai committed Jul 11, 2019
1 parent 5c04ae5 commit f6ae57b
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 523 deletions.
35 changes: 0 additions & 35 deletions Help on License

This file was deleted.

3 changes: 2 additions & 1 deletion examples/bucket_operations_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ def doBucketQuotaOperation():
# resp = obsClient.getBucketQuota(bucketName)
resp = bucketClient.getBucketQuota()

print('Getting bucket quota ' + str(resp.body) + ' \n')
print('Getting bucket quota ' + str(resp.body) + ' \n')


def doBucketVersioningOperation():
# print('Getting bucket versioning config ' + str(obsClient.getBucketVersioning(bucketName).body) + ' \n')
print('Getting bucket versioning config ' + str(bucketClient.getBucketVersioning().body) + ' \n')
Expand Down
2 changes: 1 addition & 1 deletion examples/obs_python_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
bucketName = 'my-obs-bucket-demo'

# create ObsClient instance
obsClient = ObsClient(access_key_id=AK, secret_access_key=SK, server='http://yweywyeewoi')
obsClient = ObsClient(access_key_id=AK, secret_access_key=SK, server=server)
bucketClient = obsClient.bucketClient(bucketName)

# init log
Expand Down
Binary file added release/huaweicloud-obs-sdk-python_3.19.5.1.zip
Binary file not shown.
30 changes: 0 additions & 30 deletions src/obs/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,5 @@ def set(self, key, value):
self.weak[key] = strongRef = self.Dict(value)
self.strong.append(strongRef)

class _LocalCacheProcess(object):

def __init__(self, maxlen=10):
import multiprocessing, atexit
self._mgr = multiprocessing.Manager()
self.weak = self._mgr.dict()
atexit.register(self.close)

@staticmethod
def nowTime():
return int(time.time())

def get(self, key):
value = self.weak.get(key)
if value is not None and hasattr(value, 'expire') and self.nowTime() > value['expire']:
del self.weak[key]
value = None
return value

def set(self, key, value):
self.weak[key] = value

def close(self):
if self._mgr:
try:
self._mgr.shutdown()
self._mgr = None
except:
pass


LocalCache = _LocalCacheThread
29 changes: 20 additions & 9 deletions src/obs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ def __init__(self, access_key_id, secret_access_key, is_secure=True, server=None
port=None, max_retry_count=3, timeout=60, chunk_size=65536,
long_conn_mode=False, proxy_host=None, proxy_port=None,
proxy_username=None, proxy_password=None, security_token=None,
custom_ciphers=None, use_http2=False, is_signature_negotiation=True, is_cname=False):
custom_ciphers=None, use_http2=False, is_signature_negotiation=True, is_cname=False,
max_redirect_count=10):
self.securityProvider = _SecurityProvider(access_key_id, secret_access_key, security_token)
server = server if server is not None else ''
server = util.to_string(util.safe_encode(server))
Expand Down Expand Up @@ -212,6 +213,7 @@ def __init__(self, access_key_id, secret_access_key, is_secure=True, server=None
self.use_http2 = use_http2
self.is_signature_negotiation = is_signature_negotiation
self.is_cname = is_cname
self.max_redirect_count = max_redirect_count

if self.path_style or self.is_cname:
self.is_signature_negotiation = False
Expand Down Expand Up @@ -332,9 +334,17 @@ def _make_post_request(self, bucketName, objectKey=None, pathArgs=None, headers=
def _make_put_request(self, bucketName, objectKey=None, pathArgs=None, headers=None, entity=None, chunkedMode=False, methodName=None, readable=False):
return self._make_request_with_retry(const.HTTP_METHOD_PUT, bucketName, objectKey, pathArgs, headers, entity, chunkedMode, methodName=methodName, readable=readable)

def _make_error_result(self, e, ret):
self.log_client.log(ERROR, 'request error, %s' % e)
self.log_client.log(ERROR, traceback.format_exc())
if ret is not None:
return ret
raise e

def _make_request_with_retry(self, methodType, bucketName, objectKey=None, pathArgs=None, headers=None,
entity=None, chunkedMode=False, methodName=None, readable=False, parseMethod=None, redirectLocation=None, skipAuthentication=False):
flag = 0
redirect_count = 0
conn = None
_redirectLocation = redirectLocation
while True:
Expand All @@ -349,16 +359,16 @@ def _make_request_with_retry(self, methodType, bucketName, objectKey=None, pathA
else:
util.close_conn(conn, self.log_client)
if isinstance(e, _RedirectException):
redirect_count += 1
_redirectLocation = e.location
flag -= 1
ret = e.result

if redirect_count >= self.max_redirect_count:
self.log_client.log(ERROR, 'request redirect count [%d] greater than max redirect count [%d]' % (
redirect_count, self.max_redirect_count))
return self._make_error_result(e, ret)
if flag >= self.max_retry_count or readable:
self.log_client.log(ERROR, 'request error, %s' % e)
self.log_client.log(ERROR, traceback.format_exc())
if ret is not None:
return ret
raise e
return self._make_error_result(e, ret)
flag += 1
time.sleep(math.pow(2, flag) * 0.05)
self.log_client.log(WARNING, 'request again, time:%d' % int(flag))
Expand Down Expand Up @@ -769,6 +779,7 @@ def _parse_xml_internal(self, result, methodName=None, chuckSize=65536, readable
break
xml = chunk if xml is None else xml + chunk
header = self._rename_response_headers(headers)
indicator = headers.get(self.ha.indicator_header())
if status < 300:
if methodName is not None:
parseMethod = getattr(self.convertor, 'parse' + methodName[:1].upper() + methodName[1:])
Expand Down Expand Up @@ -799,7 +810,7 @@ def _parse_xml_internal(self, result, methodName=None, chuckSize=65536, readable

if not requestId:
requestId = headers.get(self.ha.request_id_header())

self.log_client.log(DEBUG, 'http response result:status:%d,reason:%s,code:%s,message:%s,headers:%s',
status, reason, code, message, header)

Expand All @@ -808,7 +819,7 @@ def _parse_xml_internal(self, result, methodName=None, chuckSize=65536, readable
status, reason, code, message, requestId)

ret = GetResult(code=code, message=message, status=status, reason=reason, body=body,
requestId=requestId, hostId=hostId, resource=resource, header=header)
requestId=requestId, hostId=hostId, resource=resource, header=header, indicator=indicator)

if not readable:
if status >= 300 and status < 400 and status != 304 and const.LOCATION_HEADER.lower() in headers:
Expand Down
Loading

0 comments on commit f6ae57b

Please sign in to comment.