'The given download_url can have an extension like #md5#, #sha256#, (or #md5= to support pypi defaults).
https://pypi.python.org/packages/source/k/khmer/khmer-1.0.tar.gz#md5#b60639a8b2939836f66495b9a88df757
Alternatively, to not break HTTP spec, you can specify md5 and
sha256 as keys in the <action /> element.
This indicates a checksum which will be checked after download.
If the checksum does not match an exception is thrown.'

def url_download(self, install_dir, downloaded_file_name, download_url, extract=True, checksums={}):

    file_path = os.path.join(install_dir, downloaded_file_name)
    try:
        download_to_file(download_url, file_path, chunk_size=basic_util.CHUNK_SIZE)
    except Exception as e:
        err_msg = ('Error    downloading    from    URL    %s    :    %s' % (str(download_url), str(e)))
        raise Exception(err_msg)
    if (('sha256sum' in checksums) or ('#sha256#' in download_url)):
        downloaded_checksum = hashlib.sha256(open(file_path, 'rb').read()).hexdigest().lower()
        if ('sha256sum' in checksums):
            expected = checksums['sha256sum'].lower()
        else:
            expected = download_url.split('#sha256#')[1].lower()
        if (downloaded_checksum != expected):
            raise Exception(('Given    sha256    checksum    does    not    match    with    the    one    from    the    downloaded    file    (%s    !=    %s).' % (downloaded_checksum, expected)))
    if (('md5sum' in checksums) or ('#md5#' in download_url) or ('#md5=' in download_url)):
        downloaded_checksum = hashlib.md5(open(file_path, 'rb').read()).hexdigest().lower()
        if ('md5sum' in checksums):
            expected = checksums['md5sum'].lower()
        else:
            expected = re.split('#md5[#=]', download_url)[1].lower()
        if (downloaded_checksum != expected):
            raise Exception(('Given    md5    checksum    does    not    match    with    the    one    from    the    downloaded    file    (%s    !=    %s).' % (downloaded_checksum, expected)))
    if extract:
        if (tarfile.is_tarfile(file_path) or (zipfile.is_zipfile(file_path) and (not file_path.endswith('.jar')))):
            archive = CompressedFile(file_path)
            extraction_path = archive.extract(install_dir)
        else:
            extraction_path = os.path.abspath(install_dir)
    else:
        extraction_path = os.path.abspath(install_dir)
    return extraction_path
