From aefe6fcbe454cd014487523c5470d933fa70e95c Mon Sep 17 00:00:00 2001
From: Pierre LALET <pierre.lalet@cea.fr>
Date: Sun, 17 Jan 2016 17:46:50 +0100
Subject: [PATCH] Use __slots__ for PacketList (and subclasses)

---
 scapy/base_classes.py | 4 ++--
 scapy/layers/inet.py  | 1 +
 scapy/layers/inet6.py | 1 +
 scapy/plist.py        | 6 +++---
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/scapy/base_classes.py b/scapy/base_classes.py
index 4f4dc116..01f9fb3a 100644
--- a/scapy/base_classes.py
+++ b/scapy/base_classes.py
@@ -250,5 +250,5 @@ class BasePacket(Gen):
 ## Packet list base classe ##
 #############################
 
-class BasePacketList:
-    pass
+class BasePacketList(object):
+    __slots__ = []
diff --git a/scapy/layers/inet.py b/scapy/layers/inet.py
index 6cc4303d..a8a52938 100644
--- a/scapy/layers/inet.py
+++ b/scapy/layers/inet.py
@@ -937,6 +937,7 @@ PacketList.timeskew_graph = new.instancemethod(_packetlist_timeskew_graph, None,
 
 ### Create a new packet list
 class TracerouteResult(SndRcvList):
+    __slots__ = ["graphdef", "graphASres", "padding", "hloc", "nloc"]
     def __init__(self, res=None, name="Traceroute", stats=None):
         PacketList.__init__(self, res, name, stats)
         self.graphdef = None
diff --git a/scapy/layers/inet6.py b/scapy/layers/inet6.py
index 9dc92692..63b6f06d 100644
--- a/scapy/layers/inet6.py
+++ b/scapy/layers/inet6.py
@@ -2888,6 +2888,7 @@ class  AS_resolver6(AS_resolver_riswhois):
         return ip,asn,desc        
 
 class TracerouteResult6(TracerouteResult):
+    __slots__ = []
     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 !
                                               s.hlim,
diff --git a/scapy/plist.py b/scapy/plist.py
index 0308620e..78b6f4a5 100644
--- a/scapy/plist.py
+++ b/scapy/plist.py
@@ -26,7 +26,7 @@ if arch.GNUPLOT:
 #############
 
 class PacketList(BasePacketList):
-    res = []
+    __slots__ = ["stats", "res", "listname"]
     def __init__(self, res=None, name="PacketList", stats=None):
         """create a packet list from a list of packets
            res: the list of packets
@@ -47,8 +47,7 @@ class PacketList(BasePacketList):
     def _elt2show(self, elt):
         return self._elt2sum(elt)
     def __repr__(self):
-#        stats=dict.fromkeys(self.stats,0) ## needs python >= 2.3  :(
-        stats = dict(map(lambda x: (x,0), self.stats))
+        stats = dict((x, 0) for x in self.stats)
         other = 0
         for r in self.res:
             f = 0
@@ -477,6 +476,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis
 
 
 class SndRcvList(PacketList):
+    __slots__ = []
     def __init__(self, res=None, name="Results", stats=None):
         PacketList.__init__(self, res, name, stats)
     def _elt2pkt(self, elt):
-- 
GitLab