Basic Python 3 compatibility

Should work with Python 2.6, 2.7 and 3.2+.

Only tested with 2.7 and 3.3. All tests pass.