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:
YAMAMOTO Takashi 2013-11-22 13:41:31 +09:00 committed by FUJITA Tomonori
parent 4cb7683f2f
commit afcdb5f123

View File

@ -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]