Skip to content

call ¤

Command to call RPC methods.

Functions:

  • call

    Call subcommand.

  • get_method

    Return the actual aria2 method name from a differently formatted name.

call ¤

call(api: API, method: str, params: str | list[str]) -> int

Call subcommand.

Parameters:

  • api (API) –

    The API instance to use.

  • method (str) –

    Name of the method to call.

  • params (str | list[str]) –

    Parameters to use when calling method.

Returns:

  • int ( int ) –

    Always 0.

Source code in src/aria2p/cli/commands/call.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def call(api: API, method: str, params: str | list[str]) -> int:
    """Call subcommand.

    Parameters:
        api: The API instance to use.
        method: Name of the method to call.
        params: Parameters to use when calling method.

    Returns:
        int: Always 0.
    """
    real_method = get_method(method)

    if real_method is None:
        print(f"aria2p: call: Unknown method {method}.", file=sys.stderr)
        print("  Run 'aria2p call listmethods' to list the available methods.", file=sys.stderr)
        return 1

    call_params: list[Any]
    if isinstance(params, str):
        call_params = json.loads(params)
    elif params is None:
        call_params = []
    else:
        call_params = params

    response = api.client.call(real_method, call_params)
    print(json.dumps(response))

    return 0

get_method ¤

get_method(name: str) -> str | None

Return the actual aria2 method name from a differently formatted name.

Parameters:

  • name (str) –

    A method name.

Returns:

  • str | None

    The real method name.

Source code in src/aria2p/cli/commands/call.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def get_method(name: str) -> str | None:
    """Return the actual aria2 method name from a differently formatted name.

    Parameters:
        name: A method name.

    Returns:
        The real method name.
    """
    methods = {}

    for method in Client.METHODS:
        methods[method.lower()] = method
        methods[method.split(".")[1].lower()] = method

    name = name.lower()
    name = name.replace("-", "")
    name = name.replace("_", "")

    return methods.get(name)