packet lib: For convenience, make packet into a sequence type

Protocols can mow be accesed as packet[n].

Signed-off-by: Shaun Crampton <Shaun.Crampton@metaswitch.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Shaun Crampton 2013-06-05 10:39:37 -07:00 committed by FUJITA Tomonori
parent 43b439770b
commit 95f79d6a51

View File

@ -95,3 +95,15 @@ class Packet(object):
def __iter__(self):
return self
def __getitem__(self, idx):
return self.protocols[idx]
def __setitem__(self, idx, item):
self.protocols[idx] = item
def __delitem__(self, idx):
del self.protocols[idx]
def __len__(self):
return len(self.protocols)