Support Python 3k

A new pull request to merge into the nolta:python3 branch. Supersedes pull #52.