MCPcopy
hub / github.com/encode/httpx / __init__

Method __init__

httpx/_urls.py:425–461  ·  view source on GitHub ↗
(self, *args: QueryParamTypes | None, **kwargs: typing.Any)

Source from the content-addressed store, hash-verified

423 """
424
425 def __init__(self, *args: QueryParamTypes | None, **kwargs: typing.Any) -> None:
426 assert len(args) < 2, "Too many arguments."
427 assert not (args and kwargs), "Cannot mix named and unnamed arguments."
428
429 value = args[0] if args else kwargs
430
431 if value is None or isinstance(value, (str, bytes)):
432 value = value.decode("ascii") if isinstance(value, bytes) else value
433 self._dict = parse_qs(value, keep_blank_values=True)
434 elif isinstance(value, QueryParams):
435 self._dict = {k: list(v) for k, v in value._dict.items()}
436 else:
437 dict_value: dict[typing.Any, list[typing.Any]] = {}
438 if isinstance(value, (list, tuple)):
439 # Convert list inputs like:
440 # [("a", "123"), ("a", "456"), ("b", "789")]
441 # To a dict representation, like:
442 # {"a": ["123", "456"], "b": ["789"]}
443 for item in value:
444 dict_value.setdefault(item[0], []).append(item[1])
445 else:
446 # Convert dict inputs like:
447 # {"a": "123", "b": ["456", "789"]}
448 # To dict inputs where values are always lists, like:
449 # {"a": ["123"], "b": ["456", "789"]}
450 dict_value = {
451 k: list(v) if isinstance(v, (list, tuple)) else [v]
452 for k, v in value.items()
453 }
454
455 # Ensure that keys and values are neatly coerced to strings.
456 # We coerce values `True` and `False` to JSON-like "true" and "false"
457 # representations, and coerce `None` values to the empty string.
458 self._dict = {
459 str(k): [primitive_value_to_str(item) for item in v]
460 for k, v in dict_value.items()
461 }
462
463 def keys(self) -> typing.KeysView[str]:
464 """

Callers

nothing calls this directly

Calls 3

primitive_value_to_strFunction · 0.85
decodeMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected