fix iterator issues

This commit is contained in:
Roman Zeyde
2014-08-07 17:03:09 +03:00
parent 16bc186631
commit 53363ee171
6 changed files with 12 additions and 10 deletions

View File

@@ -83,7 +83,7 @@ class Splitter(object):
while True:
if all(self.read):
try:
self.last = self.iterable.next()
self.last = next(self.iterable)
except StopIteration:
return

View File

@@ -193,7 +193,7 @@ def demodulate(symbols, filters, freqs, sampler):
stats['rx_start'] = time.time()
log.info('Demodulation started')
for i, block in enumerate(itertools.izip(*streams)): # block per frequency
for i, block in enumerate(common.izip(*streams)): # block per frequency
for bits in block:
stats['rx_bits'] = stats['rx_bits'] + len(bits)
yield bits

View File

@@ -49,6 +49,8 @@ class Sampler(object):
def next(self):
return self._sample() * self.gain
__next__ = next
def _sample(self):
offset = self.offset
# offset = k + (j / self.resolution)
@@ -58,7 +60,7 @@ class Sampler(object):
end = k + self.width
while self.index < end:
self.buff[:-1] = self.buff[1:]
self.buff[-1] = self.src.next() # throws StopIteration
self.buff[-1] = next(self.src) # throws StopIteration
self.index += 1
self.offset += self.freq

View File

@@ -27,7 +27,7 @@ def record(fname, **kwargs):
def launch(*args, **kwargs):
args = map(str, args)
args = list(map(str, args))
log.debug('$ %s', ' '.join(args))
p = sp.Popen(args=args, **kwargs)
p.stop = lambda: os.kill(p.pid, signal.SIGKILL)

View File

@@ -25,13 +25,13 @@ def test_iterate():
def test_split():
L = [(i*2, i*2+1) for i in range(10)]
iters = common.split(L, n=2)
assert zip(*iters) == L
assert list(zip(*iters)) == L
for i in [0, 1]:
iters = common.split(L, n=2)
iters[i].next()
next(iters[i])
try:
iters[i].next()
next(iters[i])
assert False
except IndexError as e:
assert e.args == (i,)
@@ -43,8 +43,8 @@ def test_icapture():
z = []
for i in common.icapture(x, result=y):
z.append(i)
assert x == y
assert x == z
assert list(x) == y
assert list(x) == z
def test_dumps_loads():

View File

@@ -19,7 +19,7 @@ def test_read():
p.stdin.close()
f = stream.Reader(p.stdout)
result = zip(range(10), f)
result = list(zip(range(10), f))
p.kill()
j = 0