Make Python 3 compatible (using six)

Most of the changes involve urllib imports, plus a couple minor tweaks
to dict iteration.