A bunch of Python 3 fixes. Tests still passing for Python 2.6 and 2.7

This fixes a bunch of Python 3 issues while still allowing the tests to pass on Python 2.6 and Python 2.7.

The big thing remaining is the uri/iri stuff.