Show More
@@ -57,10 +57,21 b' class AbstractReader(object):' | |||||
57 | def __init__(self): |
|
57 | def __init__(self): | |
58 | self._finished = False |
|
58 | self._finished = False | |
59 | self._done_chunks = [] |
|
59 | self._done_chunks = [] | |
|
60 | self.available_data = 0 | |||
60 |
|
61 | |||
61 | @property |
|
62 | def addchunk(self, data): | |
62 | def available_data(self): |
|
63 | self._done_chunks.append(data) | |
63 | return sum(map(len, self._done_chunks)) |
|
64 | self.available_data += len(data) | |
|
65 | ||||
|
66 | def pushchunk(self, data): | |||
|
67 | self._done_chunks.insert(0, data) | |||
|
68 | self.available_data += len(data) | |||
|
69 | ||||
|
70 | def popchunk(self): | |||
|
71 | b = self._done_chunks.pop(0) | |||
|
72 | self.available_data -= len(b) | |||
|
73 | ||||
|
74 | return b | |||
64 |
|
75 | |||
65 | def done(self): |
|
76 | def done(self): | |
66 | return self._finished |
|
77 | return self._finished | |
@@ -83,6 +94,7 b' class AbstractReader(object):' | |||||
83 | self._done_chunks.insert(0, reinsert) |
|
94 | self._done_chunks.insert(0, reinsert) | |
84 | result = ''.join(blocks) |
|
95 | result = ''.join(blocks) | |
85 | assert len(result) == amt or (self._finished and len(result) < amt) |
|
96 | assert len(result) == amt or (self._finished and len(result) < amt) | |
|
97 | self.available_data -= amt | |||
86 | return result |
|
98 | return result | |
87 |
|
99 | |||
88 | def _load(self, data): # pragma: no cover |
|
100 | def _load(self, data): # pragma: no cover | |
@@ -121,7 +133,7 b' class AbstractSimpleReader(AbstractReade' | |||||
121 | assert not self._finished, ( |
|
133 | assert not self._finished, ( | |
122 | 'tried to add data (%r) to a closed reader!' % data) |
|
134 | 'tried to add data (%r) to a closed reader!' % data) | |
123 | logger.debug('%s read an additional %d data', self.name, len(data)) |
|
135 | logger.debug('%s read an additional %d data', self.name, len(data)) | |
124 |
self. |
|
136 | self.addchunk(data) | |
125 |
|
137 | |||
126 |
|
138 | |||
127 | class CloseIsEndReader(AbstractSimpleReader): |
|
139 | class CloseIsEndReader(AbstractSimpleReader): | |
@@ -190,6 +202,6 b' class ChunkedReader(AbstractReader):' | |||||
190 | self._finished = True |
|
202 | self._finished = True | |
191 | logger.debug('closing chunked reader due to chunk of length 0') |
|
203 | logger.debug('closing chunked reader due to chunk of length 0') | |
192 | return |
|
204 | return | |
193 |
self. |
|
205 | self.addchunk(data[block_start:block_start + amt]) | |
194 | position = block_start + amt + len(self._eol) |
|
206 | position = block_start + amt + len(self._eol) | |
195 | # no-check-code |
|
207 | # no-check-code |
General Comments 0
You need to be logged in to leave comments.
Login now