module documentation

This module provides various JSON/Dictionary utility functions.

Function pureResource Return the "pure" structure without the "<domain>:xxx" resource type name, and the oneM2M type identifier.
Function resourceDiff Compare an old and a new resource. A comparison happens for keywords and values. Attributes which names start and end with "__" (ie internal attributes) are ignored.
Function resourceModifiedAttributes Calculate the difference between an original resource and after it has been updated, and then remove the attributes that are part of the update request.
Variable _excludeFromRoot Attributes that are excluded from the root of a resource tree.
Variable _pureResourceRegex Regular expression to test for a pure resource name.
def pureResource(dct: JSON) -> tuple[JSON, str, str]:

Return the "pure" structure without the "<domain>:xxx" resource type name, and the oneM2M type identifier.

Parameters
dct:JSONJSON dictionary with the resource attributes.
Returns
tuple[JSON, str, str]Tupple with the inner JSON, the resource type name, and the found key. If the resource type name is not in the correct format, eg the domain is missing, it is None. The third element always contains the found outer attribute name.
def resourceDiff(old: JSON, new: JSON, modifiers: JSON | None = None) -> JSON:

Compare an old and a new resource. A comparison happens for keywords and values. Attributes which names start and end with "__" (ie internal attributes) are ignored.

Parameters
old:JSONOld resource dictionary to compare.
new:JSONNew resource dictionary to compare.
modifiers:JSON | NoneA dictionary. If this dictionary is given then it contains the changes that let from old to new. This is used to determine if attributes were just updated with the same values.
Returns
JSONReturn a dictionary of identified changes.
def resourceModifiedAttributes(old: JSON, new: JSON, requestPC: JSON, modifiers: JSON | None = None) -> JSON:

Calculate the difference between an original resource and after it has been updated, and then remove the attributes that are part of the update request.

Parameters
old:JSONOld resource dictionary to compare.
new:JSONNew resource dictionary to compare.
requestPC:JSONThe original request's content. This is used to remove the attributes that are part of the update request.
modifiers:JSON | NoneA dictionary. If this dictionary is given then it contains the changes that let from old to new. This is used to determine if attributes were just updated with the same values.
Returns
JSONReturn a dictionary of those attributes that have been changed in a CREATE or UPDATE request.
_excludeFromRoot: list[str] =

Attributes that are excluded from the root of a resource tree.

_pureResourceRegex =

Regular expression to test for a pure resource name.