Python3

This ports a number of modules to python3. 

I've split the work up in to a commit per module. Please feel free to review the commits one at a time.

I've reintroduced what I had in _compat.py into a _py3_compat.py. I will keep this small, only the really repetitive stuff. 


I still really dislike having lots of custom wrappers here, and would prefer to avoid a file like this.