Skip to content
Snippets Groups Projects
Commit aefe6fcb authored by Pierre LALET's avatar Pierre LALET
Browse files

Use __slots__ for PacketList (and subclasses)

parent b30167aa
No related branches found
No related tags found
No related merge requests found
...@@ -250,5 +250,5 @@ class BasePacket(Gen): ...@@ -250,5 +250,5 @@ class BasePacket(Gen):
## Packet list base classe ## ## Packet list base classe ##
############################# #############################
class BasePacketList: class BasePacketList(object):
pass __slots__ = []
...@@ -937,6 +937,7 @@ PacketList.timeskew_graph = new.instancemethod(_packetlist_timeskew_graph, None, ...@@ -937,6 +937,7 @@ PacketList.timeskew_graph = new.instancemethod(_packetlist_timeskew_graph, None,
### Create a new packet list ### Create a new packet list
class TracerouteResult(SndRcvList): class TracerouteResult(SndRcvList):
__slots__ = ["graphdef", "graphASres", "padding", "hloc", "nloc"]
def __init__(self, res=None, name="Traceroute", stats=None): def __init__(self, res=None, name="Traceroute", stats=None):
PacketList.__init__(self, res, name, stats) PacketList.__init__(self, res, name, stats)
self.graphdef = None self.graphdef = None
......
...@@ -2888,6 +2888,7 @@ class AS_resolver6(AS_resolver_riswhois): ...@@ -2888,6 +2888,7 @@ class AS_resolver6(AS_resolver_riswhois):
return ip,asn,desc return ip,asn,desc
class TracerouteResult6(TracerouteResult): class TracerouteResult6(TracerouteResult):
__slots__ = []
def show(self): def show(self):
return self.make_table(lambda (s,r): (s.sprintf("%-42s,IPv6.dst%:{TCP:tcp%TCP.dport%}{UDP:udp%UDP.dport%}{ICMPv6EchoRequest:IER}"), # TODO: ICMPv6 ! return self.make_table(lambda (s,r): (s.sprintf("%-42s,IPv6.dst%:{TCP:tcp%TCP.dport%}{UDP:udp%UDP.dport%}{ICMPv6EchoRequest:IER}"), # TODO: ICMPv6 !
s.hlim, s.hlim,
......
...@@ -26,7 +26,7 @@ if arch.GNUPLOT: ...@@ -26,7 +26,7 @@ if arch.GNUPLOT:
############# #############
class PacketList(BasePacketList): class PacketList(BasePacketList):
res = [] __slots__ = ["stats", "res", "listname"]
def __init__(self, res=None, name="PacketList", stats=None): def __init__(self, res=None, name="PacketList", stats=None):
"""create a packet list from a list of packets """create a packet list from a list of packets
res: the list of packets res: the list of packets
...@@ -47,8 +47,7 @@ class PacketList(BasePacketList): ...@@ -47,8 +47,7 @@ class PacketList(BasePacketList):
def _elt2show(self, elt): def _elt2show(self, elt):
return self._elt2sum(elt) return self._elt2sum(elt)
def __repr__(self): def __repr__(self):
# stats=dict.fromkeys(self.stats,0) ## needs python >= 2.3 :( stats = dict((x, 0) for x in self.stats)
stats = dict(map(lambda x: (x,0), self.stats))
other = 0 other = 0
for r in self.res: for r in self.res:
f = 0 f = 0
...@@ -477,6 +476,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis ...@@ -477,6 +476,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis
class SndRcvList(PacketList): class SndRcvList(PacketList):
__slots__ = []
def __init__(self, res=None, name="Results", stats=None): def __init__(self, res=None, name="Results", stats=None):
PacketList.__init__(self, res, name, stats) PacketList.__init__(self, res, name, stats)
def _elt2pkt(self, elt): def _elt2pkt(self, elt):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment