coapthon.resources package

Submodules

coapthon.resources.resource module

class coapthon.resources.resource.Resource(name, coap_server=None, visible=True, observable=True, allow_children=True)[source]

Bases: object

The Resource class. Represents the base class for all resources.

actual_content_type[source]

Get the actual required Content-Type.

Returns:the actual required Content-Type.
add_content_type(ct)[source]

Add a CoRE Link Format ct attribute to the resource.

Parameters:ct – the CoRE Link Format ct attribute
allow_children[source]

Get if the resource allow children.

Returns:True, if allow children
attributes[source]

Get the CoRE Link Format attribute of the resource.

Returns:the attribute of the resource
changed[source]

Check if the resource has been changed. For observing purpose.

Return type:bool
Returns:True, if changed
content_type[source]

Get the CoRE Link Format ct attribute of the resource.

Returns:the CoRE Link Format ct attribute
deleted[source]

Check if the resource has been deleted. For observing purpose.

Return type:bool
Returns:True, if deleted
edit_resource(request)[source]

Helper function to edit a resource

Parameters:request – the request that edit the resource
etag[source]

Get the last valid ETag of the resource.

Returns:the last ETag value or None if the resource doesn’t have any ETag
init_resource(request, res)[source]

Helper function to initialize a new resource.

Parameters:
  • request – the request that generate the new resource
  • res – the resource
Returns:

the edited resource

interface_type[source]

Get the CoRE Link Format if attribute of the resource.

Returns:the CoRE Link Format if attribute
location_query[source]

Get the Location-Query of a resource.

Returns:the Location-Query
max_age[source]

Get the Max-Age.

Returns:the Max-Age
maximum_size_estimated[source]

Get the CoRE Link Format sz attribute of the resource.

Returns:the CoRE Link Format sz attribute
observable[source]

Get if the resource is observable.

Returns:True, if observable
observe_count[source]

Get the Observe counter.

Returns:the Observe counter value
observing[source]

Get the CoRE Link Format obs attribute of the resource.

Returns:the CoRE Link Format obs attribute
payload[source]

Get the payload of the resource according to the content type specified by required_content_type or “text/plain” by default.

Returns:the payload.
render_DELETE(request)[source]

Method to be redefined to render a DELETE request on the resource.

Parameters:request – the request
Returns:a boolean
render_DELETE_advanced(request, response)[source]

Method to be redefined to render a DELETE request on the resource.

Parameters:
  • response – the partially filled response
  • request – the request
Returns:

a tuple with a boolean and the response

render_GET(request)[source]

Method to be redefined to render a GET request on the resource.

Parameters:request – the request
Returns:the resource
render_GET_advanced(request, response)[source]

Method to be redefined to render a GET request on the resource.

Parameters:
  • response – the partially filled response
  • request – the request
Returns:

a tuple with (the resource, the response)

render_POST(request)[source]

Method to be redefined to render a POST request on the resource.

Parameters:request – the request
Returns:the resource
render_POST_advanced(request, response)[source]

Method to be redefined to render a POST request on the resource.

Parameters:
  • response – the partially filled response
  • request – the request
Returns:

a tuple with (the resource, the response)

render_PUT(request)[source]

Method to be redefined to render a PUT request on the resource.

Parameters:request – the request
Returns:the resource
render_PUT_advanced(request, response)[source]

Method to be redefined to render a PUT request on the resource.

Parameters:
  • response – the partially filled response
  • request – the request
Returns:

a tuple with (the resource, the response)

resource_type[source]

Get the CoRE Link Format rt attribute of the resource.

Returns:the CoRE Link Format rt attribute
visible[source]

Get if the resource is visible.

Returns:True, if visible

Module contents