wotpy.utils.utils
Some utility functions for the WoT data type wrappers.
Functions
|
Recursive dict merge. |
|
This functions flattens a dictionary converting nested keys into simple dot-separated strings. |
Returns the main IPv4 address of the current machine in a portable fashion. |
|
|
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. |
|
Takes a tuple of args and dict of kwargs. |
|
Takes a string and transforms it to camelCase. |
|
Recursive function that attempts to convert any given object to a JSON-serializable object. |
|
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. Themerge_dctis merged intodct. :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.