From 414a0a1602b27e9ed1d5aae42ad06d781a5461a6 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 17 Sep 2014 11:47:07 +1200 Subject: [PATCH] Adjust for state object protocol changes in mitmproxy. --- netlib/odict.py | 22 ++++++++++++---------- test/test_odict.py | 6 +++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/netlib/odict.py b/netlib/odict.py index 1e51bb3f3..3fb38d855 100644 --- a/netlib/odict.py +++ b/netlib/odict.py @@ -101,16 +101,6 @@ class ODict: def items(self): return self.lst[:] - def _get_state(self): - return [tuple(i) for i in self.lst] - - def _load_state(self, state): - self.list = [list(i) for i in state] - - @classmethod - def _from_state(klass, state): - return klass([list(i) for i in state]) - def copy(self): """ Returns a copy of this object. @@ -171,6 +161,18 @@ class ODict: self.lst = nlst return count + # Implement the StateObject protocol from mitmproxy + def get_state(self): + return [tuple(i) for i in self.lst] + + def load_state(self, state): + self.list = [list(i) for i in state] + + @classmethod + def from_state(klass, state): + return klass([list(i) for i in state]) + + class ODictCaseless(ODict): """ diff --git a/test/test_odict.py b/test/test_odict.py index 794956be7..a682d7ebe 100644 --- a/test/test_odict.py +++ b/test/test_odict.py @@ -28,10 +28,10 @@ class TestODict: self.od.add("foo", 1) self.od.add("foo", 2) self.od.add("bar", 3) - state = self.od._get_state() - nd = odict.ODict._from_state(state) + state = self.od.get_state() + nd = odict.ODict.from_state(state) assert nd == self.od - nd._load_state(state) + nd.load_state(state) def test_dictToHeader2(self): self.od["one"] = ["uno"]