def get_iter(self): source, chunk = self._get_source() if source: return self._get_iter(chunk, source) errors = group_chunk_errors(self._resp_by_chunk.items()) if len(errors) == 1: # All errors are of the same type, group them status, chunks = errors.popitem() raise exc.from_status(status[0], "%s %s" % (status[1], chunks)) raise exc.ServiceUnavailable("unavailable chunks: %s" % self._resp_by_chunk)
def stream(self): # Calling that right now will make `headers` field available # before the caller starts reading the stream parts_iter = self.get_iter() if not parts_iter: raise exc.from_status(*self._resp_by_chunk.popitem()[1]) def _iter(): for part in parts_iter: for data in part["iter"]: yield data raise StopIteration return GeneratorReader(_iter())