MCPcopy
hub / github.com/pallets/werkzeug / index

Method index

src/werkzeug/datastructures/accept.py:110–124  ·  view source on GitHub ↗

Get the position of an entry or raise :exc:`ValueError`. :param key: The key to be looked up. .. versionchanged:: 0.5 This used to raise :exc:`IndexError`, which was inconsistent with the list API.

(self, key: str | tuple[str, float])

Source from the content-addressed store, hash-verified

108 return f"{type(self).__name__}([{pairs_str}])"
109
110 def index(self, key: str | tuple[str, float]) -> int: # type: ignore[override]
111 """Get the position of an entry or raise :exc:`ValueError`.
112
113 :param key: The key to be looked up.
114
115 .. versionchanged:: 0.5
116 This used to raise :exc:`IndexError`, which was inconsistent
117 with the list API.
118 """
119 if isinstance(key, str):
120 for idx, (item, _quality) in enumerate(self):
121 if self._value_matches(key, item):
122 return idx
123 raise ValueError(key)
124 return list.index(self, key)
125
126 def find(self, key: str | tuple[str, float]) -> int:
127 """Get the position of an entry or return -1.

Callers 4

findMethod · 0.95
_findFunction · 0.45
test_basic_interfaceMethod · 0.45
test_accept_basicMethod · 0.45

Calls 1

_value_matchesMethod · 0.95

Tested by 2

test_basic_interfaceMethod · 0.36
test_accept_basicMethod · 0.36