mirror of
https://github.com/romanz/amodem.git
synced 2026-04-13 17:35:24 +08:00
fix iterator issues
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user