def parse_lsof_output(file_obj, users, types):
    """
    Format for "lsof -F tL":

    p PID
    L username
    repeated multiple times:
        f file descriptor
        t file type
    """
    fd_type = ''
    user = ''

    d = {}

    for line in file_obj:
        key = line[0]
        val = line[1:].rstrip('\n')
        if key == 'p':
            user = ''
            fd_type = ''
        if key == 'L':
            user = val
        if key == 't':
            fd_type = val

            if user not in users:
                continue
            if fd_type not in types:
                continue

            if user not in d:
                d[user] = {}
            if fd_type not in d[user]:
                d[user][fd_type] = 0
            d[user][fd_type] += 1

    return d

    Format for "lsof -F tL":

    p PID
    L username
    repeated multiple times:
        f file descriptor
        t file type
    
src/collectors/filestat/filestat.py