configblock.visitorbase module

Base class for visitors to the configblock hierarchy

class configblock.visitorbase.Section(value)

Bases: Enum

Enum describing the different types of data in each ConfigBlock

Options = 1

The options directly defined on this block

SubconfigTypes = 3

The factories on this block, including both the default and any named factories

Subconfigs = 2

All subconfigs directly defined on this block, including instantiated extra subconfigs

class configblock.visitorbase.VisitorBase(only_active: bool, section_order: ~typing.Tuple[~configblock.visitorbase.Section, ...] = (<Section.Options: 1>, <Section.Subconfigs: 2>, <Section.SubconfigTypes: 3>))

Bases: object

Base class for visiting a configblock hierarchy

Provides a mechanism for iterating through a block in a well defined order.

Subclasses should provide overrides for all relevant methods. The return values of the begin_X methods can be used to control the iteration through the hierarchy.

begin() bool

Begin the output for the provided hierarchy

Returns:

Whether the hierarchy should be entered

Return type:

bool

begin_block() bool

Begin writing the specified block

Returns:

Whether the block should be entered

Return type:

bool

begin_globals() bool

Begin writing the globals

Returns:

Whether the block should be entered

Return type:

bool

begin_options() bool

Begin writing the options

Returns:

Whether the options should be iterated over

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

begin_subcfg_types() bool

Begin writing the subconfig types section

Returns:

Whether to iterate over the subconfiguration factories

Return type:

bool

begin_subcfgs() bool

Begin writing the subconfigs section

Returns:

Whether the subconfigs section should be iterated over

Return type:

bool

property current_block: ConfigBlock

The current block in the hierarchy

property depth: int

The depth in the hierarchy being visited currently

end() None

End the output

end_block() None

End writing the current block

end_globals() None

End writing the globals

end_options() None

End writing the options on the current block

end_subcfg() None

End writing the currrent subconfig

end_subcfg_types() None

End the subconfig types section

end_subcfgs() None

End writing the subconfigs section

property only_active: bool

Whether this visitor only visits active blocks

property root: ConfigBlock | None

The root of the hierarchy being visited currently

property section_order: Tuple[Section, ...]

The section order for this visitor

stack_block(block: ConfigBlock)

Add a block to the stack of currently visited blocks

stack_factory(factory: Callable[[], ConfigBlock] | None)

Called when entering a factory to avoid infinite recursion

visit(root: ConfigBlock) Any

Visit the root block

visit_block(block: ConfigBlock) None

Visit a block

visit_default_subcfg_type(factory: Callable[[], ConfigBlock] | None, already_visited: bool) None

Visit the default subconfig factory

Parameters:
  • factory (Optional[ConfigBlockFactory]) – The default subconfig factory for the current block

  • already_visited (bool) – Whether or not the information has been output in the current stack. This is to prevent infinite recursion where a block has itself as the default type

visit_globals() None

Visit the top global block

visit_option(key: str, option: OptionData) None

Visit a single option

visit_options() None

Visit the options declared on this block

visit_subcfg_type(key: str, factory: Callable[[], ConfigBlock], already_visited: bool) None

Visit a single subconfig type

Parameters:
  • factory (Optional[ConfigBlockFactory]) – The factory to visit

  • already_visited (bool) – Whether or not the information has been output in the current stack. This is to prevent infinite recursion where a block has itself as the default type

visit_subcfg_types() None

Visit the subconfiguration factories declared on this block

visit_subcfgs() None

Visit the subconfigurations declared on this block