Пример #1
0
 def _success(self, result, cellid, output, count, style):
     """Return result of some computation
     The last function in the chain of callbacks. 
     """
     data = {'content':output, 'count':count, 'cellstyle':style, 'cellid':cellid}
     jsobj = json.dumps(data)
     return self.respondJson(jsobj)
Пример #2
0
 def _success(self, result, request):
     cellid = request.args['cellid'][0]
     data = {'completions':str(result), 'cellid':cellid}
     jsobj = json.dumps(data)
     request.setHeader("content-type", "application/json")
     request.write(jsobj)
     request.finish()
Пример #3
0
 def render(self, request): 
     newtitle = request.args.get('newtitle', [None])[0]
     result = yield defer.maybeDeferred(self.notebook_db.change_notebook_metadata, newtitle)
     data = {'response':'ok', 'title':newtitle}
     jsobj = json.dumps(data)
     request.setHeader("content-type", "application/json")
     request.write(jsobj)
     request.finish()
Пример #4
0
 def _kernel_err(self, result, cellid):
     output = 'Kernel Error: The interpreter might still be starting up.'
     count = '!'
     outputstyle = 'outputtext'
     #TODO Make an errortext style 
     # It could be cool to have tracebacks be errors and
     # kernel errors could be some other sort of message/warning
     data = {'content':output, 'count':count, 'cellstyle':outputstyle, 'cellid':cellid}
     jsobj = json.dumps(data)
     return self.respondJson(jsobj)
Пример #5
0
 def render(self, request):
     orderlist = ",".join(request.args.get('orderlist', []))
     cellsdata = request.args.get('cellsdata', [None])[0]
     cellsdata = json.loads(cellsdata)
     result = yield defer.maybeDeferred(self.notebook_db.save_notebook_metadata,
             orderlist, cellsdata)
     resp = "{'resource':'%s', 'resp':'ok'}" % self.__class__.__name__
     jsobj = json.dumps(resp)
     request.setHeader("content-type", "application/json")
     request.write(jsobj)
     request.finish()
Пример #6
0
 def render(self, request):
     action = request.args['action'][0].strip()
     actions = {'kill':self.engine.kill, 'interupt':self.engine.interrupt}
     if actions.has_key(action):
         result = yield defer.maybeDeferred(actions[action])
         resp = result
     else:
         resp = "{'resp':'failed', 'msg':'Bad process command. No such action'}"
     jsobj = json.dumps(resp)
     request.setHeader("content-type", "application/json")
     request.write(jsobj)
     request.finish()
Пример #7
0
 def render(self, req): 
     """
     Delete one or more cells.
     """
     #XXX untested - javascript doesn't work right now to delete a cell?
     cellids = json.loads(req.args.get('cellids', [None])[0])
     result = yield defer.maybeDeferred(self.notebook_db.delete_cells, cellids)
     resp = "{'resource':'%s', 'resp':'ok'}" % self.__class__.__name__
     jsobj = json.dumps(resp)
     request.setHeader("content-type", "application/json")
     request.write(jsobj)
     request.finish()
Пример #8
0
 def _save_output(self, result, request, cellid):
     count, out, err = result['input_count'], result['out'], result['err']
     output = out + err
     if "__image__" in output:
         output = output[9:] + err
         style = "outputimage"
     else:
         style = "outputtext"
     outcellid = cellid + "o" #denote an 'output' cell
     d = defer.maybeDeferred(
             self.notebook_db.save_cell,
                 outcellid, output,
                 type="output", style=style, props="props")
     data = {'content':output, 'count':count, 'cellstyle':style, 'cellid':cellid}
     jsobj = json.dumps(data)
     request.write(jsobj)
     request.finish()
Пример #9
0
 def render(self, request):
     result = yield defer.maybeDeferred(self.notebook_db.get_notebook_data)
     jsobj = json.dumps(result)
     request.setHeader("content-type", "application/json")
     request.write(jsobj)
     request.finish()
Пример #10
0
 def _success(self, result, cellid):
     output = str(result)
     data = {'completions':output, 'cellid':cellid}
     jsobj = json.dumps(data)
     return self.respondJson(jsobj)
Пример #11
0
 def _success(self, result, newtitle):
     data = {'response':'ok', 'title':newtitle}
     jsobj = json.dumps(data)
     return self.respondJson(jsobj)
Пример #12
0
 def _success(self, result):
     jsobj = json.dumps(result)
     return self.respondJson(jsobj)