Python 3 fixes

An assortment of changes which restore Python 3 compatibility.

Due to various differences between implementing Python functions in C vs in Python there are probably some differences relating to coercion between bytes and unicode.  This is perhaps not something that concerns me terribly.