2to3 support

Please note, these changes break python 2.5 compatibility, due to the a lack of support for byte literals (see 634db4c and f30dfba) in python2.5. It may be possible to work around this, however this would require behavioural changes.

These commits ensure that 2to3 can generate working python3 code. There should be no changes to behaviour under python2 - almost all of the changes are making things that are implicit under python 2, explicit.

Test cases have been added to exercise additional code paths.

All unit tests pass under python2.6, python2.7 and pypy. This does not activate automatic 2to3 conversion in setup.py.

The changes may not be acceptable due to the loss of python2.5 support, but comments are appreciated in either case.