def visitGetattr(self, node, *args): "Disallow any attempts to access a restricted attribute." name = node.attrname lineno = Helpers.get_node_lineno(node) if is_unallowed_attr(name): self.errors.append(SafeEvalAttrError( \ "access to attribute '%s' is denied" % name, lineno))
def visitName(self, node, *args): "Disallow any attempts to access a restricted builtin/attr." name = node.getChildren()[0] lineno = Helpers.get_node_lineno(node) if is_unallowed_builtin(name): self.errors.append(SafeEvalBuiltinError( \ "access to builtin '%s' is denied" % name, lineno)) elif is_unallowed_attr(name): self.errors.append(SafeEvalAttrError( \ "access to attribute '%s' is denied" % name, lineno))
def fail(self, node, *args): "Default callback for unallowed AST nodes." lineno = Helpers.get_node_lineno(node) self.errors.append(SafeEvalASTNodeError( \ "execution of '%s' statements is denied" % Helpers.classname(node), lineno))