Python 3 Fixes

These are the only changes needed to compile under python 3 properly.
`basestring` includes `unicode` in Python 2, and `(str, bytes)` does not, so this is not an equivalent check.