diff --git a/requestbuilder/request.py b/requestbuilder/request.py index 67860c3..9ab3184 100644 --- a/requestbuilder/request.py +++ b/requestbuilder/request.py @@ -67,7 +67,7 @@ class BaseRequest(BaseCommand): NAME = None METHOD = 'GET' - LIST_MARKERS = [] + LIST_TAGS = [] def __init__(self, service=None, **kwargs): @@ -231,7 +231,7 @@ class AWSQueryRequest(BaseRequest): def parse_response(self, response): # Parser for list-delimited responses like EC2's response_dict = self.log_and_parse_response(response, - parse_listdelimited_aws_xml, list_markers=self.LIST_MARKERS) + parse_listdelimited_aws_xml, list_tags=self.LIST_TAGS) # Strip off the root element assert len(response_dict) == 1 return response_dict[list(response_dict.keys())[0]] diff --git a/requestbuilder/xmlparse.py b/requestbuilder/xmlparse.py index c0c97b7..4b4fbe1 100644 --- a/requestbuilder/xmlparse.py +++ b/requestbuilder/xmlparse.py @@ -18,14 +18,14 @@ except ImportError: from xml.etree import ElementTree -def parse_aws_xml(xml_stream, list_item_markers=None): +def parse_aws_xml(xml_stream, list_item_tags=None): ''' Parse a stream of XML and return a nested dict. The dict represents each XML element with a key that matches the element's name and a value of another dict if the element contains at least one child element, or the element's text if it does not. - For each element whose name appears in the list_item_markers list, its dict + For each element whose name appears in the list_item_tags list, its dict value will instead be a list that aggregates the values of every element with that name. @@ -46,8 +46,8 @@ def parse_aws_xml(xml_stream, list_item_markers=None): ''' # One fundamental assumption we make here is that elements contain text # xor other elements. - if list_item_markers is None: - list_item_markers = () + if list_item_tags is None: + list_item_tags = () stack = [(None, {})] try: for event, elem in ElementTree.iterparse(xml_stream, @@ -56,7 +56,7 @@ def parse_aws_xml(xml_stream, list_item_markers=None): if event == 'start': stack.append((tag, {})) if event == 'end': - if tag in list_item_markers: + if tag in list_item_tags: # We're ending a list item, so append it to stack[-2]'s list stack[-2][1].setdefault(tag, []) if stack[-1][1] == {}: @@ -77,14 +77,14 @@ def parse_aws_xml(xml_stream, list_item_markers=None): return stack[0][1] -def parse_listdelimited_aws_xml(xml_stream, list_markers=None): +def parse_listdelimited_aws_xml(xml_stream, list_tags=None): ''' Parse a stream of XML and return a nested dict. The dict represents each XML element with a key that matches the element's name and a value of another dict if the element contains at least one child element, or the element's text if it does not. - For each element whose name appears in the list_markers list, its dict + For each element whose name appears in the list_tags list, its dict value will instead be a list that aggregates the values of each of that element's children. @@ -105,15 +105,15 @@ def parse_listdelimited_aws_xml(xml_stream, list_markers=None): ''' # One fundamental assumption we make here is that elements contain text # xor other elements. - if list_markers is None: - list_markers = () + if list_tags is None: + list_tags = () stack = [(None, {})] try: for event, elem in ElementTree.iterparse(xml_stream, events=('start', 'end')): tag = _strip_tag(elem.tag) if event == 'start': - if tag in list_markers: + if tag in list_tags: # Start a new list stack.append((tag, [])) else: