Repository: Avaiga/taipy
File: taipy/gui/gui_actions.py (Python)

Code before:
import threading
import typing as t

from ._warnings import _warn
from .gui import Gui
from .state import State


def download(
    state: State, content: t.Any, name: t.Optional[str] = "", on_action: t.Optional[t.Union[str, t.Callable]] = ""
):
    """Download content to the client.

    Arguments:
        state (State^): The current user state as received in any callback.
        content: File path or file content. See below.
        name: File name for the content on the client browser (defaults to content name).
        on_action: Callback function (or callback name) to call when the download ends. See below.

    <h4>Notes:</h4>

    - *content*: this parameter can hold several values depending on your use case:
        - a string: the value must be an existing path name to the file that gets downloaded or
          the URL to the resource you want to download.
        - a buffer (such as a `bytes` object): if the size of the buffer is smaller than
           the [*data_url_max_size*](../../userman/advanced_features/configuration/gui-config.md#p-data_url_max_size) configuration
           setting, then the [`python-magic`](https://pypi.org/project/python-magic/) package is
           used to determine the [MIME type](https://en.wikipedia.org/wiki/Media_type) of the
           buffer content, and the download is performed using a generated "data:" URL with
           the relevant type, and a base64-encoded version of the buffer content.<br/>
           If the buffer is too large, its content is transferred after saving it in a temporary
           server file.
      - *on_action*: this callback is triggered when the transfer of the content is achieved.</br>
           In this function, you can perform any clean-up operation that could be required after
           the download is completed.<br/>
           This callback can use three optional parameters:
           - *state*: the `State^` instance of the caller.
           - *id* (optional): a string representing the identifier of the caller. If this function
             is called directly, this will always be "Gui.download". Some controls may also trigger
             download actions, and then *id* would reflect the identifier of those controls.
           - *payload* (optional): an optional payload from the caller.<br/>
             This is a dictionary with the following keys:
              - *action*: the name of the callback;
              - *args*: an array of two strings. The first element reflects the *name* parameter,
                and the second element reflects the server-side URL where the file is located.
    """
    if state and isinstance(state._gui, Gui):
        state._gui._download(content, name, on_action)
    else:
        _warn("'download()' must be called in the context of a callback.")


Review comment (suggestion):
```suggestion
           [*data_url_max_size*](../../userman/advanced_features/configuration/gui-config.md#p-data_url_max_size) configuration
```

Code after:
import threading
import typing as t

from ._warnings import _warn
from .gui import Gui
from .state import State


def download(
    state: State, content: t.Any, name: t.Optional[str] = "", on_action: t.Optional[t.Union[str, t.Callable]] = ""
):
    """Download content to the client.

    Arguments:
        state (State^): The current user state as received in any callback.
        content: File path or file content. See below.
        name: File name for the content on the client browser (defaults to content name).
        on_action: Callback function (or callback name) to call when the download ends. See below.

    <h4>Notes:</h4>

    - *content*: this parameter can hold several values depending on your use case:
        - a string: the value must be an existing path name to the file that gets downloaded or
          the URL to the resource you want to download.
        - a buffer (such as a `bytes` object): if the size of the buffer is smaller than the
          [*data_url_max_size*](../../userman/advanced_features/configuration/gui-config.md#p-data_url_max_size)
          configuration setting, then the [`python-magic`](https://pypi.org/project/python-magic/)
          package is used to determine the [MIME type](https://en.wikipedia.org/wiki/Media_type)
          of the buffer content, and the download is performed using a generated "data:" URL with
          the relevant type, and a base64-encoded version of the buffer content.<br/>
          If the buffer is too large, its content is transferred after saving it in a temporary
          server file.
        - *on_action*: this callback is triggered when the transfer of the content is achieved.</br>
          In this function, you can perform any clean-up operation that could be required after
          the download is completed.<br/>
          This callback can use three optional parameters:
            - *state*: the `State^` instance of the caller.
            - *id* (optional): a string representing the identifier of the caller. If this function
              is called directly, this will always be "Gui.download". Some controls may also trigger
              download actions, and then *id* would reflect the identifier of those controls.
            - *payload* (optional): an optional payload from the caller.<br/>
              This is a dictionary with the following keys:
                - *action*: the name of the callback;
                - *args*: an array of two strings. The first element reflects the *name* parameter,
                  and the second element reflects the server-side URL where the file is located.
    """
    if state and isinstance(state._gui, Gui):
        state._gui._download(content, name, on_action)
    else:
        _warn("'download()' must be called in the context of a callback.")