Access python dicts using path strings (mainly just doing this to l2submodule)
Ir para arquivo
2022-10-11 16:01:08 -05:00
src defaults should clobber 2022-10-11 16:01:08 -05:00
.gitignore itbegins.xcf 2022-10-07 17:39:51 -05:00
LICENSE itbegins.xcf 2022-10-07 17:39:51 -05:00
pyproject.toml itbegins.xcf 2022-10-07 17:39:51 -05:00
README.md itbegins.xcf 2022-10-07 17:39:51 -05:00

A really simple library for accessing dictionary items using paths. Meant to make working with configuration files easier.

quick-n-dirty documentalation

The class you want is confthing.Config(data, delimiter = "/", defaults = {}, requirements = [], **misc_options).

  • data is the dict you want to wrap the class around.
  • delimiter is whatever you want to use as a path delimiter.
  • defaults is a dict whose keys are paths and values are the default values for each path.
  • requirements is a list of paths that must be defined, otherwise MissingRequirementError is raised.
  • Miscellaneous options are as follows:
    • strict_subscript: when True, enables strict mode when getting items via subscript. Default is False.
    • clobber_subscript: when True, enables clobber mode when setting items via subscript. Default is False.

Methods

get(path, fallback = None, strict = False)

Tries to return the value at the specified path, otherwise returns the fallback value (or raises PathNotFoundError if strict is True).

set(path, value, clobber = False)

Tries to set the value at the specified path. If it encounters an item that isn't a dict, it'll raise NotDictError if clobber is False, or it'll replace that with an empty dict.

Subscripting

Config objects are subscriptable, calling get and set as appropriate. The two subscript options control what strict and clobber are set to when subscripting.