guydav commited on
Commit
52afe2d
1 Parent(s): 7c65e6e

Added a couple of additional restricted globals

Browse files
Files changed (1) hide show
  1. restrictedpython_code_eval.py +10 -1
restrictedpython_code_eval.py CHANGED
@@ -38,7 +38,7 @@ import datasets
38
  import numpy as np
39
  from RestrictedPython import compile_restricted, safe_builtins, limited_builtins, utility_builtins
40
  from RestrictedPython.Eval import default_guarded_getiter, default_guarded_getitem
41
- from RestrictedPython.Guards import guarded_iter_unpack_sequence, safer_getattr
42
 
43
 
44
  # TODO: Add BibTeX citation
@@ -372,6 +372,9 @@ def _unsafe_execute(check_program, result, timeout,
372
  if '_iter_unpack_sequence_' not in exec_globals:
373
  exec_globals['_iter_unpack_sequence_'] = guarded_iter_unpack_sequence # type: ignore
374
 
 
 
 
375
  if '_getitem_' not in exec_globals:
376
  exec_globals['_getitem_'] = default_guarded_getitem # type: ignore
377
 
@@ -387,6 +390,9 @@ def _unsafe_execute(check_program, result, timeout,
387
  if '_print_' not in exec_globals:
388
  exec_globals['_print_'] = DefaultPrinter # type: ignore
389
 
 
 
 
390
  with swallow_io():
391
  with time_limit(timeout):
392
  byte_code = compile_restricted(check_program, filename="<model output>", mode="exec")
@@ -669,3 +675,6 @@ def protected_inplacevar(op, var, expr):
669
  "Augmented assignment to %s objects is not allowed"
670
  " in untrusted code" % cls.__name__)
671
  return inplace_ops[op](var, expr)
 
 
 
 
38
  import numpy as np
39
  from RestrictedPython import compile_restricted, safe_builtins, limited_builtins, utility_builtins
40
  from RestrictedPython.Eval import default_guarded_getiter, default_guarded_getitem
41
+ from RestrictedPython.Guards import guarded_iter_unpack_sequence, safer_getattr, guarded_unpack_sequence
42
 
43
 
44
  # TODO: Add BibTeX citation
 
372
  if '_iter_unpack_sequence_' not in exec_globals:
373
  exec_globals['_iter_unpack_sequence_'] = guarded_iter_unpack_sequence # type: ignore
374
 
375
+ if '_unpack_sequence_' not in exec_globals:
376
+ exec_globals['_unpack_sequence_'] = guarded_unpack_sequence # type: ignore
377
+
378
  if '_getitem_' not in exec_globals:
379
  exec_globals['_getitem_'] = default_guarded_getitem # type: ignore
380
 
 
390
  if '_print_' not in exec_globals:
391
  exec_globals['_print_'] = DefaultPrinter # type: ignore
392
 
393
+ if '_apply_' not in exec_globals:
394
+ exec_globals['_apply_'] = _apply # type: ignore
395
+
396
  with swallow_io():
397
  with time_limit(timeout):
398
  byte_code = compile_restricted(check_program, filename="<model output>", mode="exec")
 
675
  "Augmented assignment to %s objects is not allowed"
676
  " in untrusted code" % cls.__name__)
677
  return inplace_ops[op](var, expr)
678
+
679
+ def _apply(f, *a, **kw):
680
+ return f(*a, **kw)