Fixes #1862: The PS backend would inadvertently close file handles passed to it on Python 3.  The TextIOWrapper that handles the encoding from unicode to ascii needs to be detached before its destructor is called, otherwise it will call close on the underlying file object.  Also cleans up how with statements are handled to avoid the sometimes problematic null contextmanager.
Merge pull request #1862 from mdboom/ps-file-closing

Matplotlib savefig() closes BytesIO object when saving in postscript format