@@ -119,7 +119,11 @@ public abstract static class ImportNode extends PythonBuiltinNode {
119
119
@ Specialization
120
120
@ TruffleBoundary
121
121
public Object importSymbol (String name ) {
122
- Object object = getContext ().getEnv ().importSymbol (name );
122
+ Env env = getContext ().getEnv ();
123
+ if (!env .isPolyglotAccessAllowed ()) {
124
+ throw raise (PythonErrorType .NotImplementedError , "polyglot access is not allowed" );
125
+ }
126
+ Object object = env .importSymbol (name );
123
127
if (object == null ) {
124
128
return PNone .NONE ;
125
129
}
@@ -134,6 +138,9 @@ abstract static class EvalInteropNode extends PythonBuiltinNode {
134
138
@ Specialization
135
139
Object evalString (@ SuppressWarnings ("unused" ) PNone path , String value , String langOrMimeType ) {
136
140
Env env = getContext ().getEnv ();
141
+ if (!env .isPolyglotAccessAllowed ()) {
142
+ throw raise (PythonErrorType .NotImplementedError , "polyglot access is not allowed" );
143
+ }
137
144
try {
138
145
boolean mimeType = isMimeType (langOrMimeType );
139
146
String lang = mimeType ? findLanguageByMimeType (env , langOrMimeType ) : langOrMimeType ;
@@ -159,6 +166,9 @@ private void raiseIfInternal(Env env, String lang) {
159
166
@ Specialization
160
167
Object evalFile (String path , @ SuppressWarnings ("unused" ) PNone string , String langOrMimeType ) {
161
168
Env env = getContext ().getEnv ();
169
+ if (!env .isPolyglotAccessAllowed ()) {
170
+ throw raise (PythonErrorType .NotImplementedError , "polyglot access is not allowed" );
171
+ }
162
172
try {
163
173
boolean mimeType = isMimeType (langOrMimeType );
164
174
String lang = mimeType ? findLanguageByMimeType (env , langOrMimeType ) : langOrMimeType ;
@@ -179,6 +189,9 @@ Object evalFile(String path, @SuppressWarnings("unused") PNone string, String la
179
189
@ Specialization
180
190
Object evalFile (String path , @ SuppressWarnings ("unused" ) PNone string , @ SuppressWarnings ("unused" ) PNone lang ) {
181
191
Env env = getContext ().getEnv ();
192
+ if (!env .isPolyglotAccessAllowed ()) {
193
+ throw raise (PythonErrorType .NotImplementedError , "polyglot access is not allowed" );
194
+ }
182
195
try {
183
196
return getContext ().getEnv ().parse (Source .newBuilder (PythonLanguage .ID , env .getTruffleFile (path )).name (path ).build ()).call ();
184
197
} catch (IOException e ) {
@@ -227,21 +240,33 @@ public abstract static class ExportSymbolNode extends PythonBuiltinNode {
227
240
@ Specialization
228
241
@ TruffleBoundary
229
242
public Object exportSymbol (Object value , String name ) {
230
- getContext ().getEnv ().exportSymbol (name , value );
243
+ Env env = getContext ().getEnv ();
244
+ if (!env .isPolyglotAccessAllowed ()) {
245
+ throw raise (PythonErrorType .NotImplementedError , "polyglot access is not allowed" );
246
+ }
247
+ env .exportSymbol (name , value );
231
248
return value ;
232
249
}
233
250
234
251
@ Specialization
235
252
@ TruffleBoundary
236
253
public Object exportSymbol (PFunction fun , @ SuppressWarnings ("unused" ) PNone name ) {
237
- getContext ().getEnv ().exportSymbol (fun .getName (), fun );
254
+ Env env = getContext ().getEnv ();
255
+ if (!env .isPolyglotAccessAllowed ()) {
256
+ throw raise (PythonErrorType .NotImplementedError , "polyglot access is not allowed" );
257
+ }
258
+ env .exportSymbol (fun .getName (), fun );
238
259
return fun ;
239
260
}
240
261
241
262
@ Specialization
242
263
@ TruffleBoundary
243
264
public Object exportSymbol (PBuiltinFunction fun , @ SuppressWarnings ("unused" ) PNone name ) {
244
- getContext ().getEnv ().exportSymbol (fun .getName (), fun );
265
+ Env env = getContext ().getEnv ();
266
+ if (!env .isPolyglotAccessAllowed ()) {
267
+ throw raise (PythonErrorType .NotImplementedError , "polyglot access is not allowed" );
268
+ }
269
+ env .exportSymbol (fun .getName (), fun );
245
270
return fun ;
246
271
}
247
272
@@ -280,7 +305,11 @@ protected static boolean isModule(Object o) {
280
305
281
306
@ TruffleBoundary
282
307
private void export (String name , Object obj ) {
283
- getContext ().getEnv ().exportSymbol (name , obj );
308
+ Env env = getContext ().getEnv ();
309
+ if (!env .isPolyglotAccessAllowed ()) {
310
+ throw raise (PythonErrorType .NotImplementedError , "polyglot access is not allowed" );
311
+ }
312
+ env .exportSymbol (name , obj );
284
313
}
285
314
}
286
315
0 commit comments