Abstract urllib2/urllib imports

Avoid repetition by figuring out which libraries to import in the
different interpreter versions once.