hikari.internal.routes#

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

Module Contents#

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

Route implementation for a CDN resource.

is_sizable: bool[source]#

Whether a size param can be specified.

path_template: str[source]#

Template string for this endpoint.

valid_formats: AbstractSet[str][source]#

Valid file formats for this endpoint.

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.

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.

compiled_path: str[source]#

The compiled route path to use.

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.

create_real_bucket_hash(initial_bucket_hash, authentication_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.

authentication_hashstr

The token hash.

Returns:
str

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

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.

class hikari.internal.routes.Route(method, path_template, *, has_ratelimits=True)[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.

has_ratelimits: bool[source]#

Whether this route is affected by ratelimits.

This should be left as True (the default) for most routes. This only covers specific routes where no ratelimits exist, so we can be a bit more efficient with them.

major_params: FrozenSet[str] | None[source]#

The optional major parameter name combination for this endpoint.

method: str[source]#

The HTTP method.

path_template: str[source]#

The template string used for the path.

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.