Calls module

The calls module provides a decorator that facilitates the handling of JSON-like data structures within Python functions. This module is particularly useful for developers working with data in the form of dictionaries, lists, and tuples, as it simplifies the conversion of these data structures into Object instances, enabling attribute-style access and other JSON-like behaviors. At the heart of this module is the jsified_function decorator, which automatically converts function arguments into Object instances. Additionally, the decorator offers options to process the function’s return value, allowing it to be returned in its original form or as a deeply unjsified structure, depending on the specified flags.

jsify.calls.camelized_function(*args, replace=None)[source]

A decorator to convert the keys of JSON-like dictionaries from camelCase to snake_case before passing them to the function.

Parameters:

replace (dict, optional) – A dictionary to specify replacements for certain keys after conversion to snake_case.

Returns:

A decorator that applies the conversion to the decorated function’s keyword arguments.

Return type:

function

jsify.calls.jsified_function(*args, result_original=False, result_deep_original=False)[source]

A decorator to convert function arguments to Object and process the results accordingly.

This decorator can be applied to a function to ensure that its arguments are automatically converted to Object instances if they are of types dict, list, or tuple. It also processes the function’s result based on the provided flags.

Parameters:
  • *args (tuple) – Positional arguments that may include the function to be decorated.

  • result_original (bool, optional) – If True, the function’s result will be unjsified using unjsify. Default is False.

  • result_deep_original (bool, optional) – If True, the function’s result will be deeply unjsified using deep_unjsify. Default is False.

Returns:

The decorated function with arguments converted to Object and results processed based on the flags.

Return type:

function

jsify.calls.json_function(f)[source]

A decorator that allows a function to accept a JSON dictionary via a special _json keyword argument.

This decorator checks if the _json keyword argument is provided. If it is, the dictionary passed via _json is unpacked and its key-value pairs are added to the function’s keyword arguments before the function is called.

Parameters:

f (function) – The function to be decorated.

Returns:

The decorated function.

Return type:

function