Parses header lines as curl yields them to us.
347753
private static function parseHeaderLine($ch, string $data, array &$info, array &$headers, ?array $options, CurlClientState $multi, int $id, ?string &$location, ?callable $resolveRedirect, ?LoggerInterface $logger): int
    {
        if (!\in_array($waitFor = @curl_getinfo($ch, CURLINFO_PRIVATE), ['headers', 'destruct'], true)) {
            return \strlen($data); // Ignore HTTP trailers
        }

        if ("\r\n" !== $data) {
            // Regular header line: add it to the list
            self::addResponseHeaders([substr($data, 0, -2)], $info, $headers);

            if (0 === strpos($data, 'HTTP') && 300 <= $info['http_code'] && $info['http_code'] < 400) {
                if (curl_getinfo($ch, CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
                } elseif (303 === $info['http_code'] || ('POST' === $info['http_method'] && \in_array($info['http_code'], [301, 302], true))) {
                    $info['http_method'] = 'HEAD' === $info['http_method'] ? 'HEAD' : 'GET';
                    curl_setopt($ch, CURLOPT_POSTFIELDS, '');
                }
            }

            if (0 === stripos($data, 'Location:')) {
                $location = trim(substr($data, 9, -2));
            }

            return \strlen($data);
        }

        // End of headers: handle redirects and add to the activity list
        $statusCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
        $info['redirect_url'] = null;

        if (300 <= $statusCode && $statusCode < 400 && null !== $location) {
            $info['redirect_url'] = $resolveRedirect($ch, $location);
            $url = parse_url($location ?? ':');

            if (isset($url['host']) && null !== $ip = $multi->dnsCache->hostnames[$url['host'] = strtolower($url['host'])] ?? null) {
                // Populate DNS cache for redirects if needed
                $port = $url['port'] ?? ('http' === ($url['scheme'] ?? parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), PHP_URL_SCHEME)) ? 80 : 443);
                curl_setopt($ch, CURLOPT_RESOLVE, ["{$url['host']}:$port:$ip"]);
                $multi->dnsCache->removals["-{$url['host']}:$port"] = "-{$url['host']}:$port";
            }
        }

        $location = null;

        if ($statusCode < 300 || 400 <= $statusCode || curl_getinfo($ch, CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
            // Headers and redirects completed, time to get the response's body
            $multi->handlesActivity[$id] = [new FirstChunk()];

            if ('destruct' === $waitFor) {
                return 0;
            }

            if ($certinfo = curl_getinfo($ch, CURLINFO_CERTINFO)) {
                $info['peer_certificate_chain'] = array_map('openssl_x509_read', array_column($certinfo, 'Cert'));
            }

            curl_setopt($ch, CURLOPT_PRIVATE, 'content');
        } elseif (null !== $info['redirect_url'] && $logger) {
            $logger->info(sprintf('Redirecting: "%s %s"', $info['http_code'], $info['redirect_url']));
        }

        return \strlen($data);
    }
616871
def parse(self, fp, headersonly=True):
        """"""
        feedparser = FeedParser(self._class)
        feedparser._set_headersonly()

        try:
            mp = mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ)
        except:
            mp = fp

        data = ""

        # While parsing the header we can convert to us-ascii?
        while True:
            line = mp.readline()
            data = data + line.decode("us-ascii")
            if line == b"\n":
                break
        feedparser.feed(data) # mp[0:5000])
        return feedparser.close()
1369724
def parse(self, lines):
        ''''''
        if self.type == 'msdos':
            return self.parse_msdos(lines)
        elif self.type == 'unix':
            return self.parse_unix(lines)
        elif self.type == 'nlst':
            return self.parse_nlst(lines)
        else:
            raise UnknownListingError('Unsupported listing type.')
134997
def _parse_header(self, data):
        
        return_list = []

        headers = data.split(':')

        for header in headers:
            header = re.split(' IN ', header, flags=re.I) # ignore case
            xheader = {'name': header[0].strip()}
            if len(header) > 1:
                xheader['units'] = header[1].strip()
            return_list.append(xheader)

        return return_list
491013
def _parseSections(self, data, elfHeader):
        """"""
        offset = elfHeader.header.e_shoff
        shdrs = []
        for i in range(elfHeader.header.e_shnum):
            shdr = self.__classes.SHDR.from_buffer(data, offset)
            section_bytes = None
            ba_section_bytes = None
            if shdr.sh_type != SHT.NOBITS:
                section_bytes = (c_ubyte * shdr.sh_size).from_buffer(data, shdr.sh_offset)
                ba_section_bytes = bytearray(section_bytes)
            shdrs.append(ShdrData(name=None,header=shdr, raw=section_bytes, bytes=ba_section_bytes))
            offset += elfHeader.header.e_shentsize

        if elfHeader.header.e_shstrndx != SHN.UNDEF:
            strtab = shdrs[elfHeader.header.e_shstrndx]
            strtab_offset = strtab.header.sh_offset

            for section in shdrs:
                section.name = get_str(strtab.raw, section.header.sh_name)

        return shdrs
218187
private void parseHeaderLine(Map<String, String> headers, String header) {
        final int colonOffset = header.indexOf(':');
        if (colonOffset == -1) {
            // This header line is malformed, skip it.
            return;
        }
        String headerName = header.substring(0, colonOffset).trim().toLowerCase();
        String headerValue = header.substring(header.indexOf(':') + 1).trim();
        if (getHeader(headers, headerName) != null) {
            // More that one heder of that name exists,
            // append to the list.
            headers.put(headerName, getHeader(headers, headerName) + ',' + headerValue);
        } else {
            headers.put(headerName, headerValue);
        }
    }
1072554
def _extract_header_value(line):
    

    # Skip blank lines, returning None
    if not line:
        return None

    # Attempt to split by equals sign
    halves = line.split('=')
    if len(halves) > 1:
        key = halves[0].strip()
        value = halves[1].strip()
        return {key: value}

    # Otherwise, attempt to split by colon
    else:
        halves = line.split(':')
        key = halves[0].strip()
        value = halves[1].strip()
        return {key: value}
885302
def readlines(self):
        """"""

        t = self.resolved_url.get_resource().get_target()
        with open(t.fspath) as f:
            return f.readlines()
697926
def _get_headers(self):
        

        header = self.lines[0]
        self.lines = self.lines[1:]

        self.headers = \
            [self.clean(h) for h in header.split(self.seperator)]
        if self.is_strip:
            self.headers = self.headers[1:-1]
        return self.headers
137773
def parse_headers(self, req, name, field):
        """"""
        return get_value(req.headers, name, field)
850831
def parser(self, lines):
        """"""
        while len(lines) > 0:
            if lines[0].startswith('##') and lines[1].startswith('# '):
                # A two-line keyword/value line starts here.
                self._header_append(lines.pop(0), lines.pop(0))
            elif lines[0].startswith('# '):
                # Lines with single comments are exposure numbers unless preceeded by double comment line
                self._append_file_id(lines.pop(0))
            elif lines[0].startswith('##'):
                # Double comment lines without a single comment following are column headers for dataset.
                self._set_column_names(lines.pop(0)[2:])
            else:
                # Last line of the header reached.
                return self
        raise IOError("Failed trying to read header")
529847
def _extract_header_number(lines):
    
    pair = _extract_header_value(lines[1])
    value_list = list(pair.values())
    return int(value_list[0])
777899
def parse_line(self, line):
        """"""

        prefix = ""
        # ignore comma at start of lines
        if line.startswith(","):
            line, prefix = line[1:], ","

        j = json.loads(line)
        yield j
        self.io.write_line(prefix + json.dumps(j))
309828
def parse_http_header(header_line):
    

    header_line = header_line.decode().strip()
    col_idx = header_line.find(':')

    if col_idx < 1:
        raise BadHttpHeaderError('Bad header: {}'.format(repr(header_line)))

    key = header_line[0:col_idx].strip()
    value = header_line[(col_idx+1):].strip()
    return HttpHeader(key=key, value=value)
61687
def extract_headers(headers):
    """"""
    sorted_headers = {}
    matches = re.findall(r'(.*):\s(.*)', headers)
    for match in matches:
        header = match[0]
        value = match[1]
        try:
            if value[-1] == ',':
                value = value[:-1]
            sorted_headers[header] = value
        except IndexError:
            pass
    return sorted_headers
866554
def _parse_block_postheader(line):
    
    parts = line[1:].split(')', 1)
    qlen = int(parts[0])
    if not len(parts[1]) == qlen:
        logging.warn("postheader expected %d-long query, found %d",
                     qlen, len(parts[1]))
    return qlen, parts[1]
354662
async def read_headers(stream: asyncio.StreamReader) -> "Headers":
    
    # https://tools.ietf.org/html/rfc7230#section-3.2

    # We don't attempt to support obsolete line folding.

    headers = Headers()
    for _ in range(MAX_HEADERS + 1):
        line = await read_line(stream)
        if line == b"":
            break

        # This may raise "ValueError: not enough values to unpack"
        raw_name, raw_value = line.split(b":", 1)
        if not _token_re.fullmatch(raw_name):
            raise ValueError("Invalid HTTP header name: %r" % raw_name)
        raw_value = raw_value.strip(b" \t")
        if not _value_re.fullmatch(raw_value):
            raise ValueError("Invalid HTTP header value: %r" % raw_value)

        name = raw_name.decode("ascii")  # guaranteed to be ASCII at this point
        value = raw_value.decode("ascii", "surrogateescape")
        headers[name] = value

    else:
        raise ValueError("Too many HTTP headers")

    return headers