mads.object

JSON file backed objectect with dotted access.

class Config(name='', *args, **kwargs)[source]

Bases: mads.object.Default

A Config objectect can read previous config from disk.

default = ''
fromdisk(name)[source]
path = 'cfg'
template(name)[source]
class Default(*args, **kwargs)[source]

Bases: mads.object.Object

A object with a “default” set. Standard default return is Object().

Constructor that initializes a variable with Object() as a default.

class Object(*args, **kwargs)[source]

Bases: dict

Dict with dotted access instead of brackets, with json files to sync and load from.

Construct an Object, dotted dictionairy access instead of brackets.

clear()[source]

Clear the ready flag.

grep(val)[source]

Grep for a matching stringified value, return a Object with those matching values.

id()[source]

Return BotType,server string.

isSet()[source]

Check whether ready flag is set.

json(*args, **kwargs)[source]

JSON string dump.

load(path=None, force=False, skip=[], full=True)[source]

Load a json file into this object. use skip as a list of keys to skip.

loads(s)[source]

Update with deconstructed (dict) json string.

merge(obj)[source]
nice(*args, **kwargs)[source]

Return a nicyfied, indent=4, sort_key is True, json dump.

prepare()[source]
Prepare the object and return a string containing the “data” part.
Keyword can be “prefix” when using a subdirectory.
Use “saved” when savestamp need to be different from the “now” timestamp.
printable(keys=[], skip=[], nokeys=False)[source]

Determine from provided keys list and/or from skipping from a skiplist a displayable string from those attributes.

pure(*args, **kwargs)[source]

Return a sliced (no _ keys), indent=4, sort_key is True, json dump.

read(path)[source]

Read a json dump from given path, returning the json string with comments stripped.

ready()[source]

Signal this object as “ready”.

register(key, val, force=False)[source]

Register key, value and throw an exception is value is already set.

save(fn='')[source]

Save this object. stime can be provided to give desired save time in the file name.

save_timed(stime='')[source]
search(name)[source]

Search this objects keys skipping keys that start with “_”.

sync(*args, **kwargs)
wait(sec=None)[source]

Wait for this object’s ready flag.