Fix StringIO imports and invocations

This fixes the issue experienced in #2386 as well as a few occurrences of the same problem. This is part of the Python 3 work.

@kjoconnor, @jamesls please review.