note that the hash of an arbitrary object is only derived from its address (closes #21154)

Patch from Armin Rigo.
make temporary read-only files writable, so rmtree can remove them (#21128)
properly explicitly close file (#21128)
explicitly close file object (#21128)
use with statement