Fixed python 2 StringIO bug

In python 2 strings were not being converted to StringIOs.

The new method assumes that template is a string and tries to convert
it to a StringIO. If that fails then it assumes a file-like object.