PY3: use six.iterkeys, six.iteritems, and tempfile