Initial port for Python 3.

This also works with Python 2.7, 2.6, and 2.5.

All the tests are passing. This probably needs a closer look though,
preferably by another pair of eyes.