PY3: use six.iterkeys, six.iteritems, and tempfile
Merge pull request #799 from felixonmars/py3-port

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