files.py 文件源码

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

项目:quantrocket-client 作者: quantrocket-llc 项目源码 文件源码
def write_response_to_filepath_or_buffer(filepath_or_buffer, response):
    """
    Writes the response content to the filepath or buffer.
    """
    if hasattr(filepath_or_buffer, "write"):
        if six.PY3 and filepath_or_buffer is sys.stdout:
            # Write bytes to stdout (https://stackoverflow.com/a/23932488)
            filepath_or_buffer = filepath_or_buffer.buffer
        mode = getattr(filepath_or_buffer, "mode", "w")
        for chunk in response.iter_content(chunk_size=1024):
            if chunk:
                if "b" not in mode and six.PY3:
                    chunk = chunk.decode("utf-8")
                filepath_or_buffer.write(chunk)
        if filepath_or_buffer.seekable():
            filepath_or_buffer.seek(0)
    else:
        with open(filepath_or_buffer, "wb") as f:
            for chunk in response.iter_content(chunk_size=1024):
                if chunk:
                    f.write(chunk)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号