Show More
@@ -15,7 +15,7 b' hide platform-specific details from the ' | |||
|
15 | 15 | |
|
16 | 16 | from i18n import _ |
|
17 | 17 | import error, osutil, encoding |
|
18 |
import |
|
|
18 | import errno, re, shutil, sys, tempfile, traceback | |
|
19 | 19 | import os, stat, time, calendar, textwrap, unicodedata, signal |
|
20 | 20 | import imp |
|
21 | 21 | |
@@ -909,31 +909,36 b' class chunkbuffer(object):' | |||
|
909 | 909 | """in_iter is the iterator that's iterating over the input chunks. |
|
910 | 910 | targetsize is how big a buffer to try to maintain.""" |
|
911 | 911 | self.iter = iter(in_iter) |
|
912 |
self. |
|
|
913 | self.targetsize = 2**16 | |
|
912 | self._queue = [] | |
|
914 | 913 | |
|
915 | 914 | def read(self, l): |
|
916 | 915 | """Read L bytes of data from the iterator of chunks of data. |
|
917 | 916 | Returns less than L bytes if the iterator runs dry.""" |
|
918 | if l > len(self.buf) and self.iter: | |
|
919 | # Clamp to a multiple of self.targetsize | |
|
920 | targetsize = max(l, self.targetsize) | |
|
921 | collector = cStringIO.StringIO() | |
|
922 | collector.write(self.buf) | |
|
923 | collected = len(self.buf) | |
|
917 | left = l | |
|
918 | buf = '' | |
|
919 | queue = self._queue | |
|
920 | while left > 0: | |
|
921 | # refill the queue | |
|
922 | if not queue: | |
|
923 | target = 2**18 | |
|
924 | 924 | for chunk in self.iter: |
|
925 |
|
|
|
926 |
|
|
|
927 |
if |
|
|
925 | queue.append(chunk) | |
|
926 | target -= len(chunk) | |
|
927 | if target <= 0: | |
|
928 | break | |
|
929 | if not queue: | |
|
928 | 930 | break |
|
929 | if collected < targetsize: | |
|
930 | self.iter = False | |
|
931 |
|
|
|
932 |
if le |
|
|
933 | s, self.buf = str(self.buf), '' | |
|
931 | ||
|
932 | chunk = queue.pop(0) | |
|
933 | left -= len(chunk) | |
|
934 | if left < 0: | |
|
935 | queue.insert(0, chunk[left:]) | |
|
936 | buf += chunk[:left] | |
|
934 | 937 | else: |
|
935 | s, self.buf = self.buf[:l], buffer(self.buf, l) | |
|
936 | return s | |
|
938 | buf += chunk | |
|
939 | ||
|
940 | return buf | |
|
941 | ||
|
937 | 942 | |
|
938 | 943 | def filechunkiter(f, size=65536, limit=None): |
|
939 | 944 | """Create a generator that produces the data in the file size |
General Comments 0
You need to be logged in to leave comments.
Login now