Py3 tweak to urllib import

This commit is contained in:
Lance 2013-10-30 11:57:50 -04:00
parent 68f7b25cf7
commit de41143159

View File

@ -8,7 +8,6 @@ package normally; instead, they're called from commands in setup.py.
""" """
from wordfreq import config from wordfreq import config
import urllib
import os import os
import sys import sys
import shutil import shutil
@ -18,6 +17,11 @@ import logging
import subprocess import subprocess
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
if sys.version_info.major == 2:
from urllib import urlretrieve
else:
from urllib.request import urlretrieve
class ProgressTracker(object): class ProgressTracker(object):
""" """
@ -59,7 +63,7 @@ def download(url, dest_filename):
os.makedirs(base_dir) os.makedirs(base_dir)
tracker = ProgressTracker(url) tracker = ProgressTracker(url)
urllib.urlretrieve(url, dest_filename, reporthook=tracker.report_progress) urlretrieve(url, dest_filename, reporthook=tracker.report_progress)
tracker.finish() tracker.finish()
logger.info("Saved database to %s" % dest_filename) logger.info("Saved database to %s" % dest_filename)
return True return True