add more stringio support to compat
modernize template.py