coapthon package

Submodules

coapthon.defines module

coapthon.defines.BLOCKWISE_SIZE = 1024

MongoDB parameters

class coapthon.defines.CodeItem

Bases: tuple

CodeItem(number, name)

name

Alias for field number 1

number

Alias for field number 0

class coapthon.defines.Codes[source]

Bases: object

CoAP codes. Every code is represented as (NUMBER, NAME)

coapthon.defines.MONGO_CONFIG_FILE = '/usr/local/etc/mongod.conf'

Message Format

class coapthon.defines.OptionItem

Bases: tuple

OptionItem(number, name, value_type, repeatable, default)

default

Alias for field number 4

name

Alias for field number 1

number

Alias for field number 0

repeatable

Alias for field number 3

value_type

Alias for field number 2

class coapthon.defines.OptionRegistry[source]

Bases: object

All CoAP options. Every option is represented as: (NUMBER, NAME, VALUE_TYPE, REPEATABLE, DEFAULT)

static get_option_flags(option_num)[source]

Get Critical, UnSafe, NoCacheKey flags from the option number as per RFC 7252, section 5.4.6

Parameters:option_num – option number
Returns:option flags
Return type:3-tuple (critical, unsafe, no-cache)

coapthon.serializer module

class coapthon.serializer.Serializer[source]

Bases: object

Serializer class to serialize and deserialize CoAP message to/from udp streams.

static as_sorted_list(options)[source]

Returns all options in a list sorted according to their option numbers.

Returns:the sorted list
static convert_to_raw(number, value, length)[source]

Get the value of an option as a ByteArray.

Parameters:
  • number – the option number
  • value – the option value
  • length – the option length
Returns:

the value of an option as a BitArray

static deserialize(datagram, source)[source]

De-serialize a stream of byte to a message.

Parameters:
  • datagram – the incoming udp message
  • source – the source address and port (ip, port)
Returns:

the message

Return type:

Message

static get_option_nibble(optionvalue)[source]

Returns the 4-bit option header value.

Parameters:optionvalue – the option value (delta or length) to be encoded.
Returns:the 4-bit option header value.
static int_to_words(int_val, num_words=4, word_size=32)[source]

Convert a int value to bytes.

Parameters:
  • int_val – an arbitrary length Python integer to be split up. Network byte order is assumed. Raises an IndexError if width of integer (in bits) exceeds word_size * num_words.
  • num_words – number of words expected in return value tuple.
  • word_size – size/width of individual words (in bits).
Returns:

a list of fixed width words based on provided parameters.

static is_request(code)[source]

Checks if is request.

Returns:True, if is request
static is_response(code)[source]

Checks if is response.

Returns:True, if is response
static read_option_value_from_nibble(nibble, pos, values)[source]

Calculates the value used in the extended option fields.

Parameters:nibble – the 4-bit option header value.
Returns:the value calculated from the nibble and the extended option value.
static read_option_value_len_from_byte(byte, pos, values)[source]

Calculates the value and length used in the extended option fields.

Parameters:byte – 1-byte option header value.
Returns:the value and length, calculated from the header including the extended fields.
static serialize(message)[source]

Serialize a message to a udp packet

Parameters:message (Message) – the message to be serialized
Return type:stream of byte
Returns:the message serialized

coapthon.transaction module

class coapthon.transaction.Transaction(request=None, response=None, resource=None, timestamp=None)[source]

Bases: object

Transaction object to bind together a request, a response and a resource.

block_transfer[source]

Return the block_transfer attribute.

Returns:True, if transaction is blockwise
completed[source]

Return the completed attribute.

Returns:True, if transaction is completed
request[source]

Return the request.

Returns:the request
Return type:Request
resource[source]

Return the resource.

Returns:the resource
Return type:Resource
response[source]

Return the response.

Returns:the response
Return type:Response
timestamp[source]

Return the timestamp.

Returns:the timestamp

coapthon.utils module

coapthon.utils.byte_len(int_type)[source]

Get the number of byte needed to encode the int passed.

Parameters:int_type – the int to be converted
Returns:the number of bits needed to encode the int passed.
coapthon.utils.check_code(code)[source]

checks if the response code is one of the valid ones defined in the rfc

Parameters:code
Returns:
coapthon.utils.check_nocachekey(option)[source]

checks if an option is a NoCacheKey option or Etag

Parameters:option
Returns:
coapthon.utils.is_uri_option(number)[source]

checks if the option is part of uri-path, uri-host, uri-port, uri-query

Parameters:number
Returns:
coapthon.utils.parse_blockwise(value)[source]

Parse Blockwise option.

Parameters:value – option value
Returns:num, m, size

Module contents