I think this can be replaced with class [StringIO](https://docs.python.org/3.4/library/io.html?highlight=stringio#io.StringIO).