Add support for Python 3

This adds support for py3k and runs fine on Python 3.3 at least with current django tip. The fixes are pretty basic and shouldn't affect 2.x.