Use StringIO from io for Python 3 compatibility