mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +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:
|
else:
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def get_first(self, k, d=None):
|
||||||
|
if k in self:
|
||||||
|
return self[k][0]
|
||||||
|
else:
|
||||||
|
return d
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
return self.lst[:]
|
return self.lst[:]
|
||||||
|
|
||||||
|
@ -85,6 +85,12 @@ class TestODict:
|
|||||||
assert self.od.get("one") == ["two"]
|
assert self.od.get("one") == ["two"]
|
||||||
assert self.od.get("two") == None
|
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:
|
class TestODictCaseless:
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user