##// END OF EJS Templates
Oops, had commited leaving some merge junk behind.
gvaroquaux -
Show More
@@ -348,7 +348,6 b' class FrontEndBase(object):'
348
348
349
349
350 def render_error(self, failure):
350 def render_error(self, failure):
351 <<<<<<< TREE
352 """Subclasses must override to render the failure.
351 """Subclasses must override to render the failure.
353
352
354 In asynchronous frontends, this method will be called as a
353 In asynchronous frontends, this method will be called as a
@@ -357,66 +356,4 b' class FrontEndBase(object):'
357 """
356 """
358
357
359 raise NotImplementedError
358 raise NotImplementedError
360
361
362
363 =======
364 """Subclasses must override to render the failure. Since this method
365 will be called as a twisted.internet.defer.Deferred's callback,
366 implementations should return result when finished.
367 """
368
369 return failure
370
371
372
373 class AsyncFrontEndBase(FrontEndBase):
374 """
375 Overrides FrontEndBase to wrap execute in a deferred result.
376 All callbacks are made as callbacks on the deferred result.
377 """
378
379 implements(IFrontEnd)
380 classProvides(IFrontEndFactory)
381
382 def __init__(self, engine=None, history=None):
383 assert(engine==None or IEngineCore.providedBy(engine))
384 self.engine = IEngineCore(engine)
385 if history is None:
386 self.history = FrontEndHistory(input_cache=[''])
387 else:
388 self.history = history
389
390
391 def execute(self, block, blockID=None):
392 """Execute the block and return the deferred result.
393
394 Parameters:
395 block : {str, AST}
396 blockID : any
397 Caller may provide an ID to identify this block.
398 result['blockID'] := blockID
399
400 Result:
401 Deferred result of self.interpreter.execute
402 """
403
404 if(not self.is_complete(block)):
405 from twisted.python.failure import Failure
406 return Failure(Exception("Block is not compilable"))
407
408 if(blockID == None):
409 blockID = uuid.uuid4() #random UUID
410
411 d = self.engine.execute(block)
412 d.addCallback(self._add_history, block=block)
413 d.addCallback(self._add_block_id_for_result, blockID)
414 d.addErrback(self._add_block_id_for_failure, blockID)
415 d.addBoth(self.update_cell_prompt, blockID=blockID)
416 d.addCallbacks(self.render_result,
417 errback=self.render_error)
418
419 return d
420
421 >>>>>>> MERGE-SOURCE
422
359
General Comments 0
You need to be logged in to leave comments. Login now