Skip to content
This repository was archived by the owner on May 8, 2018. It is now read-only.

Commit 2502eef

Browse files
committed
working auto rootkey
You don't need to set a rootkey by yourself now.
1 parent 1541137 commit 2502eef

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

mws/mws.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,17 @@ def remove_namespace(xml):
5858

5959

6060
class DictWrapper(object):
61-
def __init__(self, xml):
61+
def __init__(self, xml, rootkey=None):
6262
self.original = xml
63+
self._rootkey = rootkey
6364
self._mydict = utils.xml2dict().fromstring(remove_namespace(xml))
6465
self._response_dict = self._mydict.get(self._mydict.keys()[0],
6566
self._mydict)
6667

6768
@property
68-
def parsed(self, key=None):
69-
if key:
70-
return self._response_dict.get(key)
69+
def parsed(self):
70+
if self._rootkey:
71+
return self._response_dict.get(self._rootkey)
7172
else:
7273
return self._response_dict
7374

@@ -162,7 +163,7 @@ def make_request(self, extra_data, method="GET", **kwargs):
162163
# I do not check the headers to decide which content structure to server simply because sometimes
163164
# Amazon's MWS API returns XML error responses with "text/plain" as the Content-Type.
164165
try:
165-
parsed_response = DictWrapper(data)
166+
parsed_response = DictWrapper(data, extra_data.get("Action") + "Result")
166167
except XMLError:
167168
parsed_response = DataWrapper(data, response.headers)
168169

0 commit comments

Comments
 (0)