Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _next_block(self):
"""
Reads the next block from `ResponseData`. If there are problems
reading from it, an error will be reported to the client"
"""
self._last_block_sent += 1
if self._last_block_sent > constants.MAX_BLOCK_NUMBER:
self._last_block_sent = 0 # Wrap around the block counter.
try:
last_size = 0 # current_block size before read. Used to check EOF.
self._current_block = self._response_data.read(self._block_size)
while (
len(self._current_block) != self._block_size
and len(self._current_block) != last_size
):
last_size = len(self._current_block)
self._current_block += self._response_data.read(
self._block_size - last_size
)
except Exception as e:
logging.exception("Error while reading from source: %s" % e)
self._stats.error = {
"error_code": constants.ERR_UNDEFINED,