Skip to content

Commit 0663e0a

Browse files
committed
bah
1 parent 73b14e3 commit 0663e0a

1 file changed

Lines changed: 4 additions & 37 deletions

File tree

‎v3/simple_sandbox.py‎

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@
3737
import resource
3838

3939

40-
# ugh, I can't figure out why in Python 2, __builtins__ seems to
41-
# be a dict, but in Python 3, __builtins__ seems to be a module,
42-
# so just handle both cases ... UGLY!
43-
if type(__builtins__) is dict:
44-
BUILTIN_IMPORT = __builtins__['__import__']
45-
else:
46-
assert type(__builtins__) is types.ModuleType
47-
BUILTIN_IMPORT = __builtins__.__import__
48-
49-
5040
# whitelist of module imports
5141
ALLOWED_MODULE_IMPORTS = ('doctest',)
5242

@@ -107,29 +97,6 @@ def _runscript(self, script_str):
10797
# (at least on my Webfaction hosting with Python 2.7)
10898
#resource.setrlimit(resource.RLIMIT_FSIZE, (0, 0)) # (redundancy for paranoia)
10999

110-
# The posix module is a built-in and has a ton of OS access
111-
# facilities ... if you delete those functions from
112-
# sys.modules['posix'], it seems like they're gone EVEN IF
113-
# someone else imports posix in a roundabout way. Of course,
114-
# I don't know how foolproof this scheme is, though.
115-
# (It's not sufficient to just "del sys.modules['posix']";
116-
# it can just be reimported without accessing an external
117-
# file and tripping RLIMIT_NOFILE, since the posix module
118-
# is baked into the python executable, ergh. Actually DON'T
119-
# "del sys.modules['posix']", since re-importing it will
120-
# refresh all of the attributes. ergh^2)
121-
for a in dir(sys.modules['posix']):
122-
delattr(sys.modules['posix'], a)
123-
# do the same with os
124-
for a in dir(sys.modules['os']):
125-
if not a in ('path', 'stat', 'environ'):
126-
delattr(sys.modules['os'], a)
127-
# ppl can dig up trashed objects with gc.get_objects()
128-
import gc
129-
for a in dir(sys.modules['gc']):
130-
delattr(sys.modules['gc'], a)
131-
del sys.modules['gc']
132-
133100
# sys.modules contains an in-memory cache of already-loaded
134101
# modules, so if you delete modules from here, they will
135102
# need to be re-loaded from the filesystem.
@@ -164,10 +131,10 @@ def finalize(self):
164131
def print_finalizer(executor):
165132
#print 'DONE:'
166133
#print executor.executed_script
167-
print 'stdout:'
168-
print executor.user_stdout.getvalue()
169-
print 'stderr:'
170-
print executor.user_stderr.getvalue()
134+
print('stdout:')
135+
print(executor.user_stdout.getvalue())
136+
print('stderr:')
137+
print(executor.user_stderr.getvalue())
171138

172139

173140
# the MAIN meaty function!!!

0 commit comments

Comments
 (0)