code: def filter_ast(module_ast):
      
      def node_predicate(node):
          """
          Return true if given node is whitelisted
          """
          for an in ALLOWED_NODES:
              if isinstance(node, an):
                  return True
  
          # Recurse through Assign node LHS targets when an id is not specified,
          # otherwise check that the id is uppercase
          if isinstance(node, ast.Assign):
              return all([node_predicate(t) for t in node.targets if not hasattr(t, 'id')]) \
                  and all([t.id.isupper() for t in node.targets if hasattr(t, 'id')])
  
          return False
  
      module_ast.body = [n for n in module_ast.body if node_predicate(n)]
      return module_ast
docs: Filters a given module ast, removing non-whitelisted nodes
  
      It allows only the following top level items:
       - imports
       - function definitions
       - class definitions
       - top level assignments where all the targets on the LHS are all caps