def get_file(fname, origin, untar=False, unzip=False,<EOL>md5_hash=None, cache_subdir='<STR_LIT>'):
datadir_base = os.path.expanduser(os.path.join('<STR_LIT>', '<STR_LIT>'))<EOL>if not os.access(datadir_base, os.W_OK):<EOL><INDENT>datadir_base = os.path.join('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>datadir = os.path.join(datadir_base, cache_subdir)<EOL>if not os.path.exists(datadir):<EOL><INDENT>os.makedirs(datadir)<EOL><DEDENT>if untar or unzip:<EOL><INDENT>untar_fpath = os.path.join(datadir, fname)<EOL>if unzip:<EOL><INDENT>fpath = untar_fpath + '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>fpath = untar_fpath + '<STR_LIT>'<EOL><DEDENT><DEDENT>else:<EOL><INDENT>fpath = os.path.join(datadir, fname)<EOL><DEDENT>download = False<EOL>if os.path.exists(fpath):<EOL><INDENT>if md5_hash is not None:<EOL><INDENT>if not validate_file(fpath, md5_hash):<EOL><INDENT>print('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>download = True<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>download = True<EOL><DEDENT>if download:<EOL><INDENT>print('<STR_LIT>', origin)<EOL>global progbar<EOL>progbar = None<EOL>def dl_progress(count, block_size, total_size):<EOL><INDENT>global progbar<EOL>if progbar is None:<EOL><INDENT>progbar = Progbar(total_size)<EOL><DEDENT>else:<EOL><INDENT>progbar.update(count * block_size)<EOL><DEDENT><DEDENT>error_msg = '<STR_LIT>'<EOL>try:<EOL><INDENT>try:<EOL><INDENT>urlretrieve(origin, fpath, dl_progress)<EOL><DEDENT>except URLError as e:<EOL><INDENT>raise Exception(error_msg.format(origin, e.errno, e.reason))<EOL><DEDENT>except HTTPError as e:<EOL><INDENT>raise Exception(error_msg.format(origin, e.code, e.msg))<EOL><DEDENT><DEDENT>except (Exception, KeyboardInterrupt) as e:<EOL><INDENT>if os.path.exists(fpath):<EOL><INDENT>os.remove(fpath)<EOL><DEDENT>raise<EOL><DEDENT>progbar = None<EOL><DEDENT>if untar:<EOL><INDENT>if not os.path.exists(untar_fpath):<EOL><INDENT>print('<STR_LIT>')<EOL>tfile = tarfile.open(fpath, '<STR_LIT>')<EOL>try:<EOL><INDENT>tfile.extractall(path=datadir)<EOL><DEDENT>except (Exception, KeyboardInterrupt) as e:<EOL><INDENT>if os.path.exists(untar_fpath):<EOL><INDENT>if os.path.isfile(untar_fpath):<EOL><INDENT>os.remove(untar_fpath)<EOL><DEDENT>else:<EOL><INDENT>shutil.rmtree(untar_fpath)<EOL><DEDENT><DEDENT>raise<EOL><DEDENT>tfile.close()<EOL><DEDENT>return untar_fpath<EOL><DEDENT>elif unzip:<EOL><INDENT>if not os.path.exists(untar_fpath):<EOL><INDENT>print('<STR_LIT>')<EOL>with zipfile.ZipFile(fpath) as file_:<EOL><INDENT>try:<EOL><INDENT>file_.extractall(path=datadir)<EOL><DEDENT>except (Exception, KeyboardInterrupt) as e:<EOL><INDENT>if os.path.exists(untar_fpath):<EOL><INDENT>if os.path.isfile(untar_fpath):<EOL><INDENT>os.remove(untar_fpath)<EOL><DEDENT>else:<EOL><INDENT>shutil.rmtree(untar_fpath)<EOL><DEDENT><DEDENT>raise<EOL><DEDENT><DEDENT><DEDENT>return untar_fpath<EOL><DEDENT>return fpath<EOL>
Downloads a file from a URL if it not already in the cache.

    Passing the MD5 hash will verify the file after download as well as if it is already present in the cache.

    # Arguments
        fname: name of the file
        origin: original URL of the file
        untar: boolean, whether the file should be decompressed
        md5_hash: MD5 hash of the file for verification
        cache_subdir: directory being used as the cache

    # Returns
        Path to the downloaded file