MCPcopy
hub / github.com/urllib3/urllib3 / ensure_can_construct_http_header_dict

Function ensure_can_construct_http_header_dict

src/urllib3/_collections.py:43–60  ·  view source on GitHub ↗
(
    potential: object,
)

Source from the content-addressed store, hash-verified

41
42
43def ensure_can_construct_http_header_dict(
44 potential: object,
45) -> ValidHTTPHeaderSource | None:
46 if isinstance(potential, HTTPHeaderDict):
47 return potential
48 elif isinstance(potential, typing.Mapping):
49 # Full runtime checking of the contents of a Mapping is expensive, so for the
50 # purposes of typechecking, we assume that any Mapping is the right shape.
51 return typing.cast(typing.Mapping[str, str], potential)
52 elif isinstance(potential, typing.Iterable):
53 # Similarly to Mapping, full runtime checking of the contents of an Iterable is
54 # expensive, so for the purposes of typechecking, we assume that any Iterable
55 # is the right shape.
56 return typing.cast(typing.Iterable[tuple[str, str]], potential)
57 elif hasattr(potential, "keys") and hasattr(potential, "__getitem__"):
58 return typing.cast("HasGettableStringKeys", potential)
59 else:
60 return None
61
62
63class RecentlyUsedContainer(typing.Generic[_KT, _VT], typing.MutableMapping[_KT, _VT]):

Callers 4

__eq__Method · 0.85
__ior__Method · 0.85
__or__Method · 0.85
__ror__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected