scdatatools.utils module

class scdatatools.utils.FileHeaderStructure[source]

Bases: StructureWithEnums

class scdatatools.utils.NamedBytesIO(content, name)[source]

Bases: BytesIO

property name
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()

  • Convert `set`s to `list`s

  • 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 a TypeError).

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.crc32(filename_or_path)[source]
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

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.generate_free_key(key, keys)[source]
scdatatools.utils.get_size(obj, seen=None)[source]

Recursively finds size of objects

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)

scdatatools.utils.norm_path(path)[source]
Return type:

str

scdatatools.utils.parse_bool(val)[source]

Parse a boolean value weather in int, str, or bool

Return type:

bool

scdatatools.utils.search_for_data_dir_in_path(path)[source]
scdatatools.utils.version_from_id_file(id_file)[source]
Return type:

(dict, str)

scdatatools.utils.xxhash32(data)[source]
scdatatools.utils.xxhash32_file(file_or_path)[source]