backport most things to Python 2

The test that makes a TemporaryDirectory won't run on Python 2, and of
course the doctests won't run, but all the other tests pass on Python 2
now.