def urlretrieve(
    url,
    output=None,
    reporthook=None
):
    r = requests.get(url, stream=True)
    try:
        maxsize = int(r.headers['content-length'])
    except __HOLE__:
        maxsize = -1

    if output is None:
        try:
            filename = re.findall(
                "filename=(\S+)", r.headers['content-disposition']
            )[0].strip('\'"')
        except (IndexError, KeyError):
            filename = urlparse.unquote(
                os.path.basename(urlparse.urlparse(url).path)
            )
        filename = unique_filename(filename)
        reporthook.filename = filename
    else:
        filename = output

    with open(filename, 'wb') as f:
        for i, chunk in enumerate(r.iter_content(chunk_size=1024 * 8)):
            if chunk:
                f.write(chunk)
                if reporthook is not None:
                    reporthook(i, 1024 * 8, maxsize)
dataset/ETHPy150Open nils-werner/zget/zget/utils.py/urlretrieve