Add python 2 support on python 3 branch to unify branches

I've tried to unify python 2 and python 3 codebases. This passes all tests on python 2.6, but please recheck it and if you find it OK, merge.
Thanks.