Upgrade to Python 3

Only a few small changes needed. Bit of non-Py3-related noise in the diff due to pep8 fixes and logging.