mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Add a get_first convenience function to ODict.
This commit is contained in:
parent
1c21a28e64
commit
877a3e2062
@ -80,6 +80,12 @@ class ODict:
|
||||
else:
|
||||
return d
|
||||
|
||||
def get_first(self, k, d=None):
|
||||
if k in self:
|
||||
return self[k][0]
|
||||
else:
|
||||
return d
|
||||
|
||||
def items(self):
|
||||
return self.lst[:]
|
||||
|
||||
|
@ -85,6 +85,12 @@ class TestODict:
|
||||
assert self.od.get("one") == ["two"]
|
||||
assert self.od.get("two") == None
|
||||
|
||||
def test_get_first(self):
|
||||
self.od.add("one", "two")
|
||||
self.od.add("one", "three")
|
||||
assert self.od.get_first("one") == "two"
|
||||
assert self.od.get_first("two") == None
|
||||
|
||||
|
||||
class TestODictCaseless:
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user