bugfix: set repsonse attribute

This commit is contained in:
debugtalk
2018-07-26 22:33:35 +08:00
parent 20015ca10a
commit 4771dd272e
3 changed files with 82 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ class ResponseObject(object):
@param (requests.Response instance) resp_obj
"""
self.resp_obj = resp_obj
self.attributes = {}
def __getattr__(self, key):
try:
@@ -152,6 +153,21 @@ class ResponseObject(object):
logger.log_error(err_msg)
raise exceptions.ExtractFailure(err_msg)
# new set response attributes
elif top_query == "attributes":
if not sub_query:
# extract response attributes
return self.attributes
if sub_query in self.attributes:
return self.attributes[sub_query]
else:
# content = "attributes.new_attribute_not_exist"
err_msg = u"Failed to extract cumstom set attribute! => {}\n".format(field)
err_msg += u"response set attributes: {}\n".format(self.attributes)
logger.log_error(err_msg)
raise exceptions.ExtractFailure(err_msg)
# others
else:
err_msg = u"Failed to extract attribute from response! => {}\n".format(field)