tf-keras-skeleton.py 文件源码

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

项目:LIE 作者: EmbraceLife 项目源码 文件源码
def urlretrieve(url, filename, reporthook=None, data=None):
            """Replacement for `urlretrive` for Python 2.

            Under Python 2, `urlretrieve` relies on `FancyURLopener` from legacy
            `urllib` module, known to have issues with proxy management.

            Arguments:
                url: url to retrieve.
                filename: where to store the retrieved data locally.
                reporthook: a hook function that will be called once
                    on establishment of the network connection and once
                    after each block read thereafter.
                    The hook will be passed three arguments;
                    a count of blocks transferred so far,
                    a block size in bytes, and the total size of the file.
                data: `data` argument passed to `urlopen`.
            """

            def chunk_read(response, chunk_size=8192, reporthook=None):
              content_type = response.info().get('Content-Length')
              total_size = -1
              if content_type is not None:
                total_size = int(content_type.strip())
              count = 0
              while 1:
                chunk = response.read(chunk_size)
                count += 1
                if not chunk:
                  reporthook(count, total_size, total_size)
                  break
                if reporthook:
                  reporthook(count, chunk_size, total_size)
                yield chunk

            response = urlopen(url, data)
            with open(filename, 'wb') as fd:
              for chunk in chunk_read(response, reporthook=reporthook):
                fd.write(chunk)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号