Added python 3.x support

I tweaked a few things so it would work with Python 3.x. The unit test passed under Python 3.3; please try it under 2.7 too.