MCPcopy
hub / github.com/encode/starlette / setdefault

Method setdefault

starlette/datastructures.py:631–643  ·  view source on GitHub ↗

If the header `key` does not exist, then set it to `value`. Returns the header value.

(self, key: str, value: str)

Source from the content-addressed store, hash-verified

629 return self._list
630
631 def setdefault(self, key: str, value: str) -> str:
632 """
633 If the header `key` does not exist, then set it to `value`.
634 Returns the header value.
635 """
636 set_key = key.lower().encode("latin-1")
637 set_value = value.encode("latin-1")
638
639 for idx, (item_key, item_value) in enumerate(self._list):
640 if item_key == set_key:
641 return item_value.decode("latin-1")
642 self._list.append((set_key, set_value))
643 return value
644
645 def update(self, other: Mapping[str, str]) -> None:
646 for key, val in other.items():

Callers 1

test_mutable_headersFunction · 0.95

Calls 2

decodeMethod · 0.80
appendMethod · 0.45

Tested by 1

test_mutable_headersFunction · 0.76