scdatatools.utils module¶
- class scdatatools.utils.FileHeaderStructure[source]¶
Bases:
StructureWithEnums
- class scdatatools.utils.SCJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶
Bases:
JSONEncoder
A
JSONEncoder
which will handle _any_ element by eventually failing back to str. It will also:Respect classes that have a to_dict, to_json, dict or json method.
Handle Quaternions with
quaternion_to_dict()
Path’s use as_posix
- default(obj)[source]¶
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- class scdatatools.utils.StructureWithEnums[source]¶
Bases:
object
Add missing enum feature to ctypes Structures.
- scdatatools.utils.dict_contains_value(obj, values_to_check, ignore_case=False)[source]¶
returns the unique values of every key key within nested dict objects
- scdatatools.utils.dict_search(obj, keys, ignore_case=False)[source]¶
returns the unique values of every key key within nested dict objects
- scdatatools.utils.dict_to_etree(dict_obj)[source]¶
Convert the given dict d to an ElementTree following the following XML to JSON specification: https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html
- Return type:
<module ‘xml.etree.ElementTree’ from ‘/home/docs/.pyenv/versions/3.8.6/lib/python3.8/xml/etree/ElementTree.py’>
- scdatatools.utils.etree_to_dict(t)[source]¶
Convert the given ElementTree t to an dict following the following XML to JSON specification: https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html
- Return type:
dict
- scdatatools.utils.log_time(msg='', handler=<built-in function print>, threshold=0, finish_only=False)[source]¶
Context manager that will log the time it took to run the inner context via the callable handler (Defaults to print)