SeattleTestbed / repy_v2

Seattle Testbed's Repy ("Restricted Python") sandbox, version 2
MIT License
12 stars 50 forks source link

adding 'safe' elements to repy.py does not work as expected... #17

Closed choksi81 closed 10 years ago

choksi81 commented 10 years ago

In Repy V2, adding items like safe._BUILTIN_OK.append("foo") does not work as expected. The reason is that safe_check also needs to be modified.

As a result, there is no good way to do something like add a command line option to repy that turns on / off the safety of some strings. This should really work with the dynamic settings that repy has in its context. I can think of hacked up ways to do this, but would prefer a suggestion that is clean and readable.

choksi81 commented 10 years ago

Author: mkaplan The solution that comes to mind is to add a command line argument to repy to explicitly allow a single built-in, and then call safe_check with those arguments.

The safe_check program would then parse those arguments and call a function in safe to allow the built-in.

This would require writing the command line parsing (with optparse) for the new argument and a function in safe.py to allow a built-in. Neither should be difficult.

Other solutions: With a single process-program, this would've been possible by modifying the safe that is imported by other modules. However, that is extremely messy, and would make maintenance more difficult. In any case, because safe_check runs as a separate process, that solution is not possible.

choksi81 commented 10 years ago

Author: justinc Actually, I think you've mostly fixed this already. The point was there used to essentially be two lists of items: one in repy.py and another in safe_check.py.

You've consolidated this into safe.py and thus removed the confusion.

choksi81 commented 10 years ago

Author: mkaplan Previously, one of the goals was to avoid changing safe.py so it would be easier to upgrade to newer versions. The changes are now fully integrated into safe.py, and any future changes only require modifying safe.py.