def download(uri, filename=None, headers=None, redirect_limit=5, **kwargs):
    """ Get a remote resource and save the content to a local file. If a local
    file already exists at the download destination, the modification time of
    that file is sent in the request headers as the `If-Modified-Since` value
    to perform a conditional GET. If the remote file has not been modified, a
    304 response should then be returned.

    :param uri:
    :param filename:
    :param headers:
    :param redirect_limit:
    :param kwargs:
    :return:
    """
    from datetime import datetime
    from os import utime
    from os.path import getmtime
    from time import time
    from .tardis import datetime_to_timestamp
    try:
        last_modified = datetime.fromtimestamp(getmtime(filename))
    except __HOLE__:
        last_modified = None
    with get(uri, if_modified_since=last_modified, headers=headers, redirect_limit=redirect_limit, **kwargs) as source:
        if source.status_code == 200:
            if not filename:
                filename = source.filename
            with open(filename, "wb") as destination:
                finished = False
                while not finished:
                    data = source.read(8192)
                    if data:
                        destination.write(data)
                    else:
                        finished = True
            utime(filename, (time(), datetime_to_timestamp(source.last_modified)))
            return True
        elif source.status_code == 304:
            return False
        else:
            raise ValueError("Unexpected status code %s from download response" % source.status_code)
dataset/ETHPy150Open nigelsmall/py2neo/py2neo/packages/httpstream/__init__.py/download