Packet: fix iterator
replace Packet.__iter__ which doesn't work in cases like nested iterations. Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
4cb7683f2f
commit
afcdb5f123
@ -41,7 +41,6 @@ class Packet(object):
|
||||
self.protocols = []
|
||||
else:
|
||||
self.protocols = protocols
|
||||
self.protocol_idx = 0
|
||||
if self.data:
|
||||
self._parser(parse_cls)
|
||||
|
||||
@ -106,22 +105,12 @@ class Packet(object):
|
||||
return result[0]
|
||||
return None
|
||||
|
||||
def next(self):
|
||||
try:
|
||||
p = self.protocols[self.protocol_idx]
|
||||
except:
|
||||
self.protocol_idx = 0
|
||||
raise StopIteration
|
||||
|
||||
self.protocol_idx += 1
|
||||
return p
|
||||
|
||||
def __div__(self, trailer):
|
||||
self.add_protocol(trailer)
|
||||
return self
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
return iter(self.protocols)
|
||||
|
||||
def __getitem__(self, idx):
|
||||
return self.protocols[idx]
|
||||
|
Loading…
Reference in New Issue
Block a user