Python 3 support

Some minimal changes to enable Python 3 support without reliance on the
2to3 utility (which doesn't seem to be working for me from setup.py)
More Python 3 changes

Derived initially from a manual 2to3 run with subsequent fixes to
provide code compatible with both Python 2 and 3