Going to merge anyway but `from StringIO import StringIO`would make the code simpler I think.