Show More
@@ -79,22 +79,21 b' class AbstractReader(object):' | |||||
79 | def read(self, amt): |
|
79 | def read(self, amt): | |
80 | if self.available_data < amt and not self._finished: |
|
80 | if self.available_data < amt and not self._finished: | |
81 | raise ReadNotReady() |
|
81 | raise ReadNotReady() | |
82 |
|
|
82 | blocks = [] | |
83 | def pred(s): |
|
83 | need = amt | |
84 | needed = need[0] > 0 |
|
84 | while self._done_chunks: | |
85 |
|
|
85 | b = self.popchunk() | |
86 |
|
|
86 | if len(b) > need: | |
87 | blocks = list(itertools.takewhile(pred, self._done_chunks)) |
|
87 | nb = b[:need] | |
88 | self._done_chunks = self._done_chunks[len(blocks):] |
|
88 | self.pushchunk(b[need:]) | |
89 | over_read = sum(map(len, blocks)) - amt |
|
89 | b = nb | |
90 | if over_read > 0 and blocks: |
|
90 | blocks.append(b) | |
91 | logger.debug('need to reinsert %d data into done chunks', over_read) |
|
91 | need -= len(b) | |
92 | last = blocks[-1] |
|
92 | if need == 0: | |
93 | blocks[-1], reinsert = last[:-over_read], last[-over_read:] |
|
93 | break | |
94 | self._done_chunks.insert(0, reinsert) |
|
|||
95 | result = ''.join(blocks) |
|
94 | result = ''.join(blocks) | |
96 | assert len(result) == amt or (self._finished and len(result) < amt) |
|
95 | assert len(result) == amt or (self._finished and len(result) < amt) | |
97 | self.available_data -= amt |
|
96 | ||
98 | return result |
|
97 | return result | |
99 |
|
98 | |||
100 | def _load(self, data): # pragma: no cover |
|
99 | def _load(self, data): # pragma: no cover |
General Comments 0
You need to be logged in to leave comments.
Login now