

def _readinto_chunked(self, b):
    assert (self.chunked != _UNKNOWN)
    chunk_left = self.chunk_left
    total_bytes = 0
    mvb = memoryview(b)
    while True:
        if (chunk_left is None):
            try:
                chunk_left = self._read_next_chunk_size()
                if (chunk_left == 0):
                    break
            except ValueError:
                raise IncompleteRead(bytes(b[0:total_bytes]))
        if (len(mvb) < chunk_left):
            n = self._safe_readinto(mvb)
            self.chunk_left = (chunk_left - n)
            return (total_bytes + n)
        elif (len(mvb) == chunk_left):
            n = self._safe_readinto(mvb)
            self._safe_read(2)
            self.chunk_left = None
            return (total_bytes + n)
        else:
            temp_mvb = mvb[0:chunk_left]
            n = self._safe_readinto(temp_mvb)
            mvb = mvb[n:]
            total_bytes += n
        self._safe_read(2)
        chunk_left = None
    self._read_and_discard_trailer()
    self._close_conn()
    return total_bytes

dataset/ETHPy150Open OpenCobolIDE/OpenCobolIDE/open_cobol_ide/extlibs/future/backports/http/client.py HTTPResponse._readinto_chunked/original