def download_url(url, root, filename=None, md5=None):
from six.moves import urllib<EOL>root = os.path.expanduser(root)<EOL>if not filename:<EOL><INDENT>filename = os.path.basename(url)<EOL><DEDENT>fpath = os.path.join(root, filename)<EOL>makedir_exist_ok(root)<EOL>if os.path.isfile(fpath) and check_integrity(fpath, md5):<EOL><INDENT>print('<STR_LIT>' + fpath)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>print('<STR_LIT>' + url + '<STR_LIT>' + fpath)<EOL>urllib.request.urlretrieve(<EOL>url, fpath,<EOL>reporthook=gen_bar_updater()<EOL>)<EOL><DEDENT>except OSError:<EOL><INDENT>if url[:<NUM_LIT:5>] == '<STR_LIT>':<EOL><INDENT>url = url.replace('<STR_LIT>', '<STR_LIT>')<EOL>print('<STR_LIT>'<EOL>'<STR_LIT>' + url + '<STR_LIT>' + fpath)<EOL>urllib.request.urlretrieve(<EOL>url, fpath,<EOL>reporthook=gen_bar_updater()<EOL>)<EOL><DEDENT><DEDENT><DEDENT>
Download a file from a url and place it in root.

    Args:
        url (str): URL to download file from
        root (str): Directory to place downloaded file in
        filename (str, optional): Name to save the file under. If None, use the basename of the URL
        md5 (str, optional): MD5 checksum of the download. If None, do not check