def __init__(self, it):
self.it = iter(it)
def read(self, size):
- v = next(self.it)
+ v = next(self.it, None)
return v or ''
def read_ids():
while 1:
line = line.strip()
try:
it = cp.get(line.strip())
- next(it) # skip the file type
+ next(it, None) # skip the file type
except KeyError, e:
add_error('error: %s' % e)
continue
raise
-def next(it):
- """Get the next item from an iterator, None if we reached the end."""
- try:
- return it.next()
- except StopIteration:
- return None
-
-
def merge_iter(iters, pfreq, pfunc, pfinal, key=None):
if key:
samekey = lambda e, pe: getattr(e, key) == getattr(pe, key, None)
count = 0
total = sum(len(it) for it in iters)
iters = (iter(it) for it in iters)
- heap = ((next(it),it) for it in iters)
+ heap = ((next(it, None),it) for it in iters)
heap = [(e,it) for e,it in heap if e]
heapq.heapify(heap)