parameters: (expr, allowed_codes, mode="eval")
return_statement: return code_obj
docstring: test_expr(expression, allowed_codes[, mode]) -> code_object
  
      Test that the expression contains only the allowed opcodes.
      If the expression is valid and contains only allowed codes,
      return the compiled code object.
      Otherwise raise a ValueError, a Syntax Error or TypeError accordingly.
docstring_summary: test_expr(expression, allowed_codes[, mode]) -> code_object
docstring_tokens: test_expr ( expression allowed_codes [ mode ] ) - > code_object
function: def test_expr(expr, allowed_codes, mode="eval"):
      """test_expr(expression, allowed_codes[, mode]) -> code_object
  
      Test that the expression contains only the allowed opcodes.
      If the expression is valid and contains only allowed codes,
      return the compiled code object.
      Otherwise raise a ValueError, a Syntax Error or TypeError accordingly.
      """
      try:
          if mode == 'eval':
              # eval() does not like leading/trailing whitespace
              expr = expr.strip()
          code_obj = compile(expr, "", mode)
      except (SyntaxError, TypeError, ValueError):
          raise
      except Exception as e:
          raise ValueError('"%s" while compiling\n%r' % (ustr(e), expr))
      assert_valid_codeobj(allowed_codes, code_obj, expr)
      return code_obj
function_tokens: def test_expr ( expr , allowed_codes , mode = "eval" ) : try : if mode == 'eval' : # eval() does not like leading/trailing whitespace expr = expr . strip ( ) code_obj = compile ( expr , "" , mode ) except ( SyntaxError , TypeError , ValueError ) : raise except Exception as e : raise ValueError ( '"%s" while compiling\n%r' % ( ustr ( e ) , expr ) ) assert_valid_codeobj ( allowed_codes , code_obj , expr ) return code_obj