194
194
self.cmdQ.put({"exc": ''.join(tb).decode('utf-8', 'replace')})
195
195
self.webio.flush()
196
196
self.curr_cmd = ''
198
198
# throw away a partial command.
200
200
cmd = compile(ln['block'], "<web session>", 'exec');
204
204
self.webio.flush()
205
205
self.cmdQ.put({"exc": ''.join(tb).decode('utf-8', 'replace')})
206
206
self.curr_cmd = ''
210
self.globs['__builtins__'] = globals()['__builtins__']
211
self.cmdQ.put({'response': 'okay'})
212
# Unpickle the new space (if provided)
213
if isinstance(ln['flush'],dict):
214
for g in ln['flush']:
216
self.globs[g] = cPickle.loads(ln['flush'][g])
220
if isinstance(ln['call'], dict):
223
args = params['args']
226
if 'kwargs' in params:
227
kwargs = params['kwargs']
232
function = cPickle.loads(params['function'])
233
result = function(*args, **kwargs)
234
self.cmdQ.put({'output': result})
236
self.cmdQ.put({'response': 'failure: %s'%repr(e)})
238
self.cmdQ.put({'response': 'failure'})
239
elif 'inspect' in ln:
208
240
# Like block but return a serialization of the state
209
# throw away a partial command and all state.
241
# throw away partial command
212
globs['__builtins__'] = globals()['__builtins__']
213
output_buffer = cStringIO.StringIO()
243
stdout = cStringIO.StringIO()
244
stderr = cStringIO.StringIO()
215
246
cmd = compile(ln['inspect'], "<web session>", 'exec');
219
sys.stdout = output_buffer
220
sys.stderr = output_buffer
221
250
# We don't expect a return value - 'single' symbol prints
252
eval(cmd, self.globs)
224
253
except Exception, e:
226
255
tb = format_exc_start(start=1)
230
259
inspection['exception'] = exception
232
261
# Write out the inspection object
233
inspection['output'] = output_buffer.getvalue()
234
inspection['globals'] = flatten(globs)
235
self.cmdQ.put({"inspection": inspection})
236
output_buffer.close()
262
inspection['stdout'] = stdout.getvalue()
263
inspection['stderr'] = stderr.getvalue()
264
inspection['globals'] = flatten(self.globs)
265
self.cmdQ.put(inspection)
237
268
self.curr_cmd = ''
270
raise Exception, "Invalid Command"
241
273
if os.fork(): # launch child and...