

def _parse_results(self, stream):
    'Parse results and messages out of *stream*.'
    result = None
    values = None
    try:
        for (event, elem) in et.iterparse(stream, events=('start', 'end')):
            if ((elem.tag == 'results') and (event == 'start')):
                is_preview = (msg_type.attrib['preview'] == '1')
                self.is_preview = is_preview
            if (elem.tag == 'result'):
                if (event == 'start'):
                    result = OrderedDict()
                elif (event == 'end'):
                    (yield result)
                    result = None
                    elem.clear()
            elif ((elem.tag == 'field') and (result is not None)):
                if (event == 'start'):
                    values = []
                elif (event == 'end'):
                    field_name = elem.attrib['k'].encode('utf8')
                    if (len(values) == 1):
                        result[field_name] = values[0]
                    else:
                        result[field_name] = values
                    elem.clear()
            elif ((elem.tag in ('text', 'v')) and (event == 'end')):
                values.append(elem.text.encode('utf8'))
                elem.clear()
            elif (elem.tag == 'msg'):
                if (event == 'start'):
                    msg_type = elem.attrib['type']
                elif (event == 'end'):
                    (yield Message(msg_type, elem.text.encode('utf8')))
                    elem.clear()
    except et.ParseError as pe:
        if ('no element found' in pe.msg):
            return
        else:
            raise

dataset/ETHPy150Open splunk/splunk-ref-pas-code/spikes/googledrive_addon/bin/splunklib/results.py ResultsReader._parse_results/VarMisuse@72/105 `elem`->`msg_type`