human
Complete this python program:
def _gen_keep_files(name, require, walk_d=None):
assistant
#Here is the Python code you requested.

    """Generate the list of files that need to be kept when a dir based function
    like directory or recurse has a clean.
    """
    def _is_child(path, directory):
        '\n                                Check    whether    ``path``    is    child    of    ``directory``\n                                '
        path = os.path.abspath(path)
        directory = os.path.abspath(directory)
        relative = os.path.relpath(path, directory)
        return (not relative.startswith(os.pardir))
    def _add_current_path(path):
        _ret = set()
        if os.path.isdir(path):
            (dirs, files) = walk_d.get(path, ((), ()))
            _ret.add(path)
            for _name in files:
                _ret.add(os.path.join(path, _name))
            for _name in dirs:
                _ret.add(os.path.join(path, _name))
        return _ret
    def _process_by_walk_d(name, ret):
        if os.path.isdir(name):
            walk_ret.update(_add_current_path(name))
            (dirs, _) = walk_d.get(name, ((), ()))
            for _d in dirs:
                p = os.path.join(name, _d)
                walk_ret.update(_add_current_path(p))
                _process_by_walk_d(p, ret)
    def _process(name):
        ret = set()
        if os.path.isdir(name):
            for (root, dirs, files) in os.walk(name):
                ret.add(name)
                for name in files:
                    ret.add(os.path.join(root, name))
                for name in dirs:
                    ret.add(os.path.join(root, name))
        return ret
    keep = set()
    if isinstance(require, list):
        required_files = [comp for comp in require if ('file' in comp)]
        for comp in required_files:
            for low in __lowstate__:
                if ((low['name'] == comp['file']) or (low['__id__'] == comp['file'])):
                    fn = low['name']
                    fun = low['fun']
                    if os.path.isdir(fn):
                        if _is_child(fn, name):
                            if (fun == 'recurse'):
                                fkeep = _gen_recurse_managed_files(**low)[3]
                               ...