port to python3

mostly based on 2to3 and some adoption of urllib.