Spaces:
Sleeping
Sleeping
Debugging
Browse files
restrictedpython_code_eval.py
CHANGED
@@ -17,6 +17,7 @@ Lightly adapted and mostly copied verbatim from the implementation in `evaluate`
|
|
17 |
"""
|
18 |
import ast
|
19 |
import contextlib
|
|
|
20 |
import faulthandler
|
21 |
import itertools
|
22 |
import importlib
|
@@ -84,13 +85,26 @@ class CodeEvalRestrictingTransformer(RestrictingNodeTransformer):
|
|
84 |
def visit_AugAssign(self, node):
|
85 |
# allow += and similar operations for list indices
|
86 |
if isinstance(node.target, ast.Subscript):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
new_node = ast.Assign(
|
88 |
targets=[node.target],
|
89 |
value=ast.Call(
|
90 |
func=ast.Name('_inplacevar_', ast.Load()),
|
91 |
args=[
|
92 |
ast.Str(IOPERATOR_TO_STR[type(node.op)]),
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
94 |
node.value
|
95 |
],
|
96 |
keywords=[]))
|
|
|
17 |
"""
|
18 |
import ast
|
19 |
import contextlib
|
20 |
+
import copy
|
21 |
import faulthandler
|
22 |
import itertools
|
23 |
import importlib
|
|
|
85 |
def visit_AugAssign(self, node):
|
86 |
# allow += and similar operations for list indices
|
87 |
if isinstance(node.target, ast.Subscript):
|
88 |
+
# new_name = copy.deepcopy(node.target.value)
|
89 |
+
# new_name.ctx = ast.Load() # type: ignore
|
90 |
+
|
91 |
+
new_subscript = copy.deepcopy(node.target)
|
92 |
+
new_subscript.ctx = ast.Load()
|
93 |
+
if hasattr(new_subscript.value, 'ctx'):
|
94 |
+
new_subscript.value.ctx = ast.Load() # type: ignore
|
95 |
+
|
96 |
new_node = ast.Assign(
|
97 |
targets=[node.target],
|
98 |
value=ast.Call(
|
99 |
func=ast.Name('_inplacevar_', ast.Load()),
|
100 |
args=[
|
101 |
ast.Str(IOPERATOR_TO_STR[type(node.op)]),
|
102 |
+
new_subscript,
|
103 |
+
# ast.Subscript(
|
104 |
+
# value=new_name,
|
105 |
+
# slice=node.target.slice,
|
106 |
+
# ctx=ast.Load(),
|
107 |
+
# ),
|
108 |
node.value
|
109 |
],
|
110 |
keywords=[]))
|