nucleus.async_utils

FormDataContextHandler

A context handler for file form data that handles closing all files in a request.

class nucleus.async_utils.FormDataContextHandler(form_data_and_file_pointers_fn)

A context handler for file form data that handles closing all files in a request.

Why do I need to wrap my requests in such a funny way?

  1. Form data must be regenerated on each request to avoid errors

    see https://github.com/Rapptz/discord.py/issues/6531

  2. Files must be properly open/closed for each request.

  3. We need to be able to do 1/2 above multiple times so that we can implement retries

    properly.

Write a function that returns a tuple of form data and file pointers, then pass it to the constructor of this class, and this class will handle the rest for you.

Parameters:

form_data_and_file_pointers_fn (Callable[Ellipsis, Tuple[FileFormData, Sequence[BinaryIO]]])