Welcome to unv_utils’s documentation!

unv.utils.collections.update_dict_recur(original: dict, from_dict: dict, copy: bool = False) → dict[source]

Update dict recursively.

>>> original = {0: 'zero', 1: {1: 'one'}, 2: {2: {3: 3}}, 6: 'item'}
>>> update_with = {0: 1, 1: {1: 'hello'}, 2: {2: {4: 4}}, 5: 1}
>>> result = update_dict_recur(original, update_with)
>>> result is original  # original dict not copied
True
>>> result[0]  # was 'one'
1
>>> result[1]  # updated inside, was 'one'
{1: 'hello'}
>>> result[2][2]  # added {4: 4} from `update_with`
{3: 3, 4: 4}
>>> result[5]  # added new item to dict
1
>>> result[6]  # same
'item'
>>> original = {1: 'one', 2: {2: 2}}
>>> update_with = {1: 1, 2: {2: 'two'}}
>>> result = update_dict_recur(original, update_with, copy=True)
>>> original is not result
True
>>> result[2][2]
'two'
unv.utils.files.calc_crc32_for_file(path: pathlib.Path) → int[source]

Read file by path and return crc32 sum integer.

>>> import tempfile
>>> import pathlib
>>> fp = tempfile.NamedTemporaryFile()
>>> fp.write(b'Some data')
9
>>> fp.flush()
>>> calc_crc32_for_file(pathlib.Path(fp.name))
1530096573

Indices and tables