Python 3 port, based on current master branch

Tests pass on py26, py27, py33 and pypy. Also ran a quick manual test on py33 and it seems to work fine. Fixes #237.