Parse metadata and rows from the block only once.
773100
def _parse_block(self):
        """"""
        if self._iter_rows is not None:
            return

        rows = _avro_rows(self._block, self._avro_schema)
        self._num_items = self._block.avro_rows.row_count
        self._remaining = self._block.avro_rows.row_count
        self._iter_rows = iter(rows)
1194512
def parse(self, nodes):
    """"""
    self.last_node_type = self.initial_node_type
    for node_number, node in enumerate(nodes):
      try:
        self.step(node)
      except Exception as ex:
        raise Exception("An error occurred on node {}".format(node_number)) from ex
1329316
def read_chunked(self):
        """"""
        self._load_metadata()
        for i in range(self.npartitions):
            yield self._get_partition(i)
280744
def loadMetadata(self):
        
        #TODO: change that spectra dont have to be iterated to extract metadata
        #node
        if self._parsed:
            raise TypeError('Mzml file already parsed.')
        [None for _ in self._parseMzml()]
        self._parsed = True
1050680
def _extract_all(node, name, limit_count=None):
    """"""

    seq = []

    for i in range(0, len(node.getElementsByTagName(name))):
        if len(seq) == limit_count:
            break

        seq.append(_extract(node, name, i))

    return seq
848086
def iterateBlocksBackFrom(block):
        
        count = 0
        while block.isValid() and count < MAX_SEARCH_OFFSET_LINES:
            yield block
            block = block.previous()
            count += 1
893156
private void parseQueryRowsRaw(boolean lastChunk) {
        while (responseContent.isReadable()) {
            int splitPos = findSplitPosition(responseContent, ',');
            int arrayEndPos = findSplitPosition(responseContent, ']');

            boolean doSectionDone = false;

            if (splitPos == -1 && arrayEndPos == -1) {
                //need more data
                break;
            } else if (arrayEndPos > 0 && (arrayEndPos < splitPos || splitPos == -1)) {
                splitPos = arrayEndPos;
                doSectionDone = true;
            }

            int length = splitPos - responseContent.readerIndex();
            ByteBuf resultSlice = responseContent.readSlice(length);
            queryRowObservable.onNext(resultSlice.copy());
            responseContent.skipBytes(1);
            responseContent.discardReadBytes();

            if (doSectionDone) {
                sectionDone();
                queryParsingState = transitionToNextToken(lastChunk);
                break;
            }
        }
    }
486684
def parse(self, xmp):
        """"""
        tree = etree.fromstring(xmp)
        rdf_tree = tree.find(RDF_NS + 'RDF')
        meta = defaultdict(dict)
        for desc in rdf_tree.findall(RDF_NS + 'Description'):
            for el in desc.getchildren():
                ns, tag = self._parse_tag(el)
                value = self._parse_value(el)
                meta[ns][tag] = value
        return dict(meta)
174116
def deserialize_block(value):
        
        # Block id strings are stored under batch/txn ids for reference.
        # Only Blocks, not ids or Nones, should be returned by _get_block.
        block = Block()
        block.ParseFromString(value)
        return BlockWrapper(
            block=block)
404939
def parse_block(self, block, lineno, indent):
        
        tree = self.driver.parse_tokens(self.wrap_toks(block, lineno, indent))
        tree.future_features = frozenset()
        return tree
880108
def parsemetadata(self, node):
        """"""

        if 'type' in node.attrib:
            self.metadatatype = node.attrib['type']
        else:
            #no type specified, default to native
            self.metadatatype = "native"

        if 'src' in node.attrib:
            self.metadata = ExternalMetaData(node.attrib['src'])
        elif self.metadatatype == "native":
            self.metadata = NativeMetaData()
        else:
            self.metadata = None #may be set below to ForeignData

        for subnode in node:
            if subnode.tag == '{' + NSFOLIA + '}annotations':
                self.parsexmldeclarations(subnode)
            elif subnode.tag == '{' + NSFOLIA + '}meta':
                if self.metadatatype == "native":
                    if subnode.text:
                        self.metadata[subnode.attrib['id']] = subnode.text
                else:
                    raise MetaDataError("Encountered a meta element but metadata type is not native!")
            elif subnode.tag == '{' + NSFOLIA + '}provenance':
                #forward compatibility with FoLiA 2.0; ignore provenance
                print("WARNING: Ignoring provenance data. Use foliapy instead of pynlpl.formats.folia for FoLiA v2.0 compatibility!",file=sys.stderr)
                pass
            elif subnode.tag == '{' + NSFOLIA + '}foreign-data':
                if self.metadatatype == "native":
                    raise MetaDataError("Encountered a foreign-data element but metadata type is native!")
                elif self.metadata is not None:
                    #multiple foreign-data elements, chain:
                    e = self.metadata
                    while e.next is not None:
                        e = e.next
                    e.next = ForeignData(self, node=subnode)
                else:
                    self.metadata = ForeignData(self, node=subnode)
            elif subnode.tag == '{' + NSFOLIA + '}submetadata':
                self.parsesubmetadata(subnode)
            elif subnode.tag == '{http://www.mpi.nl/IMDI/Schema/IMDI}METATRANSCRIPT': #backward-compatibility for old IMDI without foreign-key
                E = ElementMaker(namespace=NSFOLIA,nsmap={None: NSFOLIA, 'xml' : "http://www.w3.org/XML/1998/namespace"})
                self.metadatatype = "imdi"
                self.metadata = ForeignData(self, node=subnode)
391406
def dict_row_reader(self):
        

        rows = self.unpacked_contents

        if not rows:
            return

        header = rows.pop(0)

        for row in rows:
            yield dict(list(zip(header, row)))
785716
def _parse_blocks(instream):
    
    ilines = sugar.unblank(instream)
    for line in ilines:
        if line.startswith('['):
            # Start of block
            level, one, name, seqcount, params = _parse_block_header(line)
            qlen, qchars = _parse_block_postheader(next(ilines))
            # Pass control to the sequence parser
            sequences = list(_parse_sequences(ilines, qlen))
            # Validation
            if not len(sequences) == seqcount:
                logging.warn("Expected %d sequences in block %s, found %d",
                             seqcount, name, len(sequences))
            yield {'level': level,
                   'one': one,
                   'name': name,
                   # 'seqcount': seqcount,
                   'params': params,
                   'query_length': qlen,
                   'query_chars': qchars,
                   'sequences': sequences,
                   }
37087
def _parse(self, content):
        """"""
        if content.find('<clam') != -1:
            data = clam.common.data.CLAMData(content,self, loadmetadata=self.loadmetadata)
            if data.errors:
                error = data.parametererror()
                if error:
                    raise clam.common.data.ParameterError(error)
            return data
        else:
            return True
816429
def parse_content(self, content):
        
        self.rows = []
        if len(content) < 2:
            self.no_data = True
            return

        # Parse header, remembering column numbers for data capture.  We use
        # a finditer to get the positions, and we find by field rather than
        # splitting on three or more spaces because of this.
        headers = []
        field_re = re.compile(r'\w+(\s\w+)*')
        for match in field_re.finditer(content[0]):
            headers.append({'name': match.group(), 'start': match.start()})

        # Parse the rest of the line.  Each field starts at the column
        # given by the header and ends with at least three spaces.
        for line in content[1:]:
            # I think the dictionary comprehension version of this is too
            # complicated for words :-)
            row = {}
            for header in headers:
                value = line[header['start']:].split('   ', 1)[0]
                if value == '':
                    value = None
                row[header['name']] = value
            self.rows.append(row)

        # If we have a key_field set, construct a data dictionary on it.
        # Note that duplicates will be overwritten, but we ignore '<none>'.
        if self.key_field and self.key_field in self.rows[0]:
            self.data = {}
            for row in self.rows:
                k = row[self.key_field]
                if k is not None and k != '<none>':
                    self.data[k] = row
66173
def parse(resp) -> DataFrameType:
    """"""
    statements = []
    for statement in resp['results']:
        series = {}
        for s in statement.get('series', []):
            series[_get_name(s)] = _drop_zero_index(_serializer(s))
        statements.append(series)

    if len(statements) == 1:
        series: dict = statements[0]
        if len(series) == 1:
            return list(series.values())[0]  # DataFrame
        else:
            return series  # dict
    return statements
698394
def parse_blocks(lines):  # type: (List[str]) -> List[List[str]]
    
    blocks = []

    while lines:
        if lines[0] == '':
            lines.pop(0)
        else:
            blocks.append(parse_block(lines))

    return blocks