Miscellaneous Python 3 compatibility fixes

This takes care of the "print-function" and "StringIO" Python 3 incompatibilities.

I imagine the "contextlib.nested" ones are going to be pretty annoying, and I have no clue about the "__module__" errors.

(You can run the tests under Python 3 with `$ TOXENV=py34 tox`)
Build is failing because this is not compatible with Python 2.6, I believe. Something like
```
if sys.version_info[0] < 3
```
may work.