python 3 compatibility

Compatibility with python 3 (without breaking compatibility with python 2). The only change is StringIO import statement.