use tempfile and io, not os and codecs, for Python 3 compatibility