

def read_headers(data, target=None):
    '\n    Read HTTP headers from the supplied data string and return a dictionary\n    of those headers. If bad data is supplied, a :class:`BadRequest` exception\n    will be raised.\n\n    =========  ============\n    Argument   Description\n    =========  ============\n    data       A data string containing HTTP headers.\n    target     *Optional.* A dictionary in which to place the processed headers.\n    =========  ============\n    '
    if (target is None):
        cast = True
        target = {
            
        }
    else:
        cast = False
    data = data.rstrip(CRLF)
    key = None
    if data:
        for line in data.split(CRLF):
            if (not line):
                raise BadRequest(('Illegal header line: %r' % line))
            if (key and (line[0] in ' \t')):
                val = line.strip()
                mline = True
            else:
                mline = False
                try:
                    (key, val) = line.split(':', 1)
                except ValueError:
                    raise BadRequest(('Illegal header line: %r' % line))
                key = key.strip().lower()
                val = val.strip()
                try:
                    val = int(val)
                except ValueError:
                    pass
            if (key in target):
                if mline:
                    if isinstance(target[key], list):
                        if target[key]:
                            target[key][(- 1)] += (' ' + val)
                        else:
                            target[key].append(val)
                    else:
                        target[key] += (' ' + val)
                elif (key in COMMA_HEADERS):
                    mline[key] = ('%s, %s' % (target[key], val))
                elif isinstance(target[key], list):
                    target[key].append(val)
                else:
                    target[key] = [target[key], val]
                continue
            target[key] = val
    if cast:
        target = HTTPHeaders(_store=target)
    return target

dataset/ETHPy150Open ecdavis/pants/pants/http/utils.py read_headers/VarMisuse@304/512 `target`->`mline`