#NEWLINE# def add_callbacks( future , callback , errback ) : #NEWLINE# #INDENT# '\n    callback or errback may be None, but at least one must be\n    non-None.\n\n    XXX beware the "f._result" hack to get "chainable-callback" type\n    behavior.\n    ' #NEWLINE# def done( f ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# res = f . result ( ) #NEWLINE# if callback : #NEWLINE# #INDENT# x = callback ( res ) #NEWLINE# if ( x is not None ) : #NEWLINE# #INDENT# f . _result = x #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except Exception : #NEWLINE# #INDENT# if errback : #NEWLINE# #INDENT# errback ( create_failure ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return future . add_done_callback ( done )