@contextmanager
def _download_file(uri, bulk_api):
    'Download the bulk API result file for a single batch'
    resp = requests.get(uri, headers=bulk_api.headers(), stream=True)
    with tempfile.TemporaryFile('w+b') as f:
        for chunk in resp.iter_content(chunk_size=None):
            f.write(chunk)
        f.seek(0)
        (yield f)
Download the bulk API result file for a single batch
@contextmanager
def _download_file(uri, bulk_api):
    
    resp = requests.get(uri, headers=bulk_api.headers(), stream=True)
    with tempfile.TemporaryFile('w+b') as f:
        for chunk in resp.iter_content(chunk_size=None):
            f.write(chunk)
        f.seek(0)
        (yield f)