add support for cancelling deferreds

I essentially just translated the code for cancellation from http://twistedmatrix.com/trac/browser/tags/releases/twisted-13.1.0/twisted/internet/defer.py .