# Path: google/resumable_media/_download.py
# _CONTENT_RANGE_RE = re.compile(
#     r"bytes (?P<start_byte>\d+)-(?P<end_byte>\d+)/(?P<total_bytes>\d+)",
#     flags=re.IGNORECASE,
# )
# _ACCEPTABLE_STATUS_CODES = (http.client.OK, http.client.PARTIAL_CONTENT)
# _GET = "GET"
# _ZERO_CONTENT_RANGE_HEADER = "bytes */0"
# class DownloadBase(object):
# class Download(DownloadBase):
# class ChunkedDownload(DownloadBase):
#     def __init__(self, media_url, stream=None, start=None, end=None, headers=None):
#     def finished(self):
#     def _get_status_code(response):
#     def _get_headers(response):
#     def _get_body(response):
#     def __init__(
#         self, media_url, stream=None, start=None, end=None, headers=None, checksum="md5"
#     ):
#     def _prepare_request(self):
#     def _process_response(self, response):
#     def consume(self, transport, timeout=None):
#     def __init__(self, media_url, chunk_size, stream, start=0, end=None, headers=None):
#     def bytes_downloaded(self):
#     def total_bytes(self):
#     def invalid(self):
#     def _get_byte_range(self):
#     def _prepare_request(self):
#     def _make_invalid(self):
#     def _process_response(self, response):
#     def consume_next_chunk(self, transport, timeout=None):
# def add_bytes_range(start, end, headers):
# def get_range_info(response, get_headers, callback=_helpers.do_nothing):
# def _check_for_zero_content_range(response, get_status_code, get_headers):
# 
# Path: google/resumable_media/common.py
# _SLEEP_RETRY_ERROR_MSG = (
#     "At most one of `max_cumulative_retry` and `max_retries` " "can be specified."
# )
# UPLOAD_CHUNK_SIZE = 262144  # 256 * 1024
# PERMANENT_REDIRECT = http.client.PERMANENT_REDIRECT  # type: ignore
# TOO_MANY_REQUESTS = http.client.TOO_MANY_REQUESTS
# MAX_SLEEP = 64.0
# MAX_CUMULATIVE_RETRY = 600.0
# RETRYABLE = (
#     http.client.TOO_MANY_REQUESTS,  # 429
#     http.client.REQUEST_TIMEOUT,  # 408
#     http.client.INTERNAL_SERVER_ERROR,  # 500
#     http.client.BAD_GATEWAY,  # 502
#     http.client.SERVICE_UNAVAILABLE,  # 503
#     http.client.GATEWAY_TIMEOUT,  # 504
# )
# class InvalidResponse(Exception):
# class DataCorruption(Exception):
# class RetryStrategy(object):
#     def __init__(self, response, *args):
#     def __init__(self, response, *args):
#     def __init__(
#         self,
#         max_sleep=MAX_SLEEP,
#         max_cumulative_retry=None,
#         max_retries=None,
#         initial_delay=1.0,
#         multiplier=2.0,
#     ):
#     def retry_allowed(self, total_sleep, num_retries):


import http.client
import io
import mock
import pytest  # type: ignore
from google.resumable_media import _download
from google.resumable_media import common
        assert headers == expected

    def test__make_invalid(self):
        download = _download.ChunkedDownload(EXAMPLE_URL, 512, None)
        assert not download.invalid
        download._make_invalid()
        assert download.invalid

    def test__process_response(self):
        data = b"1234xyztL" * 37  # 9 * 37 == 33
        chunk_size = len(data)
        stream = io.BytesIO()
        download = _download.ChunkedDownload(EXAMPLE_URL, chunk_size, stream)
        _fix_up_virtual(download)

        already = 22
        download._bytes_downloaded = already
        total_bytes = 4444

        # Check internal state before.
        assert not download.finished
        assert download.bytes_downloaded == already
        assert download.total_bytes is None
        # Actually call the method to update.
        response = self._mock_response(
            already,
            already + chunk_size - 1,
            total_bytes,
            content=data,
            status_code=int(http.client.PARTIAL_CONTENT),

# Path: google/resumable_media/_download.py
# _CONTENT_RANGE_RE = re.compile(
#     r"bytes (?P<start_byte>\d+)-(?P<end_byte>\d+)/(?P<total_bytes>\d+)",
#     flags=re.IGNORECASE,
# )
# _ACCEPTABLE_STATUS_CODES = (http.client.OK, http.client.PARTIAL_CONTENT)
# _GET = "GET"
# _ZERO_CONTENT_RANGE_HEADER = "bytes */0"
# class DownloadBase(object):
# class Download(DownloadBase):
# class ChunkedDownload(DownloadBase):
#     def __init__(self, media_url, stream=None, start=None, end=None, headers=None):
#     def finished(self):
#     def _get_status_code(response):
#     def _get_headers(response):
#     def _get_body(response):
#     def __init__(
#         self, media_url, stream=None, start=None, end=None, headers=None, checksum="md5"
#     ):
#     def _prepare_request(self):
#     def _process_response(self, response):
#     def consume(self, transport, timeout=None):
#     def __init__(self, media_url, chunk_size, stream, start=0, end=None, headers=None):
#     def bytes_downloaded(self):
#     def total_bytes(self):
#     def invalid(self):
#     def _get_byte_range(self):
#     def _prepare_request(self):
#     def _make_invalid(self):
#     def _process_response(self, response):
#     def consume_next_chunk(self, transport, timeout=None):
# def add_bytes_range(start, end, headers):
# def get_range_info(response, get_headers, callback=_helpers.do_nothing):
# def _check_for_zero_content_range(response, get_status_code, get_headers):
# 
# Path: google/resumable_media/common.py
# _SLEEP_RETRY_ERROR_MSG = (
#     "At most one of `max_cumulative_retry` and `max_retries` " "can be specified."
# )
# UPLOAD_CHUNK_SIZE = 262144  # 256 * 1024
# PERMANENT_REDIRECT = http.client.PERMANENT_REDIRECT  # type: ignore
# TOO_MANY_REQUESTS = http.client.TOO_MANY_REQUESTS
# MAX_SLEEP = 64.0
# MAX_CUMULATIVE_RETRY = 600.0
# RETRYABLE = (
#     http.client.TOO_MANY_REQUESTS,  # 429
#     http.client.REQUEST_TIMEOUT,  # 408
#     http.client.INTERNAL_SERVER_ERROR,  # 500
#     http.client.BAD_GATEWAY,  # 502
#     http.client.SERVICE_UNAVAILABLE,  # 503
#     http.client.GATEWAY_TIMEOUT,  # 504
# )
# class InvalidResponse(Exception):
# class DataCorruption(Exception):
# class RetryStrategy(object):
#     def __init__(self, response, *args):
#     def __init__(self, response, *args):
#     def __init__(
#         self,
#         max_sleep=MAX_SLEEP,
#         max_cumulative_retry=None,
#         max_retries=None,
#         initial_delay=1.0,
#         multiplier=2.0,
#     ):
#     def retry_allowed(self, total_sleep, num_retries):


# Path: tests/unit/test__download.py
import http.client
import io
import mock
import pytest  # type: ignore
from google.resumable_media import _download
from google.resumable_media import common

        assert headers == expected

    def test__make_invalid(self):
        download = _download.ChunkedDownload(EXAMPLE_URL, 512, None)
        assert not download.invalid
        download._make_invalid()
        assert download.invalid

    def test__process_response(self):
        data = b"1234xyztL" * 37  # 9 * 37 == 33
        chunk_size = len(data)
        stream = io.BytesIO()
        download = _download.ChunkedDownload(EXAMPLE_URL, chunk_size, stream)
        _fix_up_virtual(download)

        already = 22
        download._bytes_downloaded = already
        total_bytes = 4444

        # Check internal state before.
        assert not download.finished
        assert download.bytes_downloaded == already
        assert download.total_bytes is None
        # Actually call the method to update.
        response = self._mock_response(
            already,
            already + chunk_size - 1,
            total_bytes,
            content=data,
            status_code=int(http.client.PARTIAL_CONTENT),

        )