WiP: improve py3k compatibility

These commits improve py3k compatibility. It's a small number of commits and more work may be needed, but I'm sending this PR to ensure it's not forgotten.