hikari.internal.data_binding#
Data binding utilities.
Module Contents#
- hikari.internal.data_binding.JSONObject[source]#
Type hint for a JSON-decoded object representation as a mapping.
- hikari.internal.data_binding.JSONArray[source]#
Type hint for a JSON-decoded array representation as a sequence.
- hikari.internal.data_binding.JSONDecodeError: Type[Exception][source]#
Exception raised when loading an invalid JSON string.
- class hikari.internal.data_binding.URLEncodedFormBuilder(executor=None)[source]#
Helper class to generate
aiohttp.FormData
.
- class hikari.internal.data_binding.StringMapBuilder(arg=(), **kwargs)[source]#
Bases:
multidict.MultiDict
[str
]Helper class used to quickly build query strings or header maps.
This will consume any items that are not
hikari.undefined.UNDEFINED
. If a value is unspecified, it will be ignored when inserting it. This reduces the amount of boilerplate needed for generating the headers and query strings for low-level HTTP API interaction, amongst other things.Warning
Because this subclasses
dict
, you should not use the index operator to set items on this object. Doing so will skip any form of validation on the type. Use theput*
methods instead.- put(key, value, /)[source]#
- put(key: str, value: hikari.undefined.UndefinedOr[T_co], /, *, conversion: Callable[[T_co], Stringish]) None
Add a key and value to the string map.
Note
The value will always be cast to a
str
before inserting it.True
will be translated to"true"
,False
will be translated to"false"
, andNone
will be translated to"null"
.- Parameters
- key
str
The string key.
- value
hikari.undefined.UndefinedOr
[typing.Any
] The value to set.
- key
- Other Parameters
- conversion
typing.Optional
[typing.Callable
[[typing.Any
],typing.Any
]] An optional conversion to perform.
- conversion
- class hikari.internal.data_binding.JSONObjectBuilder[source]#
-
Helper class used to quickly build JSON objects from various values.
If provided with any values that are
hikari.undefined.UNDEFINED
, then these values will be ignored.This speeds up generation of JSON payloads for low level HTTP and websocket API interaction.
Warning
Because this subclasses
dict
, you should not use the index operator to set items on this object. Doing so will skip any form of validation on the type. Use theput*
methods instead.- put(key, value, /)[source]#
- put(key: str, value: hikari.undefined.UndefinedNoneOr[T_co], /, *, conversion: Callable[[T_co], JSONish]) None
Put a JSON value.
If the value is
hikari.undefined.UNDEFINED
it will not be stored.- Parameters
- key
str
The key to give the element.
- value
hikari.undefined.UndefinedOr
[typing.Any
] The JSON type to put. This may be a non-JSON type if a conversion is also specified. This may alternatively be undefined. In the latter case, nothing is performed.
- key
- Other Parameters
- conversion
typing.Optional
[typing.Callable
[[typing.Any
],JSONish
]] The optional conversion to apply.
- conversion
- put_array(key, values, /)[source]#
- put_array(key: str, values: hikari.undefined.UndefinedOr[Iterable[T_co]], /, *, conversion: Callable[[T_co], JSONish]) None
Put a JSON array.
If the value is
hikari.undefined.UNDEFINED
it will not be stored.If provided, a conversion will be applied to each item.
- Parameters
- key
str
The key to give the element.
- values
hikari.undefined.UndefinedOr
[typing.Iterable
[T_co
]] The JSON types to put. This may be an iterable of non-JSON types if a conversion is also specified. This may alternatively be undefined. In the latter case, nothing is performed.
- key
- Other Parameters
- conversion
typing.Optional
[typing.Callable
[[typing.Any
],JSONType
]] The optional conversion to apply.
- conversion
- put_snowflake(key, value, /)[source]#
Put a key with a snowflake value into the builder.
If the value is
hikari.undefined.UNDEFINED
it will not be stored.- Parameters
- key
str
The key to give the element.
- value
hikari.undefined.UndefinedNoneOr
[hikari.snowflakes.SnowflakeishOr
[hikari.snowflakes.Unique
]] The JSON type to put. This may alternatively be undefined, in this case, nothing is performed. This may also be
None
, in this case the value isn’t cast.
- key
- put_snowflake_array(key, values, /)[source]#
Put an array of snowflakes with the given key into this builder.
If the value is
hikari.undefined.UNDEFINED
it will not be stored.Each snowflake should be castable to an
int
.- Parameters
- key
str
The key to give the element.
- values
hikari.undefined.UndefinedOr
[typing.Iterable
[hikari.snowflakes.SnowflakeishOr
[hikari.snowflakes.Unique
]]] The JSON snowflakes to put. This may alternatively be undefined. In the latter case, nothing is performed.
- key