|
37 | 37 | import resource |
38 | 38 |
|
39 | 39 |
|
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 | | - |
50 | 40 | # whitelist of module imports |
51 | 41 | ALLOWED_MODULE_IMPORTS = ('doctest',) |
52 | 42 |
|
@@ -107,29 +97,6 @@ def _runscript(self, script_str): |
107 | 97 | # (at least on my Webfaction hosting with Python 2.7) |
108 | 98 | #resource.setrlimit(resource.RLIMIT_FSIZE, (0, 0)) # (redundancy for paranoia) |
109 | 99 |
|
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 | | - |
133 | 100 | # sys.modules contains an in-memory cache of already-loaded |
134 | 101 | # modules, so if you delete modules from here, they will |
135 | 102 | # need to be re-loaded from the filesystem. |
@@ -164,10 +131,10 @@ def finalize(self): |
164 | 131 | def print_finalizer(executor): |
165 | 132 | #print 'DONE:' |
166 | 133 | #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()) |
171 | 138 |
|
172 | 139 |
|
173 | 140 | # the MAIN meaty function!!! |
|
0 commit comments