@@ -42,19 +42,20 @@ def getall(self, key, default=_marker):
42
42
res = tuple ([v for k , v in self ._items if k == key ])
43
43
if res :
44
44
return res
45
- if not res and default != _marker :
45
+ if not res and default is not _marker :
46
46
return default
47
47
raise KeyError ('Key not found: %r' % key )
48
48
49
49
def getone (self , key , default = _marker ):
50
50
"""
51
- Get one value matching the key, raising a KeyError if multiple
52
- values were found.
51
+ Get first value matching the key
53
52
"""
54
- v = self .getall (key , default = _marker )
55
- if len (v ) > 1 and v != default :
56
- raise KeyError ('Multiple values match %r: %r' % (key , v ))
57
- return v [0 ]
53
+ for k , v in self ._items :
54
+ if k == key :
55
+ return v
56
+ if default is not _marker :
57
+ return default
58
+ raise KeyError ('Key not found: %r' % key )
58
59
59
60
# extra methods #
60
61
@@ -269,12 +270,14 @@ def __init__(self, items, *, getall=False):
269
270
super ().__init__ (items_to_use )
270
271
271
272
def __contains__ (self , value ):
272
- values = [item [1 ] for item in self ._mapping ]
273
- return value in values
273
+ for item in self ._mapping :
274
+ if item [1 ] == value :
275
+ return True
276
+ return False
274
277
275
278
def __iter__ (self ):
276
- values = ( item [ 1 ] for item in self ._mapping )
277
- yield from values
279
+ for item in self ._mapping :
280
+ yield item [ 1 ]
278
281
279
282
280
283
class _KeysView (abc .KeysView ):
0 commit comments