This module contains various utilty functions that are used to work with requests and responses.
| Function | content |
Convert a content to a string. If the content is a string, it is returned as is. If the content is a byte array, it is decoded to a string. If the content is neither a string nor a byte array, it is converted to a hex string. |
| Function | create |
Create a positive Result object with a request. |
| Function | create |
Create a dictionary with a couple of pre-initialized fields. No validation is done. |
| Function | create |
Create a Result object from a URI. The URI is unquoted, parsed and the request is created. |
| Function | curl |
Create a cURL command from a request. |
| Function | deserialize |
Deserialize a data structure. Supported media serialization types are JSON and cbor. |
| Function | deserialize |
Deserialize data into a dictionary, depending on the serialization type. |
| Function | determine |
Determine the type of serialization for a notification from either the url's ct query parameter, or the given list of csz (contentSerializations, attribute of a target AE/CSE), or the CSE's default serialization. |
| Function | fill |
Fill a request with arguments from a MultiDict. The MultiDict contains the arguments from a request. |
| Function | filter |
Filter a dictionary by a list of attributes to include. |
| Function | from |
Make the path a valid oneM2M ID (unescape /~/ and /_/) and return it. This is valid of CoAP URL paths as well. |
| Function | remove |
Remove Null/None-values from a dictionary, but ignore the ones specified in allowedNull. |
| Function | serialize |
Serialize a dictionary, depending on the serialization type. |
| Function | to |
Make the path a valid CoAP URL path (escape / and //) and return it. |
| Function | to |
Make the url a valid http URL (escape // and ///) and return it. |
Convert a content to a string. If the content is a string, it is returned as is. If the content is a byte array, it is decoded to a string. If the content is neither a string nor a byte array, it is converted to a hex string.
| Parameters | |
content:bytes | str | Any | The content to convert. |
ct:ContentSerializationType | The content serialization type. |
| Returns | |
str | The content as a string. |
Create a dictionary with a couple of pre-initialized fields. No validation is done.
| Parameters | |
**kwargs:Any | individual attributes to set in the request. |
| Returns | |
JSON | JSON dictionary with the request. |
Create a Result object from a URI. The URI is unquoted, parsed and the request is created.
| Parameters | |
request:CSERequest | The request to create. |
url:str | The URL to parse. |
| Returns | |
tuple[ | A tuple with the Result object, the URL and the parsed URL. |
Create a cURL command from a request.
| Parameters | |
request:JSON | The request to create the cURL command from. |
| Returns | |
str | A cURL command. |
Deserialize a data structure. Supported media serialization types are JSON and cbor.
| Parameters | |
data:bytes | The data to deserialize. |
contentContentSerializationType | The content type of the data. |
| Returns | |
JSON | The deserialized data structure. |
| Raises | |
*UNSUPPORTED_MEDIA_TYPE* if the content type is not supported. | |
*BAD_REQUEST* if the data is malformed. | |
Deserialize data into a dictionary, depending on the serialization type.
| Parameters | |
data:bytes | The data to deserialize. |
ct:ContentSerializationType | The data content serialization format. |
| Returns | |
JSON | None | If the data is not None, but has a length of 0 then an empty dictionary is returned. If an unknown content serialization is specified then None is returned. Otherwise, a JSON object is returned. |
str, csz: list[ str], defaultSerialization: ContentSerializationType) -> ContentSerializationType | None:
¶
Determine the type of serialization for a notification from either the url's ct query parameter, or the given list of csz (contentSerializations, attribute of a target AE/CSE), or the CSE's default serialization.
As a side effect this function also validates the allowed URL scheme.
| Parameters | |
url:str | The URL to parse. |
csz:list[ | The fallback content serialization. |
defaultContentSerializationType | The CSE's defaults serialization. |
| Returns | |
ContentSerializationType | None | The determined content serialization, or None if none could be determined. |
MultiDict, dct: JSON, cseRequest: CSERequest, sep: str | None = None) -> CSERequest:
¶
Fill a request with arguments from a MultiDict. The MultiDict contains the arguments from a request.
| Parameters | |
arguments:MultiDict | The MultiDict with the arguments. |
dct:JSON | The dictionary to fill. |
cseCSERequest | The CSERequest object to fill. |
sep:str | None | The separator for the attribute list. |
| Returns | |
CSERequest | The filled CSERequest object. |
Make the path a valid oneM2M ID (unescape /~/ and /_/) and return it. This is valid of CoAP URL paths as well.
| Parameters | |
path:str | The path to convert. |
| Returns | |
str | A valid ID with unescaped special characters. |
Serialize a dictionary, depending on the serialization type.
| Parameters | |
data:JSON | The data to serialize. |
ct:ContentSerializationType | The data content serialization format. |
| Returns | |
str | bytes | JSON | None | A data str or byte object with the serialized data, or None. |
Make the path a valid CoAP URL path (escape / and //) and return it.
| Parameters | |
path:str | The path to convert. |
| Returns | |
str | A valid CoAP URL path with escaped special characters for oneM2M IDs |