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

Method setdefault

src/werkzeug/datastructures/headers.py:432–447  ·  view source on GitHub ↗

Return the first value for the key if it is in the headers, otherwise set the header to the value given by ``default`` and return that. :param key: The header key to get. :param default: The value to set for the key if it is not in the headers.

(self, key: str, default: t.Any)

Source from the content-addressed store, hash-verified

430 self.remove(key)
431
432 def setdefault(self, key: str, default: t.Any) -> str:
433 """Return the first value for the key if it is in the headers,
434 otherwise set the header to the value given by ``default`` and
435 return that.
436
437 :param key: The header key to get.
438 :param default: The value to set for the key if it is not in the
439 headers.
440 """
441 try:
442 return self._get_key(key)
443 except KeyError:
444 pass
445
446 self.set(key, default)
447 return self._get_key(key)
448
449 def setlistdefault(self, key: str, default: cabc.Iterable[t.Any]) -> list[str]:
450 """Return the list of values for the key if it is in the

Callers 5

_find_common_rootsFunction · 0.45
_set_defaultsMethod · 0.45
display_consoleMethod · 0.45
addMethod · 0.45
addMethod · 0.45

Calls 2

_get_keyMethod · 0.95
setMethod · 0.95

Tested by

no test coverage detected