def defer_or_apply(func):
 def closure(future, adapt):
  if isinstance(defer, Deferred):
   d = Deferred()
   future.addCallback((lambda r: d.callback(adapt(r))))
   return d
  return adapt(future)
 return closure

def defer_or_apply ( func ) : def closure ( future , adapt ) : if isinstance ( defer , Deferred ) : d = Deferred ( ) future . addCallback ( ( lambda r : d . callback ( adapt ( r ) ) ) ) return d return adapt ( future ) return closure
decorator to apply an adapter method to a result regardless if it is a deferred or a concrete response .