equal
deleted
inserted
replaced
287 def sort(l): |
287 def sort(l): |
288 if not isinstance(l, list): |
288 if not isinstance(l, list): |
289 l = list(l) |
289 l = list(l) |
290 l.sort() |
290 l.sort() |
291 return l |
291 return l |
|
292 |
|
293 def increasingchunks(source, min=1024, max=65536): |
|
294 '''return no less than min bytes per chunk while data remains, |
|
295 doubling min after each chunk until it reaches max''' |
|
296 def log2(x): |
|
297 if not x: |
|
298 return 0 |
|
299 i = 0 |
|
300 while x: |
|
301 x >>= 1 |
|
302 i += 1 |
|
303 return i - 1 |
|
304 |
|
305 buf = [] |
|
306 blen = 0 |
|
307 for chunk in source: |
|
308 buf.append(chunk) |
|
309 blen += len(chunk) |
|
310 if blen >= min: |
|
311 if min < max: |
|
312 min = min << 1 |
|
313 nmin = 1 << log2(blen) |
|
314 if nmin > min: |
|
315 min = nmin |
|
316 if min > max: |
|
317 min = max |
|
318 yield ''.join(buf) |
|
319 blen = 0 |
|
320 buf = [] |
|
321 if buf: |
|
322 yield ''.join(buf) |
292 |
323 |
293 class Abort(Exception): |
324 class Abort(Exception): |
294 """Raised if a command needs to print an error and exit.""" |
325 """Raised if a command needs to print an error and exit.""" |
295 |
326 |
296 class UnexpectedOutput(Abort): |
327 class UnexpectedOutput(Abort): |