def apply(self, data, path=None):
if path is None:<EOL><INDENT>path = []<EOL><DEDENT>if not isinstance(data, dict):<EOL><INDENT>return data<EOL><DEDENT>def _enumerate(value):<EOL><INDENT>if isinstance(value, list):<EOL><INDENT>for k, v in enumerate(value):<EOL><INDENT>yield k, v<EOL><DEDENT><DEDENT>elif isinstance(value, dict):<EOL><INDENT>for k, v in value.items():<EOL><INDENT>yield k, v<EOL><DEDENT><DEDENT><DEDENT>def _set(container, key, value):<EOL><INDENT>if isinstance(container, list):<EOL><INDENT>container.append(value)<EOL><DEDENT>else:<EOL><INDENT>container[key] = value<EOL><DEDENT><DEDENT>def _apply(ramap, value, status=False, wc=False, path=[]):<EOL><INDENT>if not isinstance(value, dict) and not isinstance(value, list):<EOL><INDENT>if status:<EOL><INDENT>return value<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>if not wc:<EOL><INDENT>status = ramap.get("<STR_LIT>", status)<EOL><DEDENT>handler = None<EOL>key_handler = None<EOL>if path and self.handlers:<EOL><INDENT>namespace = Namespace(path)<EOL>for _handler in self.handlers.values():<EOL><INDENT>if namespace.match(_handler.get("<STR_LIT>").keys, partial=False):<EOL><INDENT>handler = _handler<EOL>key_handler = handler.get("<STR_LIT:key>")<EOL>break<EOL><DEDENT><DEDENT><DEDENT>if isinstance(value, list):<EOL><INDENT>if not key_handler:<EOL><INDENT>key_handler = list_key_handler<EOL><DEDENT>rv = []<EOL><DEDENT>else:<EOL><INDENT>rv = {}<EOL><DEDENT>for k, v in _enumerate(value):<EOL><INDENT>if key_handler:<EOL><INDENT>k = key_handler(v, k)<EOL><DEDENT>k = str(k)<EOL>if isinstance(v, dict) or isinstance(v, list):<EOL><INDENT>if k in ramap:<EOL><INDENT>r = _apply(ramap[k], v, status=status, path=path+[k])<EOL>if r:<EOL><INDENT>_set(rv, k, r)<EOL><DEDENT><DEDENT>elif "<STR_LIT:*>" in ramap:<EOL><INDENT>r = _apply(ramap["<STR_LIT:*>"], v, status=status, wc=True, path=path+[k])<EOL>if r:<EOL><INDENT>_set(rv, k, r)<EOL><DEDENT><DEDENT>elif status:<EOL><INDENT>_set(rv, k, v)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if k in ramap:<EOL><INDENT>if ramap[k].get("<STR_LIT>", True):<EOL><INDENT>_set(rv, k, v)<EOL><DEDENT><DEDENT>elif "<STR_LIT:*>" in ramap and ramap["<STR_LIT:*>"].get("<STR_LIT>", True):<EOL><INDENT>_set(rv, k, v)<EOL><DEDENT>elif status:<EOL><INDENT>_set(rv, k, v)<EOL><DEDENT><DEDENT><DEDENT>return rv<EOL><DEDENT>tmpns = {}<EOL>for ns, handler in self.handlers.items():<EOL><INDENT>if handler.get("<STR_LIT>"):<EOL><INDENT>p = self.pset.get_permissions(ns)<EOL>if p & const.PERM_READ:<EOL><INDENT>exists = False<EOL>for _ns in self.pset.namespaces:<EOL><INDENT>if Namespace(_ns).match(Namespace(ns).keys, partial=False):<EOL><INDENT>exists = True<EOL>break<EOL><DEDENT><DEDENT>if exists:<EOL><INDENT>continue<EOL><DEDENT>tmpns[ns] = p<EOL>self.pset[ns] = const.PERM_DENY<EOL><DEDENT><DEDENT><DEDENT>rv = _apply(self.pset.read_access_map, data)<EOL>for ns, p in tmpns.items():<EOL><INDENT>if p is None:<EOL><INDENT>del self.pset[ns]<EOL><DEDENT>else:<EOL><INDENT>self.pset[ns] = p<EOL><DEDENT><DEDENT>return rv<EOL>
Apply permissions in this set to the provided data, effectively
removing all keys from it are not permissioned to be viewed

Arguments:

data -- dict of data

Returns:

Cleaned data