Commit c318d3c
authored
Fix RestrictedEvalProvider to retain state and print (#686)
Closes #685.
Two defects in `RestrictedEvalProvider.exec`, fine for single-shot
synthesis decoding but breaking any caller that reuses the namespace
across calls (e.g. a persistent REPL):
- Rebinding a name already in the namespace was silently dropped:
`keys_before` was snapshotted after `rglobals.update(env)`, so the
copy-back only saw never-before-present keys. Replace with an
identity diff that copies back every binding effect — new names and
rebindings of seeded names alike.
- `print(...)` raised `NameError: '_print_'`: RestrictedPython rewrites
print into its `_print_` collector protocol, which the provider never
supplied. Add `_StdoutPrintCollector`, a `_print_` factory routing
output to the real `sys.stdout` so output-capturing callers see it.
The `exec` op's contract — after `exec(bytecode, env)`, `env` reflects
all top-level binding effects — now holds under both providers.
Backward-compatible with the synthesis decode caller (its dict is read
once and discarded).1 parent b68a742 commit c318d3c
2 files changed
Lines changed: 83 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
724 | 725 | | |
725 | 726 | | |
726 | 727 | | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
727 | 738 | | |
728 | 739 | | |
729 | 740 | | |
| |||
800 | 811 | | |
801 | 812 | | |
802 | 813 | | |
803 | | - | |
804 | | - | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
805 | 818 | | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
806 | 822 | | |
807 | 823 | | |
808 | | - | |
809 | | - | |
810 | | - | |
811 | | - | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
28 | 33 | | |
29 | 34 | | |
30 | 35 | | |
| |||
1537 | 1542 | | |
1538 | 1543 | | |
1539 | 1544 | | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
0 commit comments