# `SafeEvaluator`

digraph inheritance1536c5813d { bgcolor=transparent; rankdir=UD; ratio=compress; size="8.0, 12.0"; "SafeEvaluator" [URL="#taurus.core.util.safeeval.SafeEvaluator",color=dodgerblue1,fillcolor=white,fontcolor=black,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.5,shape=box,style=rounded,target="_top",tooltip="This class provides a safe eval replacement."]; }

class SafeEvaluator(safedict=None, defaultSafe=True)

  This class provides a safe eval replacement.

  The method eval() will only evaluate the expressions considered safe (whitelisted). By default it has a whitelist of mathematical expressions that can be turn off using defaultSafe=False at init

  The user can add more safe functions passing a safedict to the addSafe() or init methods.

  Functions can be removed by name using removeSafe()

  Note: In order to use variables defined outside, the user must explicitly declare them safe.

  Import from `taurus.core.util.safeeval` as:

      from taurus.core.util.safeeval import SafeEvaluator

  addSafe(safedict, permanent=False)

    The values in safedict will be evaluable (whitelisted)

    The safedict is as follows: {“eval_name”:object, …}. The evaluator will interpret eval_name as object.

  eval(expr)

    safe eval

  getSafe()

    returns the currently whitelisted expressions

  removeSafe(name, permanent=False)

    Removes an object from the whitelist

  resetSafe()

    restores the safe dict with wich the evaluator was instantiated