From 45463744d5226c3dc57b94e38b82d73109c08015 Mon Sep 17 00:00:00 2001 From: Pierre LALET <pierre.lalet@cea.fr> Date: Wed, 23 Aug 2017 10:55:52 +0200 Subject: [PATCH] CacheInstance: use timestamp in .update() --- scapy/config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scapy/config.py b/scapy/config.py index 3408648b..871c182c 100755 --- a/scapy/config.py +++ b/scapy/config.py @@ -201,8 +201,12 @@ class CacheInstance(dict, object): self._timetable[item] = time.time() dict.__setitem__(self, item,v) def update(self, other): - dict.update(self, other) - self._timetable.update(other._timetable) + for key, value in other.iteritems(): + # We only update an element from `other` either if it does + # not exist in `self` or if the entry in `self` is older. + if key not in self or self._timetable[key] < other._timetable[key]: + dict.__setitem__(self, key, value) + self._timetable[key] = other._timetable[key] def iteritems(self): if self.timeout is None: return six.iteritems(self.__dict__) -- GitLab