Make Python 3 compatible

All tests pass on Python 2.6 and Python 3.4. I also tested this by converting a bunch of HTML documents, which uncovered a bunch of encoding issues. When I get some more time, I'll look into adding more tests.