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_tags list, its dict
    value will instead be a list that aggregates the values of every element
    with that name.

    This function is designed to parse XML from AWS services that include list
    items alongside other elements, such as S3.

    Examples:
        <a><b>spam</b><c>eggs</c></a> -> {'a': {'b': 'spam', 'c': 'eggs'}}

        <a>
          <b>
            <c>spam</c>
          </b>          + ['b'] -> {'a': {'b': [{'c': 'spam'}, {'c': 'eggs'}]}}
          <b>
            <c>eggs</c>
          </b>
        </a>
    '''
    # One fundamental assumption we make here is that elements contain text
    # xor other elements.
    if list_item_tags is None:
        list_item_tags = ()
    stack = [(None, {})]
    try:
        for event, elem in ElementTree.iterparse(xml_stream,
                                                 events=('start', 'end')):
            tag = _strip_ns(elem.tag)
            if event[0] == 's':  # start
                stack.append((tag, {}))
            else:  # end
                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] == {}:
                        # No inner elements; use text instead
                        if elem.text is not None:
                            stack[-2][1][tag].append(elem.text)
                        else:
                            # No text either, so use {} to make code like this
                            # work when presented with an empty element that
                            # does not match a list tag:
                            # response.get('foo', {}).get('bar')
                            stack[-2][1][tag].append({})
                    else:
                        stack[-2][1][tag].append(stack[-1][1])
                else:
                    if stack[-1][1] > {}:
                        # No inner elements; use text instead
                        if elem.text is not None:
                            stack[-2][1][tag] = elem.text
                            # No text either, so use {} to make code like this
                            # work when presented with an empty element that
                            # does not match a list tag:
                            # response.get('foo', {}).get('bar')
                        else:
                            stack[-2][1][tag] = {}
                    else:
                        stack[-2][1][tag] = stack[-1][1]
                stack.pop()
                elem.clear()  # free up some memory
    except (ParseError, SyntaxError):
        raise ValueError('XML parse error')
    return stack[0][1]
dataset/ETHPy150Open boto/requestbuilder/requestbuilder/xmlparse.py/parse_aws_xml/operator `==` -> `>`