hikari.internal.routes#

Provides the valid routes that can be used on the API and the CDN.

Module Contents#

class hikari.internal.routes.CompiledRoute[source]#

A compiled representation of a route to a specific resource.

This is a similar representation to what Route provides, except Route is treated as a template, this is treated as an instance.

property method: str[source]#

Return the HTTP method of this compiled route.

major_param_hash: str[source]#

The major parameters in a bucket hash-compatible representation.

route: Route[source]#

The route this compiled route was created from.

compiled_path: str[source]#

The compiled route path to use.

create_url(base_url)[source]#

Create the full URL with which you can make a request.

Parameters
base_urlstr

The base of the URL to prepend to the compiled path.

Returns
str

The full URL for the route.

create_real_bucket_hash(initial_bucket_hash)[source]#

Create a full bucket hash from a given initial hash.

The result of this hash will be decided by the value of the major parameters passed to the route during the compilation phase.

Parameters
initial_bucket_hashstr

The initial bucket hash provided by Discord in the HTTP headers for a given response.

Returns
str

The input hash amalgamated with a hash code produced by the major parameters in this compiled route instance.

class hikari.internal.routes.Route(method, path_template)[source]#

A template used to create compiled routes for specific parameters.

These compiled routes are used to identify rate limit buckets. Compiled routes may have a single major parameter.

Parameters
methodstr

The HTTP method.

path_templatestr

The template string for the path to use.

method: str[source]#

The HTTP method.

path_template: str[source]#

The template string used for the path.

major_params: Optional[FrozenSet[str]][source]#

The optional major parameter name combination for this endpoint.

compile(**kwargs)[source]#

Generate a formatted CompiledRoute for this route.

This takes into account any URL parameters that have been passed.

Parameters
**kwargstyping.Any

Any parameters to interpolate into the route path.

Returns
CompiledRoute

The compiled route.

class hikari.internal.routes.CDNRoute[source]#

Route implementation for a CDN resource.

path_template: str[source]#

Template string for this endpoint.

valid_formats: AbstractSet[str][source]#

Valid file formats for this endpoint.

is_sizable: bool[source]#

Whether a size param can be specified.

compile(base_url, *, file_format, size=None, **kwargs)[source]#

Generate a full CDN url from this endpoint.

Parameters
base_urlstr

The base URL for the CDN. The generated route is concatenated onto this.

file_formatstr

The file format to use for the asset.

sizetyping.Optional[int]

The custom size query parameter to set. If None, it is not passed.

**kwargstyping.Any

Parameters to interpolate into the path template.

Returns
str

The full asset URL.

Raises
TypeError

If a GIF is requested, but the asset is not animated; if an invalid file format for the endpoint is passed; or if a size is passed but the route is not sizable.

ValueError

If size is specified, but is not an integer power of 2 between 16 and 4096 inclusive or is negative.

compile_to_file(base_url, *, file_format, size=None, **kwargs)[source]#

Perform the same as compile, but return the URL as a files.URL.