File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7979# whitelist of module imports
8080ALLOWED_MODULE_IMPORTS = ('math' , 'random' , 'datetime' ,
8181 'functools' , 'operator' , 'string' ,
82- 'collections' , 're' , 'json' )
82+ 'collections' , 're' , 'json' ,
83+ 'heapq' , 'bisect' )
84+
85+ # PREEMPTIVELY import all of these modules, so that when the user's
86+ # script imports them, it won't try to do a file read (since they've
87+ # already been imported and cached in memory). Remember that when
88+ # the user's code runs, resource.setrlimit(resource.RLIMIT_NOFILE, (0, 0))
89+ # will already be in effect, so no more files can be opened.
90+ for m in ALLOWED_MODULE_IMPORTS :
91+ __import__ (m )
92+
8393
8494# Restrict imports to a whitelist
8595def __restricted_import__ (* args ):
Original file line number Diff line number Diff line change 173173philip@pgbovine.net
174174</ p >
175175
176+ < a href ="http://pythontutor.com/ "> Online Python Tutor</ a > supports < a
177+ href ="http://www.python.org/doc/2.7/ "> Python 2.7</ a > and < a
178+ href ="http://www.python.org/doc/3.2/ "> Python 3.2</ a > with limited module
179+ imports and no file I/O.
180+ The following modules may be imported:
181+ bisect,
182+ collections,
183+ datetime,
184+ functools,
185+ heapq,
186+ json,
187+ math,
188+ operator,
189+ random,
190+ re,
191+ string
192+ </ p >
193+
176194< p > Have a question? Maybe the < a
177195href ="https://github.com/pgbovine/OnlinePythonTutor/blob/master/v3/docs/user-FAQ.md "> FAQ</ a >
178196or other < a
179197href ="https://github.com/pgbovine/OnlinePythonTutor/blob/master/v3/docs/ "> documentation</ a >
180- can help.</ p >
198+ can help. Its code is open source on < a
199+ href ="https://github.com/pgbovine/OnlinePythonTutor/ "> GitHub</ a > .</ p >
181200
182201< p > Join the < a
183202href ="https://groups.google.com/forum/#!forum/pythontutor-users "> pythontutor-users</ a >
186205to receive occasional announcements.
187206(Your name and email address will be kept private; only the list owner can see them.)</ p >
188207
189- < p >
190-
191- < a href ="http://pythontutor.com/ "> Online Python Tutor</ a > supports < a
192- href ="http://www.python.org/doc/2.7/ "> Python 2.7</ a > and < a
193- href ="http://www.python.org/doc/3.2/ "> Python 3.2</ a > with limited module
194- imports and no file I/O. It is designed for teaching programming, not
195- for running or debugging production code. Its code is open source on < a
196- href ="https://github.com/pgbovine/OnlinePythonTutor/ "> GitHub</ a > .
197-
198- </ p >
199-
200-
201208< p style ="margin-top: 8px; ">
202209Copyright © 2010-2012 < a href ="http://www.pgbovine.net/ "> Philip Guo</ a > . All rights reserved.
203210</ p >
You can’t perform that action at this time.
0 commit comments