equal
deleted
inserted
replaced
1290 def read(self, l=None): |
1290 def read(self, l=None): |
1291 """Read L bytes of data from the iterator of chunks of data. |
1291 """Read L bytes of data from the iterator of chunks of data. |
1292 Returns less than L bytes if the iterator runs dry. |
1292 Returns less than L bytes if the iterator runs dry. |
1293 |
1293 |
1294 If size parameter is omitted, read everything""" |
1294 If size parameter is omitted, read everything""" |
|
1295 if l is None: |
|
1296 return ''.join(self.iter) |
|
1297 |
1295 left = l |
1298 left = l |
1296 buf = [] |
1299 buf = [] |
1297 queue = self._queue |
1300 queue = self._queue |
1298 while left is None or left > 0: |
1301 while left > 0: |
1299 # refill the queue |
1302 # refill the queue |
1300 if not queue: |
1303 if not queue: |
1301 target = 2**18 |
1304 target = 2**18 |
1302 for chunk in self.iter: |
1305 for chunk in self.iter: |
1303 queue.append(chunk) |
1306 queue.append(chunk) |
1306 break |
1309 break |
1307 if not queue: |
1310 if not queue: |
1308 break |
1311 break |
1309 |
1312 |
1310 chunk = queue.popleft() |
1313 chunk = queue.popleft() |
1311 if left is not None: |
1314 left -= len(chunk) |
1312 left -= len(chunk) |
1315 if left < 0: |
1313 if left is not None and left < 0: |
|
1314 queue.appendleft(chunk[left:]) |
1316 queue.appendleft(chunk[left:]) |
1315 buf.append(chunk[:left]) |
1317 buf.append(chunk[:left]) |
1316 else: |
1318 else: |
1317 buf.append(chunk) |
1319 buf.append(chunk) |
1318 |
1320 |