class documentation

Base class for all oneM2M resource types,

Method __contains__ Implementation of the membership test operator.
Method __delitem__ Implementation of the self[key| operation for deleting attributes.
Method __eq__ Test for equality of the resource to another resource.
Method __getattr__ Map the normal object attribute access to the internal resource attribute dictionary.
Method __getitem__ Implementation of the self[key| operation for retrieving attributes.
Method __init__ Initialization of a Resource instance.
Method __repr__ Object representation as string.
Method __setitem__ Implementation of the self[key] operation for assigning to attributes.
Method __str__ String representation of the resource's attributes.
Method activate This method is called to activate a resource, usually in a CREATE request.
Method asDict Get the JSON resource representation.
Method attribute Return the value of an attribute.
Method canHaveChild Check whether resource is a valild child resource for this resource.
Method childAdded Called after a child resource was added to the resource.
Method childRemoved Called when a child resource of the resource was removed.
Method childUpdated Called when a child resource was updated.
Method childWillBeAdded Called before a child will be added to a resource.
Method createChildResourceFromDict Create a child resource from a JSON dictionary.
Method dbCreate Add the resource to the database.
Method dbDelete Delete the resource from the database.
Method dbReload Load a new copy of the same resource from the database.
Method dbReloadDict Reload the resource instance from the database.
Method dbUpdate Update the resource in the database.
Method deactivate Deactivate an active resource.
Method decrementSubscriptionCounter Decrement the subscription counter for the resource.
Method delAttribute Delete the attribute 'key' from the resource.
Method getAttributes Get all attributes of the resource.
Method getCurrentOriginator Retrieve the current originator. This could be different from the originator / creator of the resource in case of the custodian attribute is set.
Method getFinalResourceAttribute Determine and return the final value of an attribute during an update.
Method getLocationCoordinates Retrieve a resource's location coordinates (internal attribute).
Method getOriginator Retrieve a resource's originator.
Method getRVI Retrieve a resource's release version indicator.
Method getSrn Retrieve a resource's full structured resource name.
Method getSubscriptionCounter Retrieve the subscription counter for the resource.
Method handleCreateRequest Process a CREATE request that is directed to a virtual resource.
Method handleDeleteRequest Process a DELETE request that is directed to a virtual resource.
Method handleNotification Process a notification request that is directed to a resource.
Method handleRetrieveRequest Process a RETRIEVE request that is directed to a virtual resource.
Method handleUpdateRequest Process a UPDATE request that is directed to a virtual resource.
Method hasAttribute Check whether an attribute exists for the resource.
Method hasAttributeDefined Test whether a resource supports the specified attribute. This method may be overwritten in sub-classes, for example for virtual resources.
Method incrementSubscriptionCounter Increment the subscription counter for the resource.
Method initialize This method is called when a new resource is created and before written to the database.
Method isAnnounced Test whether a the resource's type is an announced type.
Method isCreatedInternally Test whether a resource has been created for another resource.
Method isModifiedAfter Test whether this resource has been modified after another resource.
Method isVirtual Test whether the resource is a virtual resource.
Method retrieveParentResource Retrieve the parent resource of this resouce.
Method retrieveParentResourceRaw Retrieve the raw (!) parent resource of this resouce.
Method selectAttributes Determine the selected attributes for a partial retrieve of a resource.
Method setAttribute Assign a value to a resource attribute.
Method setCreatedInternally Save the resource ID for which this resource was created for.
Method setLocationCoordinates Set a resource's location coordinates (internal attribute).
Method setOriginator Set a resource's originator.
Method setResourceID Set the resource ID for the resource if not already set.
Method setResourceName Set the resource name.
Method setRVI Assign the release version for a resource.
Method setSrn Set a resource's full structured resource name.
Method structuredPath Determine the structured path of a resource.
Method typeAsString Return the resource type as a string. If the resource is a flex container, the specialization is added.
Method update Update, add or remove resource attributes.
Method updated Signal to a resource that is was successfully updated.
Method validate Validate a resource.
Method willBeDeactivated This method is called before a resource will be deactivated.
Method willBeRetrieved This method is called before a resource will be send back in a RETRIEVE response.
Method willBeUpdated This method is called before a resource will be updated and before calling the update() method.
Class Variable __slots__ Slots for the class.
Class Variable dispatcher Injected Dispatcher instance.
Class Variable factory Injected Factory instance.
Class Variable importer Injected Importer instance.
Class Variable notificationManager Injected NotificationManager instance.
Class Variable requestManager Injected RequestManager instance.
Class Variable storage Injected Storage instance.
Class Variable validator Injected Validator instance.
Instance Variable dict Dictionary for public and internal resource attributes.
Method _checkAndFixACPIreferences Check whether a referenced ACP resoure exists, and if yes, change the ID in the list to CSE relative unstructured format.
Method _normalizeURIAttribute Normalize the URLs in the given attribute.
Class Variable _excludeFromUpdate Resource attributes that are excluded when updating the resource
Instance Variable _originalDict Original dictionary as it was created. This is used for validation in activate() later.
def __contains__(self, key: str) -> bool:

Implementation of the membership test operator.

It maps to the hasAttribute() method.

Parameters
key:strResource attribute name to test for.
Returns
boolBoolean, indicating the existens of an attribute
def __delitem__(self, key: str):

Implementation of the self[key| operation for deleting attributes.

It maps to the delAttribute() method, with setNone implicitly set to the default.

Parameters
key:strResource attribute name to delete. This can be a path (see findXPath).
def __eq__(self, other: object) -> bool:

Test for equality of the resource to another resource.

Parameters
other:objectOther object to test for.
Returns
boolIf the other object is a Resource instance and has the same resource ID, then True is returned, of False otherwise.
def __getattr__(self, key: str) -> Any:

Map the normal object attribute access to the internal resource attribute dictionary.

It maps to the attribute() method, but there is no default value.

Parameters
key:strResource attribute name to get.
Returns
AnyThe attribute's value, or None
def __getitem__(self, key: str) -> Any:

Implementation of the self[key| operation for retrieving attributes.

It maps to the attribute() method, but there is no default value.

Parameters
key:strResource attribute name to look for. This can be a path (see findXPath).
Returns
AnyThe attribute's value, or None
def __init__(self, dct: JSON, create: bool | None = False):

Initialization of a Resource instance.

Parameters
dct:JSONMandatory resource attributes.
create:bool | NoneUndocumented
def __repr__(self) -> str:

Object representation as string.

Returns
strString that identifies the resource.
def __setitem__(self, key: str, value: Any):

Implementation of the self[key] operation for assigning to attributes.

It maps to the setAttribute() method, and always overwrites existing values.

Parameters
key:strThe resource attribute's name. This can be a path (see setXPath).
value:AnyValue to assign to the attribute.
def __str__(self) -> str:

String representation of the resource's attributes.

Returns
strString with the resource formatted as a JSON structure
def activate(self, parentResource: Resource, originator: str):

This method is called to activate a resource, usually in a CREATE request.

This is not always the case, e.g. when a resource object is just used temporarly. NO notification on activation/creation happens in this method!

This method is implemented in sub-classes as well.

Parameters
parentResource:ResourceThe resource's parent resource.
originator:strThe request's originator.
Raises
BAD_REQUESTIn case of an invalid attribute.
def asDict(self, embedded: bool | None = True, update: bool | None = False, noACP: bool | None = False, sort: bool = False) -> JSON:

Get the JSON resource representation.

Parameters
embedded:bool | NoneOptional indicator whether the resource should be embedded in another resource structure. In this case it is not embedded in its own "domain:name" structure.
update:bool | NoneOptional indicator whether only the updated attributes shall be included in the result.
noACP:bool | NoneOptional indicator whether the acpi attribute shall be included in the result.
sort:boolUndocumented
Returns
JSONA JSON object with the resource representation.
def attribute(self, key: str, default: Any | None = None) -> Any:

Return the value of an attribute.

Parameters
key:strResource attribute name to look for. This can be a path (see findXPath).
default:Any | NoneA default value to return if the attribute is not set.
Returns
AnyThe attribute's value, the default value, or None
def canHaveChild(self, resource: Resource) -> bool:

Check whether resource is a valild child resource for this resource.

Parameters
resource:ResourceThe resource to test.
Returns
boolBoolean indicating whether resource is a an allowed resorce for this resource.
def childAdded(self, childResource: Resource, originator: str):

Called after a child resource was added to the resource.

This method is implemented in some sub-classes.

Parameters
childResource:ResourceThe child resource that was be added as a child to the resource.
originator:strThe request originator.
def childRemoved(self, childResource: Resource, originator: str):

Called when a child resource of the resource was removed.

This method is implemented in some sub-classes.
Parameters
childResource:ResourceThe removed child resource.
originator:strThe request originator.
def childUpdated(self, childResource: Resource, updatedAttributes: JSON, originator: str):
overridden in acme.resources.TS.TS

Called when a child resource was updated.

This method is implemented in some sub-classes.

Parameters
childResource:ResourceThe child resource that was be updates.
updatedAttributes:JSONJSON dictionary with the updated attributes.
originator:strThe request originator.
def childWillBeAdded(self, childResource: Resource, originator: str):

Called before a child will be added to a resource.

This method is implemented in some sub-classes.

Parameters
childResource:ResourceResource that will be added as a child to the resource.
originator:strThe request originator.
def createChildResourceFromDict(self, dct: JSON, ty: ResourceTypes | None = None, originator: str | None = None, preCreateCB: Callable[[Resource], None] | None = None) -> tuple[Resource, str]:

Create a child resource from a JSON dictionary.

Parameters
dct:JSONThe JSON dictionary with the resource attributes.
ty:ResourceTypes | NoneOptional resource type. If not provided, then the type is determined from the dictionary.
originator:str | NoneOptional request originator.
preCreateCB:Callable[[Resource], None] | NoneOptional callback function that is called with the resource instance before it is stored in the database. This can be used to perform some checks and adjustments before the resource is created.
Returns
tuple[Resource, str]Tuple with the created resource and its resource ID.
def dbCreate(self, overwrite: bool | None = False):

Add the resource to the database.

Parameters
overwrite:bool | NoneIf true an already existing resource with the same resource ID is overwritten.
Returns
Result object indicating success or failure.
def dbDelete(self):

Delete the resource from the database.

Returns
Result object indicating success or failure.
def dbReload(self) -> Resource:

Load a new copy of the same resource from the database.

The current resource is NOT changed.

Note

The version of the resource in the database might be different, e.g. when the resource instance has been modified but not updated in the database.

Returns
ResourceResource instance.
def dbReloadDict(self) -> Resource:

Reload the resource instance from the database.

The current resource's internal attributes are updated with the versions from the database.

Returns
ResourceUpdated Resource instance.
def dbUpdate(self, finalize: bool = False) -> Resource:

Update the resource in the database.

This also raises a CSE internal updateResource event.

Parameters
finalize:boolTreat this database write as a final update to the resource. Only then an event is raised.
Returns
ResourceResult object indicating success or failure.
def deactivate(self, originator: str, parentResource: Resource):

Deactivate an active resource.

This usually happens when creating the resource via a request. A subscription check for deletion is performed.

This method is implemented in sub-classes as well.

Parameters
originator:strThe requests originator that let to the deletion of the resource.
parentResource:ResourceThe resource's parent resource.
def decrementSubscriptionCounter(self):

Decrement the subscription counter for the resource.

This is used to determine whether a resource has active subscriptions.

def delAttribute(self, key: str, setNone: bool | None = True):

Delete the attribute 'key' from the resource.

Parameters
key:strName of the resource attribute name to delete.
setNone:bool | NoneBy default (True) the attribute is not deleted but set to None and later removed when storing the resource in the DB. If setNone' is *False, then the attribute is immediately deleted from the resource instance's internal dictionary.
def getAttributes(self, includingInternal: bool = False) -> dict[str, Any]:

Get all attributes of the resource.

Parameters
includingInternal:boolOptional indicator whether internal attributes shall be included.
Returns
dict[str, Any]Dictionary with a copy of all attributes.
def getCurrentOriginator(self) -> str:

Retrieve the current originator. This could be different from the originator / creator of the resource in case of the custodian attribute is set.

Returns
strThe current originator.
def getFinalResourceAttribute(self, key: str, dct: JSON | None) -> Any:

Determine and return the final value of an attribute during an update.

Parameters
key:strAttribute name.
dct:JSON | NoneThe dictionary with updated attributes.
Returns
AnyThe either updated attribute, or old value if the attribute is not updated. The method returns None if the attribute does not exists.
def getLocationCoordinates(self) -> list:

Retrieve a resource's location coordinates (internal attribute).

Returns
listThe resource's location coordinates. Might be None.
def getOriginator(self) -> str:

Retrieve a resource's originator.

This is the originator that created the resource. It is stored internally within the resource.

Returns
strThe resource's originator.
def getRVI(self) -> str:

Retrieve a resource's release version indicator.

Returns
strThe resource's rvi.
def getSrn(self) -> str:

Retrieve a resource's full structured resource name.

Returns
strThe resource's full structured resource name.
def getSubscriptionCounter(self) -> int:

Retrieve the subscription counter for the resource.

Returns
intThe current subscription counter value.
def handleCreateRequest(self, request: CSERequest, id: str, originator: str) -> Result:

Process a CREATE request that is directed to a virtual resource.

This method must be implemented by virtual resource class.

Parameters
request:CSERequestThe request to process.
id:strThe structured or unstructured resource ID of the target resource.
originator:strThe request's originator.
Returns
ResultResult object indicating success or failure.
def handleDeleteRequest(self, request: CSERequest, id: str, originator: str) -> Result:

Process a DELETE request that is directed to a virtual resource.

This method must be implemented by virtual resource class.

Parameters
request:CSERequestThe request to process.
id:strThe structured or unstructured resource ID of the target resource.
originator:strThe request's originator.
Returns
ResultResult object indicating success or failure.
def handleNotification(self, request: CSERequest, originator: str):

Process a notification request that is directed to a resource.

This method is implemented in some sub-classes. Those implementations override this method to handle the notification request.

Parameters
request:CSERequestThe request to process.
originator:strThe request's originator.
Raises
INTERNAL_SERVER_ERRORIn case the method is not implemented and overridden in a sub-class.
def handleRetrieveRequest(self, request: CSERequest | None = None, id: str | None = None, originator: str | None = None) -> Result:

Process a RETRIEVE request that is directed to a virtual resource.

This method must be implemented by virtual resource class.

Parameters
request:CSERequest | NoneThe request to process.
id:str | NoneThe structured or unstructured resource ID of the target resource.
originator:str | NoneThe request's originator.
Returns
ResultResult object indicating success or failure.
def handleUpdateRequest(self, request: CSERequest, id: str, originator: str) -> Result:

Process a UPDATE request that is directed to a virtual resource.

This method must be implemented by virtual resource class.

Parameters
request:CSERequestThe request to process.
id:strThe structured or unstructured resource ID of the target resource.
originator:strThe request's originator.
Returns
ResultResult object indicating success or failure.
def hasAttribute(self, key: str) -> bool:

Check whether an attribute exists for the resource.

Parameters
key:strResource attribute name to look for.
Returns
boolBoolean, indicating the existens of an attribute
def hasAttributeDefined(self, name: str) -> bool:

Test whether a resource supports the specified attribute. This method may be overwritten in sub-classes, for example for virtual resources.

Parameters
name:strAttribute to test.
Returns
boolBoolean with the result of the test.
def incrementSubscriptionCounter(self):

Increment the subscription counter for the resource.

This is used to determine whether a resource has active subscriptions.

def isAnnounced(self) -> bool:

Test whether a the resource's type is an announced type.

Returns
boolTrue if the resource is an announced resource type.
def isCreatedInternally(self) -> bool:

Test whether a resource has been created for another resource.

Returns
boolTrue if this resource has been created for another resource.
def isModifiedAfter(self, otherResource: Resource) -> bool:

Test whether this resource has been modified after another resource.

Parameters
otherResource:ResourceAnother resource used for the test.
Returns
boolTrue if this resource has been modified after otherResource.
def isVirtual(self) -> bool:

Test whether the resource is a virtual resource.

Returns
boolTrue when the resource is a virtual resource.
def retrieveParentResource(self) -> Resource:

Retrieve the parent resource of this resouce.

Returns
ResourceThe parent Resource of the resource.
def retrieveParentResourceRaw(self) -> JSON:

Retrieve the raw (!) parent resource of this resouce.

Returns
JSONDocument of the parent resource
def selectAttributes(self, request: CSERequest, attributeList: list[str] | None = None):

Determine the selected attributes for a partial retrieve of a resource.

Parameters
request:CSERequestUndocumented
attributeList:list[str] | NoneThe list of attributes to filter.
Raises
BAD_REQUESTIn case an attribute is not defined for the resource.
def setAttribute(self, key: str, value: Any, overwrite: bool | None = True):

Assign a value to a resource attribute.

If the attribute doesn't exist then it is created.

Parameters
key:strThe resource attribute's name. This can be a path (see setXPath).
value:AnyValue to assign to the attribute.
overwrite:bool | NoneOverwrite the value if already set.
def setCreatedInternally(self, ri: str):

Save the resource ID for which this resource was created for.

This has some impacts on internal handling and checks.

Parameters
ri:strResource ID of the resource for which this resource has been created for.
def setLocationCoordinates(self, crd: JSON):

Set a resource's location coordinates (internal attribute).

Parameters
crd:JSONThe location coordinates to assign to a resource.
def setOriginator(self, originator: str, overwrite: bool | None = True):

Set a resource's originator.

This is the originator that created the resource. It is stored internally within the resource.

Parameters
originator:strThe originator to assign to a resource.
overwrite:bool | NoneUndocumented
def setResourceID(self):

Set the resource ID for the resource if not already set.

def setResourceName(self, rn: str):

Set the resource name.

Also set/update the internal structured resource name.

Parameters
rn:strThe new resource name for the resource.
def setRVI(self, rvi: str):

Assign the release version for a resource.

This is usually assigned from the rvi indicator in the resource's CREATE request.

Parameters
rvi:strOriginal CREATE request's rvi.
def setSrn(self, srn: str):

Set a resource's full structured resource name.

Parameters
srn:strThe full structured resource name to assign to a resource.
def structuredPath(self) -> str | None:

Determine the structured path of a resource.

Returns
str | NoneStructured path of the resource or None
def typeAsString(self) -> str:

Return the resource type as a string. If the resource is a flex container, the specialization is added.

Returns
strThe resource type as a string.
def update(self, dct: JSON | None = None, originator: str | None = None, doValidateAttributes: bool | None = True):

Update, add or remove resource attributes.

A subscription check for update is performed.

This method is implemented in sub-classes as well.

Note

This method updates the resource in the database. It should be called only after all other checks where performed.

Parameters
dct:JSON | NoneAn optional JSON dictionary with the attributes to be updated.
originator:str | NoneThe optional requests originator that let to the update of the resource.
doValidateAttributes:bool | NoneIf True optionally call the resource's validate() method.
Raises
CONTENTS_UNACCEPTABLEIn case of a resource mismatch.
BAD_REQUESTIn case of an invalid attribute.
INTERNAL_SERVER_ERRORIn case the parent resource coudln't be retrieved.
def updated(self, dct: JSON | None = None, originator: str | None = None):

Signal to a resource that is was successfully updated.

This handler can be used to perform additional actions after the resource was updated, stored etc.

This method is implemented in some sub-classes.

Parameters
dct:JSON | NoneOptional JSON dictionary with the updated attributes.
originator:str | NoneThe optional request originator.
def validate(self, originator: str | None = None, dct: JSON | None = None, parentResource: Resource | None = None):

Validate a resource.

Usually called within activate() or update() methods.

This method is implemented in some sub-classes.

Raises
BAD_REQUEST: In case of a validation error.
Parameters
originator:str | NoneOptional request originator
dct:JSON | NoneUpdated attributes to validate
parentResource:Resource | NoneThe parent resource
def willBeDeactivated(self, originator: str, parentResource: Resource, parentDelete: bool = False):

This method is called before a resource will be deactivated.

This method is implemented in some sub-classes, which may throw an execption if the resource cannot be deactivated. If it is implemented it should call the super class' willBeDeactivated() method to check for child resources.

Parameters
originator:strThe request originator.
parentResource:ResourceThe resource's parent resource.
parentDelete:boolUndocumented
def willBeRetrieved(self, originator: str | None, request: CSERequest | None = None, subCheck: bool | None = True):

This method is called before a resource will be send back in a RETRIEVE response.

This method is implemented in some sub-classes.

Parameters
originator:str | NoneThe request originator.
request:CSERequest | NoneThe RETRIEVE request.
subCheck:bool | NoneOptional indicator that a blocking Retrieve shall be performed, if configured.
def willBeUpdated(self, dct: JSON | None = None, originator: str | None = None, subCheck: bool | None = True):

This method is called before a resource will be updated and before calling the update() method.

This method is implemented in some sub-classes.

Parameters
dct:JSON | NoneJSON dictionary with the attributes that will be updated.
originator:str | NoneThe request originator.
subCheck:bool | NoneOptional indicator that a blocking Update shall be performed, if configured.
__slots__: tuple[str, ...] =

Slots for the class.

factory: Factory =

Injected Factory instance.

importer: Importer =

Injected Importer instance.

notificationManager: NotificationManager =

Injected NotificationManager instance.

dict =

Dictionary for public and internal resource attributes.

def _checkAndFixACPIreferences(self, acpi: list[str]) -> list[str]:

Check whether a referenced ACP resoure exists, and if yes, change the ID in the list to CSE relative unstructured format.

Parameters
acpi:list[str]List if resource IDs to ACP resources.
Returns
list[str]If fully successful (ie. all ACP resources exist), then a new list with all IDs converted is returned.
def _normalizeURIAttribute(self, attributeName: str):

Normalize the URLs in the given attribute.

Various changes are made to the URI in case they are not fully compliant. This could be, for example, poa, nu and other attributes that usually hold a URI.

If the target attribute is a list of URI then all the URIs in the list are normalized.

Parameters
attributeName:strName of the attribute to normalize.
_excludeFromUpdate: list[str] =

Resource attributes that are excluded when updating the resource

_originalDict =

Original dictionary as it was created. This is used for validation in activate() later.