From 501fb3b44f14e9c0d40a63bd8b47200b01e50be9 Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Thu, 14 Apr 2016 17:23:04 +0300 Subject: regression: python3 support --- .../trex_control_plane/stl/trex_stl_lib/trex_stl_types.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py') diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py index f6718fda..d84af22f 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py @@ -1,5 +1,5 @@ -from collections import namedtuple +from collections import namedtuple, OrderedDict from .utils.text_opts import * from .trex_stl_exceptions import * import types @@ -157,3 +157,12 @@ class StatNotAvailable(object): def __cmp__(self, *args, **kwargs): raise Exception("Stat '%s' not available at this setup" % self.stat_name) +class LRU_cache(OrderedDict): + def __init__(self, maxlen = 20, *args, **kwargs): + OrderedDict.__init__(self, *args, **kwargs) + self.maxlen = maxlen + + def __setitem__(self, *args, **kwargs): + OrderedDict.__setitem__(self, *args, **kwargs) + if len(self) > self.maxlen: + self.popitem(last = False) -- cgit 1.2.3-korg