hio.help.mining

hio.help.mining module

Support for Mine dict subclass for shared in memory database

Module Contents

class hio.help.mining.Mine(*pa, **kwa)

Bases: dict

Mine subclass of dict with custom methods dunder methods and get that will only allow actual keys as str. Iterables passed in as key are converted to a “_’ joined str. Uses “_” so can use dict constuctor if need be with str path. Assumes items in Iterable do not contain ‘_’. Supports attribute syntax to access items, e.g. mine.a = 5 and mine.a_b = 4.

Special static methods: tokeys(k) returns split of k at separator ‘_’ as tuple.

get(k, default=None)

Return the value for key if key is in the dictionary, else default.

update(*pa, **kwa)

Convert keys that are tuples when positional argument is Iterable or Mapping to ‘.’ joined strings

dict __init__ signature options are:

dict(**kwa)
dict(mapping, **kwa)
dict(iterable, **kwa)

dict.update has same call signature:

d.update({"a": 5, "b": 2}, c=3, d=4)
static tokey(keys)

Joins tuple of strings keys to ‘_’ joined string key. If already str then returns unchanged.

Parameters:

keys (Iterable[str] | str) – non-string Iteralble of path key components to be ‘_’ joined into key. If keys is already str then returns unchanged

Returns:

‘.’ joined string

Return type:

key (str)

static tokeys(key)

Converts ‘_’ joined string key to tuple of keys by splitting on ‘_’

Parameters:

key (str) – ‘_’ joined string to be split

Returns:

split of key on ‘_’ into path key components

Return type:

keys (tuple[str])