code: def guarded_eval(code: str, context: EvaluationContext):
      """Evaluate provided code in the evaluation context.
  
      If evaluation policy given by context is set to ``forbidden``
      no evaluation will be performed; if it is set to ``dangerous``
      standard :func:`eval` will be used; finally, for any other,
      policy :func:`eval_node` will be called on parsed AST.
      """
      locals_ = context.locals
  
      if context.evaluation == "forbidden":
          raise GuardRejection("Forbidden mode")
  
      # note: not using `ast.literal_eval` as it does not implement
      # getitem at all, for example it fails on simple `[0][1]`
  
      if context.in_subscript:
          # syntatic sugar for ellipsis (:) is only available in susbcripts
          # so we need to trick the ast parser into thinking that we have
          # a subscript, but we need to be able to later recognise that we did
          # it so we can ignore the actual __getitem__ operation
          if not code:
              return tuple()
          locals_ = locals_.copy()
          locals_[SUBSCRIPT_MARKER] = IDENTITY_SUBSCRIPT
          code = SUBSCRIPT_MARKER + "[" + code + "]"
          context = EvaluationContext(
              **{**context._asdict(), **{"locals": locals_}}
          )
  
      if context.evaluation == "dangerous":
          return eval(code, context.globals, context.locals)
  
      expression = ast.parse(code, mode="eval")
  
      return eval_node(expression, context)
  
imports: from inspect import signature, Signature
  from typing import Any, Callable, Dict, Set, Sequence, Tuple, NamedTuple, Type, Literal, Union, TYPE_CHECKING
  import ast
  import builtins
  import collections
  import operator
  import sys
  from functools import cached_property
  from dataclasses import dataclass, field
  from types import MethodDescriptorType, ModuleType
  from IPython.utils.docs import GENERATING_DOCUMENTATION
  from IPython.utils.decorators import undoc
label_desc: Use image node_id 5 for calling a global function with example usage: guarded_eval(code, context) and returns: eval_node, eval, tuple