Use io.StringIO for everything

Also, add missing decode() call for Python 2 upon reading from standard
in.
Make things a bit friendlier to Python 2