Skip to content

Commit 890e155

Browse files
committed
support module imports again
1 parent ea003aa commit 890e155

2 files changed

Lines changed: 31 additions & 14 deletions

File tree

‎v3/pg_logger.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,17 @@
7979
# whitelist of module imports
8080
ALLOWED_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
8595
def __restricted_import__(*args):

‎v3/visualize.html‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,30 @@
173173
philip@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
177195
href="https://github.com/pgbovine/OnlinePythonTutor/blob/master/v3/docs/user-FAQ.md">FAQ</a>
178196
or other <a
179197
href="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
183202
href="https://groups.google.com/forum/#!forum/pythontutor-users">pythontutor-users</a>
@@ -186,18 +205,6 @@
186205
to 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;">
202209
Copyright &copy; 2010-2012 <a href="http://www.pgbovine.net/">Philip Guo</a>. All rights reserved.
203210
</p>

0 commit comments

Comments
 (0)