Fix fdopen() mode for PY3 compatibility