MCPcopy Index your code
hub / github.com/python-telegram-bot/python-telegram-bot / RequestData

Class RequestData

src/telegram/request/_requestdata.py:31–143  ·  view source on GitHub ↗

Instances of this class collect the data needed for one request to the Bot API, including all parameters and files to be sent along with the request. .. versionadded:: 20.0 Warning: How exactly instances of this are created should be considered an implementation detail

Source from the content-addressed store, hash-verified

29
30@final
31class RequestData:
32 """Instances of this class collect the data needed for one request to the Bot API, including
33 all parameters and files to be sent along with the request.
34
35 .. versionadded:: 20.0
36
37 Warning:
38 How exactly instances of this are created should be considered an implementation detail
39 and not part of PTBs public API. Users should exclusively rely on the documented
40 attributes, properties and methods.
41
42 Attributes:
43 contains_files (:obj:`bool`): Whether this object contains files to be uploaded via
44 ``multipart/form-data``.
45 """
46
47 __slots__ = ("_parameters", "contains_files")
48
49 def __init__(self, parameters: list[RequestParameter] | None = None):
50 self._parameters: list[RequestParameter] = parameters or []
51 self.contains_files: bool = any(param.input_files for param in self._parameters)
52
53 @property
54 def parameters(self) -> dict[str, str | int | list[Any] | dict[Any, Any]]:
55 """Gives the parameters as mapping of parameter name to the parameter value, which can be
56 a single object of type :obj:`int`, :obj:`float`, :obj:`str` or :obj:`bool` or any
57 (possibly nested) composition of lists, tuples and dictionaries, where each entry, key
58 and value is of one of the mentioned types.
59
60 Returns:
61 dict[:obj:`str`, :obj:`str` | :obj:`int` | list[any] | dict[any, any]]
62 """
63 return {
64 param.name: param.value # type: ignore[misc]
65 for param in self._parameters
66 if param.value is not None
67 }
68
69 @property
70 def json_parameters(self) -> dict[str, str]:
71 """Gives the parameters as mapping of parameter name to the respective JSON encoded
72 value.
73
74 Tip:
75 By default, this property uses the standard library's :func:`json.dumps`.
76 To use a custom library for JSON encoding, you can directly encode the keys of
77 :attr:`parameters` - note that string valued keys should not be JSON encoded.
78
79 Returns:
80 dict[:obj:`str`, :obj:`str`]
81 """
82 return {
83 param.name: param.json_value
84 for param in self._parameters
85 if param.json_value is not None
86 }
87
88 def url_encoded_parameters(self, encode_kwargs: dict[str, Any] | None = None) -> str:

Callers 7

_do_postMethod · 0.90
simple_rqsFunction · 0.90
file_rqsFunction · 0.90
mixed_rqsFunction · 0.90
test_url_encodingMethod · 0.90

Calls

no outgoing calls

Tested by 6

simple_rqsFunction · 0.72
file_rqsFunction · 0.72
mixed_rqsFunction · 0.72
test_url_encodingMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…