coapthon.layers package

Submodules

coapthon.layers.blocklayer module

class coapthon.layers.blocklayer.BlockLayer[source]

Bases: object

Handle the Blockwise options. Hides all the exchange to both servers and clients.

static error(transaction, code)[source]

Notifies generic error on blockwise exchange.

Parameters:transaction (Transaction) – the transaction that owns the response

:rtype : Transaction :return: the edited transaction

static incomplete(transaction)[source]

Notifies incomplete blockwise exchange.

Parameters:transaction (Transaction) – the transaction that owns the response

:rtype : Transaction :return: the edited transaction

receive_empty(empty, transaction)[source]

Dummy function. Used to do not broke the layered architecture.

Parameters:
  • empty (Message) – the received empty message
  • transaction (Transaction) – the transaction that owns the empty message

:rtype : Transaction :return: the transaction

receive_request(transaction)[source]

Handles the Blocks option in a incoming request.

Parameters:transaction (Transaction) – the transaction that owns the request

:rtype : Transaction :return: the edited transaction

receive_response(transaction)[source]

Handles the Blocks option in a incoming response.

Parameters:transaction (Transaction) – the transaction that owns the response

:rtype : Transaction :return: the edited transaction

send_request(request)[source]

Handles the Blocks option in a outgoing request.

Parameters:request (Request) – the outgoing request
Returns:the edited request
send_response(transaction)[source]

Handles the Blocks option in a outgoing response.

Parameters:transaction (Transaction) – the transaction that owns the response

:rtype : Transaction :return: the edited transaction

coapthon.layers.forwardLayer module

class coapthon.layers.forwardLayer.ForwardLayer(server)[source]

Bases: object

Class used by Proxies to forward messages.

receive_request(transaction)[source]

Setup the transaction for forwarding purposes on Forward Proxies.

Parameters:transaction (Transaction) – the transaction that owns the request

:rtype : Transaction :return: the edited transaction

receive_request_reverse(transaction)[source]

Setup the transaction for forwarding purposes on Reverse Proxies.

Parameters:transaction (Transaction) – the transaction that owns the request

:rtype : Transaction :return: the edited transaction

coapthon.layers.messagelayer module

class coapthon.layers.messagelayer.MessageLayer(starting_mid)[source]

Bases: object

Handles matching between messages (Message ID) and request/response (Token)

fetch_mid()[source]

Gets the next valid MID.

Returns:the mid to use
receive_empty(message)[source]

Pair ACKs with requests.

Parameters:message (Message) – the received message

:rtype : Transaction :return: the transaction to which the message belongs to

receive_request(request)[source]

Handle duplicates and store received messages.

Parameters:request (Request) – the incoming request

:rtype : Transaction :return: the edited transaction

receive_response(response)[source]

Pair responses with requests.

Parameters:response (Response) – the received response

:rtype : Transaction :return: the transaction to which the response belongs to

send_empty(transaction, related, message)[source]

Manage ACK or RST related to a transaction. Sets if the transaction has been acknowledged or rejected.

Parameters:
  • transaction – the transaction
  • related – if the ACK/RST message is related to the request or the response. Must be equal to

transaction.request or to transaction.response or None :type message: Message :param message: the ACK or RST message to send

send_request(request)[source]

Create the transaction and fill it with the outgoing request.

Parameters:request (Request) – the request to send

:rtype : Transaction :return: the created transaction

send_response(transaction)[source]

Set the type, the token and eventually the MID for the outgoing response

Parameters:transaction (Transaction) – the transaction that owns the response

:rtype : Transaction :return: the edited transaction

coapthon.layers.messagelayer.str_append_hash(*args)[source]

Convert each argument to a lower case string, appended, then hash

coapthon.layers.observelayer module

class coapthon.layers.observelayer.ObserveLayer[source]

Bases: object

Manage the observing feature. It store observing relationships.

notify(resource, root=None)[source]

Prepare notification for the resource to all interested observers.

Return type:

list

Parameters:
  • resource – the resource for which send a new notification
  • root – deprecated
Returns:

the list of transactions to be notified

receive_empty(empty, transaction)[source]

Manage the observe feature to remove a client in case of a RST message receveide in reply to a notification.

Parameters:
  • empty (Message) – the received message
  • transaction (Transaction) – the transaction that owns the notification message

:rtype : Transaction :return: the modified transaction

receive_request(transaction)[source]

Manage the observe option in the request end eventually initialize the client for adding to the list of observers or remove from the list.

Parameters:transaction (Transaction) – the transaction that owns the request

:rtype : Transaction :return: the modified transaction

receive_response(transaction)[source]

Sets notification’s parameters.

Parameters:transaction (Transaction) – the transaction

:rtype : Transaction :return: the modified transaction

remove_subscriber(message)[source]

Remove a subscriber based on token.

Parameters:message – the message
send_empty(message)[source]

Eventually remove from the observer list in case of a RST message.

Parameters:message (Message) – the message
Returns:the message unmodified
send_request(request)[source]

Add itself to the observing list

Parameters:request – the request
Returns:the request unmodified
send_response(transaction)[source]

Finalize to add the client to the list of observer.

Parameters:transaction (Transaction) – the transaction that owns the response
Returns:the transaction unmodified

coapthon.layers.requestlayer module

class coapthon.layers.requestlayer.RequestLayer(server)[source]

Bases: object

Class to handle the Request/Response layer

receive_request(transaction)[source]

Handle request and execute the requested method

Parameters:transaction (Transaction) – the transaction that owns the request

:rtype : Transaction :return: the edited transaction with the response to the request

send_request(request)[source]
Dummy function. Used to do not broke the layered architecture.
Parameters:request (Request) – the request
Returns:the request unmodified

coapthon.layers.resourcelayer module

class coapthon.layers.resourcelayer.ResourceLayer(parent)[source]

Bases: object

Handles the Resources.

add_resource(transaction, parent_resource, lp)[source]

Render a POST on a new resource.

Parameters:
  • transaction – the transaction
  • parent_resource – the parent of the resource
  • lp – the location_path attribute of the resource
Returns:

the response

static corelinkformat(resource)[source]

Return a formatted string representation of the corelinkformat in the tree.

Returns:the string
create_resource(path, transaction)[source]

Render a POST request.

Parameters:
  • path – the path of the request
  • transaction – the transaction
Returns:

the response

delete_resource(transaction, path)[source]

Render a DELETE request.

Parameters:
  • transaction – the transaction
  • path – the path
Returns:

the response

discover(transaction)[source]

Render a GET request to the .well-know/core link.

Parameters:transaction – the transaction
Returns:the transaction
edit_resource(transaction, path)[source]

Render a POST on an already created resource.

Parameters:
  • path – the path of the resource
  • transaction – the transaction
Returns:

the transaction

get_resource(transaction)[source]

Render a GET request.

Parameters:transaction – the transaction
Returns:the transaction
update_resource(transaction)[source]

Render a PUT request.

Parameters:transaction – the transaction
Returns:the response

coapthon.layers.cachelayer module

class coapthon.layers.cachelayer.CacheLayer(mode, max_dim=2048)[source]

Bases: object

receive_request(transaction)[source]

checks the cache for a response to the request

Parameters:transaction
Returns:
send_response(transaction)[source]

updates the cache with the response if there was a cache miss

Parameters:transaction
Returns:

Module contents