diff options
| author | Aldo Cortesi <aldo@nullcube.com> | 2013-02-28 09:28:48 +1300 |
|---|---|---|
| committer | Aldo Cortesi <aldo@nullcube.com> | 2013-02-28 09:28:48 +1300 |
| commit | 0fa63519654db2567995f3c3ac6e464796de66a3 (patch) | |
| tree | 188d65e2751ae8e42bc0ba74053a6750ff70be51 | |
| parent | f30df13384b1c31ee7bcd78b0caea37043434bcf (diff) | |
| download | mitmproxy-0fa63519654db2567995f3c3ac6e464796de66a3.tar.gz mitmproxy-0fa63519654db2567995f3c3ac6e464796de66a3.tar.bz2 mitmproxy-0fa63519654db2567995f3c3ac6e464796de66a3.zip | |
ODict.keys
| -rw-r--r-- | netlib/odict.py | 3 | ||||
| -rw-r--r-- | test/test_odict.py | 19 |
2 files changed, 22 insertions, 0 deletions
diff --git a/netlib/odict.py b/netlib/odict.py index bddb3877..0759a5bf 100644 --- a/netlib/odict.py +++ b/netlib/odict.py @@ -36,6 +36,9 @@ class ODict: ret.append(i[1]) return ret + def keys(self): + return list(set([self._kconv(i[0]) for i in self.lst])) + def _filter_lst(self, k, lst): k = self._kconv(k) new = [] diff --git a/test/test_odict.py b/test/test_odict.py index d59ed67e..26bff357 100644 --- a/test/test_odict.py +++ b/test/test_odict.py @@ -63,6 +63,15 @@ class TestODict: self.od.add("foo", 1) assert [i for i in self.od] + def test_keys(self): + assert not self.od.keys() + self.od.add("foo", 1) + assert self.od.keys() == ["foo"] + self.od.add("foo", 2) + assert self.od.keys() == ["foo"] + self.od.add("bar", 2) + assert len(self.od.keys()) == 2 + def test_copy(self): self.od.add("foo", 1) self.od.add("foo", 2) @@ -122,3 +131,13 @@ class TestODictCaseless: self.od.add("bar", 3) del self.od["foo"] assert len(self.od) == 1 + + def test_keys(self): + assert not self.od.keys() + self.od.add("foo", 1) + assert self.od.keys() == ["foo"] + self.od.add("Foo", 2) + assert self.od.keys() == ["foo"] + self.od.add("bar", 2) + assert len(self.od.keys()) == 2 + |
