moobius.json_utils#

Module-level functions#

marked_recursive_dataclass#

Recursively converts nested lists, dicts, etc into dataclasses if they have been markd with types._DTYPE and types._DVAL.

Signature:

  • **marked_recursive_dataclass**(data)

Parameters:

  • __data:__ Data.

Returns:

  • The dataclassed data. Used for JSON loading.

Used by json_utils.enhanced_json_load.

Raises:

  • (this function does not raise any notable errors)

marked_recursive_undataclass#

Converts data containing dataclasses back into pure dicts, making them with json_utils._DTYPE and json_utils._DVAL..

Signature:

  • **marked_recursive_undataclass**(data, typemark_dataclasses)

Parameters:

  • __data:__ Dataclassed data.

  • __typemark_dataclasses:__ Whether to mark dataclasses in a special way so they are known as such.

Returns:

  • The non-dataclassed data.

Used by json_utils.enhanced_json_save.

Raises:

  • (this function does not raise any notable errors)

enhanced_json_load#

Loads JSON from the disk,.

Signature:

  • **enhanced_json_load**(filename)

Parameters:

  • __filename:__ Filename or bytes.

Returns:

  • The possibly-nested datastructure which may have Dataclasses.

Raises:

  • (this function does not raise any notable errors)

enhanced_json_save#

Saves the JSON to the disk and/or a string.

Signature:

  • **enhanced_json_save**(filename, data, typemark_dataclasses, indent)

Parameters:

  • __filename:__ The filename or file object to save to. None if not saving to any file.

  • __data:__ What needs to be saved. Can be a nested datastructure even with embedded dataclasses.

  • __typemark_dataclasses=True:__ Save dataclasses as special dicts so that on enhanced_json_load load they are converted back into dataclasses.

  • __indent=2:__ The indent to display the text at.

Returns:

  • The data as a JSON string.

Raises:

  • (this function does not raise any notable errors)

recursive_json_load#

Loads json files into dicts and lists, including dicts/lists of json filenames. Used for the app configuration. Strings anywhere in x that have no newlines and end in .json or .JSON will be treated like filenames. Does not use enhanced_json features..

Signature:

  • **recursive_json_load**(x)

Parameters:

  • __x:__ Generic input x.

Returns:

  • The modified input.

Raises:

  • (this function does not raise any notable errors)

update_jsonfile#

Updates a json file. Uses enhanced_json_load (which makes dataclasses have metadata).

Signature:

  • **update_jsonfile**(fname, key_path, value)

Parameters:

  • __fname:__ The json file.

  • __key_path:__ The path within the datastructure.

  • __value:__ The new value.

Returns:

  • None.

Raises:

  • (this function does not raise any notable errors)

get_config#

Calculates the configuration in various ways. Config files are automatically generated by quickstart.py which is invoked by running the command “moobius”. This may involve JSON file reading.

Signature:

  • **get_config**(config, account_config, service_config, db_config, log_config)

Parameters:

  • __config=None:__ The entire config, a string (JSON filepath) or dict.

  • __account_config=None:__ The account-sepcific config with secrets, a string (JSON filepath) or dict.

  • __service_config=None:__ Service-specific config (the urls, the service id, and the channels).

  • __db_config=None:__ Config specific to the Moobius db engine. A list of attributes. This feature is an independent feature to the Platform.

  • __log_config=None:__ Config specific to logging. This feature is an independent feature to the Platform.

Returns:

  • The config as a dict. Where to save the new service id as [json filename, datastructure_path], if there is a JSON file to save to.

Raises:

  • (this function does not raise any notable errors)

Internals#