py3: use write() instead of print()
Because print() expects str and we want to write bytes.
There should be no functional changes as part of this.
Differential Revision: https://phab.mercurial-scm.org/D5011
py3: convert sorting field to sysstr
This is used as part of an attribute name check and needs to be native str.
Differential Revision: https://phab.mercurial-scm.org/D5008