def get_file_permissions(policy, files_dict, processes_dict):
    """Get the processes that can access a set of files, with their related
    permissions.

    Returns a nested dictionary {file: {process: set(perms)}}."""
    # Local variable not to query the policy for every file
    hugemap = {}
    # Prepare a nested dictionary [type][class]{domain: list(rules)}
    # This contains all allow rules "allow domain type: class {...}"
    # accessible by the three indexes [type], [class], [domain]
    for f in files_dict.values():
        if f.context.type not in hugemap:
            # We don't know this type
            hugemap[f.context.type] = {}
        if f.security_class not in hugemap[f.context.type]:
            # We don't know this [type][class] combination
            dmns = policy.get_domains_allowed_to(f.context, f.security_class)
            hugemap[f.context.type][f.security_class] = dmns
    # Prepare the output dictionary
    # This will be accessed as outmap[fname][pname], giving the set of
    # permissions associated to each pair of values of the indexes
    outmap = {}
    # Process all files
    for fname, f in files_dict.iteritems():
        if fname not in outmap:
            outmap[fname] = {}
        for pname, p in processes_dict.iteritems():
            if hugemap[f.context.type][f.security_class] in p.context.type:
                # We have some rule from this type to the current file
                if pname not in outmap[fname]:
                    # If we don't have any permissions for this process yet
                    outmap[fname][pname] = set()
                for rule in hugemap[f.context.type][f.security_class][p.context.type]:
                    outmap[fname][pname].update(rule.perms)
    return outmap
dataset/ETHPy150Open seandroid-analytics/seal/seal.py/get_file_permissions/swapped operands of `in`