Bases: object
A CoAP link.
A link represents a resource supported by a CoAP end-point. Links comprise the URI-reference at which the resource may be accessed, along with a set of parameters that can be used to provide additional information about the resource and how to use it.
Link resources are described in a text format registered as application/link-format and can be obtained from a CoAP end-point by getting the /.well-known/r resource from that endpoint.
Create a LinkValue instance from a URI and a set of parameters.
Arbitrary keywords are accepted and stored as link parameters.
Extract and create a LinkValue instance from a resource description.
The ABNF grammar for link-value in CoAP is evaluated against text to extract the URI and associated link parameters of a link value. An instance of this class is created to hold those parameters, and returned as link. The octets consumed in defining the link are stripped, and the remainder returned in remainder.
Parameter: | text – A sequence of octets comprising a resource description, optionally followed by other text. |
---|---|
Returns: | (link, remainder) |
Bases: coapy.link.ParameterValueSupport
Value support where the value is a string enclosed in angle brackets, e.g. </path>.
Note: | A close-angle-bracket (>) character cannot appear within the string body, not even if escaped. |
---|
Bases: coapy.link.ParameterValueSupport
Value support where the value is a sequence of ASCII integers separated by commas, e.g. 0,41.
The represented value is expressed as a Python list of int instances.
Bases: coapy.link.ParameterValueSupport
Value support where the value is a string enclosed in ASCII double quotes, e.g. "some text".
Note: | Quote characters cannot appear within the string body, not even if escaped. |
---|
Bases: coapy.link.ParameterValueSupport
Value support where the value is a sequence of one or more ASCII digits, e.g. 42.
Bases: coapy.link.ParameterValueSupport
Value support where the value matches the ptoken rule in the CoAP link-value ABNF.
Bases: coapy.link.ParameterValueSupport
Value support where the value is a string enclosed in ASCII single quotes, e.g. 'some text'.
Note: | Quote characters cannot appear within the string body, not even if escaped. |
---|
Bases: coapy.link.ParameterValueSupport
Value support for unrecognized parameters.
This matches either PVS_ptoken or PVS_dquotedString, depending on the content of the value.
Override base class to support either dquotedString or ptoken.
If the text begins with double-quotes, this processes as PVS_dquotedString.decode(). Otherwise, it processes as PVS_ptoken.decode().
Override base class to support either dquotedString or ptoken.
If the value is consistent with the requirements of PVS_ptoken, this processes as PVS_ptoken.encode(). Otherwise, it processes as PVS_dquotedString.encode().
Bases: object
Base class for extracting and formatting link-format attributes.
CoAP link parameters are key/value pairs, separated by an ASCII equals sign. The value pattern can be specific to the key; for example, the d= attribute value is a URI-reference.
There is a subclass of this class for each type of link-param value. Normally, those subclasses need only override the _re and _format attributes; in other cases _processDecoded() or other methods must also be overridden.
Extract a parameter value from the text.
The default implementation matches the _re regular expression against the start of text. If the pattern match fails, value is None. Otherwise, the extracted pattern is run through _processDecoded() and returned as value. In either case, any matched prefix is stripped from the returned text value.
Parameter: | text – A string comprising the value for a parameter, followed optionally by additional parameters or link descriptions. |
---|---|
Returns: | A tuple (value, text) |
Convert a parameter value into the text representation used in a link description.
Note: | The implementing class is not obliged to validate that the result of encoding value is a string that can be decoded to the same value. For example, value is not checked for illegal characters. |
---|---|
Parameter: | value – value to be represented |
Return type: | str |
Base class for extracting and formatting link-format attributes.
CoAP link parameters are key/value pairs, separated by an ASCII equals sign. The value pattern can be specific to the key; for example, the d= attribute value is a URI-reference.
There is a subclass of this class for each type of link-param value. Normally, those subclasses need only override the _re and _format attributes; in other cases _processDecoded() or other methods must also be overridden.
A compiled regular expression used to extract the parameter value.
The expression should produce a single group the value of which is the value of the parameter (e.g., excluding surrounding quotation characters). By default, this expression is used by the decode() method.
A format string used to express the parameter value in a link-value description.
This should produce a sequence that can be matched by decode().
Perform any post-processing on an value string.
The default implementation simply returns text unchanged. Override this in subclasses that need to do something more complex, such as convert a comma-separated sequence of ASCII-encoded integers into a list of Python int instances.
Parameter: | text – the text to be processed |
---|---|
Return type: | specific to the subclass |