utils.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:databrewer 作者: rmax 项目源码 文件源码
def download_file(url, filename, quiet=True, reporthook_kwargs=None):
    """Downloads a file with optional progress report."""
    if '://' not in url:
        raise ValueError("fully qualified URL required: %s" % url)
    if url.partition('://')[0] not in ('https', 'http', 'ftp'):
        raise ValueError("unsupported URL schema: %s" % url)

    if url.startswith('ftp://'):
        retrieve = _urlretrieve
    else:
        retrieve = _urlretrieve_requests

    if quiet:
        return retrieve(url, filename)

    reporthook_kwargs = reporthook_kwargs or {}
    if filename:
        reporthook_kwargs.setdefault('desc', filename)

    reporthook_kwargs.setdefault('unit', 'b')
    reporthook_kwargs.setdefault('unit_scale', True)

    reporthook = _ReportHook(**reporthook_kwargs)
    retrieve = _urlretrieve if url.startswith('ftp://') else _urlretrieve_requests
    with contextlib.closing(reporthook):
        retrieve(url, filename, reporthook)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号