

def start(self, response):
    '\n        Initiate and return a stream for `response` body  with progress\n        callback attached. Can be called only once.\n\n        :param response: Initiated response object with headers already fetched\n        :type response: requests.models.Response\n\n        :return: RawStream, output_file\n\n        '
    assert (not self.status.time_started)
    try:
        total_size = int(response.headers['Content-Length'])
    except (KeyError, ValueError, TypeError):
        total_size = None
    if self._output_file:
        if (self._resume and (response.status_code == PARTIAL_CONTENT)):
            total_size = parse_content_range(response.headers.get('Content-Range'), self._resumed_from)
        else:
            self._resumed_from = 0
            try:
                self._output_file.seek(0)
                self._output_file.truncate()
            except IOError:
                pass
    else:
        fn = None
        if ('Content-Disposition' in response.headers):
            fn = filename_from_content_disposition(response.headers['Content-Disposition'])
        if (not fn):
            fn = filename_from_url(url=response.url, content_type=response.headers.get('Content-Type'))
        self._output_file = open(get_unique_filename(fn), mode='a+b')
    self.status.started(resumed_from=self._resumed_from, total_size=total_size)
    stream = RawStream(msg=HTTPResponse(response), with_headers=False, with_body=True, on_body_chunk_downloaded=self.chunk_downloaded, chunk_size=(1024 * 8))
    self._progress_reporter.output.write(('Downloading %sto "%s"\n' % (((humanize_bytes(total_size) + ' ') if (total_size is not None) else ''), self._output_file.name)))
    self._progress_reporter.start()
    return (stream, self._output_file)

dataset/ETHPy150Open RoseOu/flasky/venv/lib/python2.7/site-packages/httpie/downloads.py Download.start/original