class ResponseBody(dict):
def __init__(self, response, body=None):
body_data = body or {}
self.update(body_data)
self.response = response
self.body = body_data
def __str__(self):
body = super(ResponseBody, self).__str__()
return "Response: %s\nBody: %s" % (self.response, body)
class ResponseBodyData(object):
def __init__(self, response, data):
self.response = response
self.data = data
def __str__(self):
return "response: %s\nBody: %s" % (self.response, self.data)
class ResponseBodyList(list):
def __init__(self, response, body=None):
body_data = body or []
self.extend(body_data)
self.response = response
def __str__(self):
self.body = super(ResponseBodyList, self).__str__()
return "response: %s\nBody: %s" % (self.response, self.body)
res = ResponseBodyData({},d)
res_d = ResponseBody({},d)
print res.data
print res_d.body
print res_d.body.items()
print res_d.items()
'''
{'a': {'v': {'c': 'e'}, 'one': 'one'}, 'b': {'c': 'c'}}
{'a': {'v': {'c': 'e'}, 'one': 'one'}, 'b': {'c': 'c'}}
[('a', {'v': {'c': 'e'}, 'one': 'one'}), ('b', {'c': 'c'})]
[('a', {'v': {'c': 'e'}, 'one': 'one'}), ('b', {'c': 'c'})]
'''
网友评论