_compat: backport TemporaryDirectory implementation

This is the implementation currently in 3.4 backported to 2.7's weakref
implementation. Add appropriate attribution and source to copyright
banner.

Tehe 3.4 implementation has the strong advantage of being a *lot*
smaller than the original Stack Overflow implementation :).