configblock.dictwriter module

Class to produce a dictionary from a hierarchy of config blocks

class configblock.dictwriter.DictWriter(only_active: bool = True, default=<object object>, convert_values: bool = True)

Bases: VisitorBase

Visitor that creates a dictionary representation of the hierarchy

begin_globals() bool

Begin writing the globals

Returns:

Whether the block should be entered

Return type:

bool

begin_subcfg(key: str, subcfg: ConfigBlock) bool

Begin writing a single subconfig

Note that this method should not handle further iteration into the subconfig

Returns:

Whether the subconfig should be entered

Return type:

bool

convert_value(value: Any) Any
convert_value(value: Enum) str

Convert a value for output

New conversion functions can be registered using DictWriter.convert_value.register but note that this will add the converter to all DictWriters. Otherwise a subclass can just override this method as normal.

property current_dict: Dict
end_globals() None

End writing the globals

end_subcfg() None

End writing the currrent subconfig

visit(root: ConfigBlock) Dict

Return a dictionary representation of the provided hierarchy

visit_option(key: str, option: OptionData) None

Visit a single option