wotpy.utils.utils

Some utility functions for the WoT data type wrappers.

Functions

dict_merge(dct, merge_dct)

Recursive dict merge.

flatten(dictionary[, parent_key, separator])

This functions flattens a dictionary converting nested keys into simple dot-separated strings.

get_main_ipv4_address()

Returns the main IPv4 address of the current machine in a portable fashion.

handle_observer_finalization(observer)

Builds a decorator that yields the wrapped coroutine and calls on_completed or on_error on the observer when the coroutine ends or raises an error.

merge_args_kwargs_dict(args, kwargs)

Takes a tuple of args and dict of kwargs.

to_camel(val)

Takes a string and transforms it to camelCase.

to_json_obj(obj)

Recursive function that attempts to convert any given object to a JSON-serializable object.

to_snake(val)

Takes a string and transforms it to snake_case.

wotpy.utils.utils.dict_merge(dct, merge_dct)

Recursive dict merge. Inspired by :meth:dict.update(), instead of updating only top-level keys, dict_merge recurses down into dicts nested to an arbitrary depth, updating keys. The merge_dct is merged into dct. :param dct: dict onto which the merge is executed :param merge_dct: dct merged into dct :return: None Source: https://gist.github.com/angstwad/bf22d1822c38a92ec0a9

wotpy.utils.utils.flatten(dictionary, parent_key='', separator='.')

This functions flattens a dictionary converting nested keys into simple dot-separated strings. Source: https://stackoverflow.com/questions/6027558/flatten-nested-dictionaries-compressing-keys

wotpy.utils.utils.get_main_ipv4_address()

Returns the main IPv4 address of the current machine in a portable fashion. Attribution to the answer provided by Jamieson Becker on: https://stackoverflow.com/a/28950776

wotpy.utils.utils.handle_observer_finalization(observer)

Builds a decorator that yields the wrapped coroutine and calls on_completed or on_error on the observer when the coroutine ends or raises an error.

wotpy.utils.utils.merge_args_kwargs_dict(args, kwargs)

Takes a tuple of args and dict of kwargs. Returns a dict that is the result of merging the first item of args (if that item is a dict) and the kwargs dict.

wotpy.utils.utils.to_camel(val)

Takes a string and transforms it to camelCase.

wotpy.utils.utils.to_json_obj(obj)

Recursive function that attempts to convert any given object to a JSON-serializable object.

wotpy.utils.utils.to_snake(val)

Takes a string and transforms it to snake_case.