cement.ext.ext_yaml

Cement yaml extension module.

class cement.ext.ext_yaml.YamlConfigHandler(*args, **kw)[source]

Bases: ConfigParserConfigHandler

This class implements the Config Handler interface, and provides the same functionality of ConfigParserConfigHandler but with Yaml configuration files. See pyYaml for more information on pyYaml.

Note This extension has an external dependency on pyYaml. You must include pyYaml in your application’s dependencies as Cement explicitly does not include external dependencies for optional extensions.

Due to changes in pyYaml version 5.1 to deprecate yaml.load without specifying a Loader=…, this class will attempt to parse the yaml content with the 5.1 sugar method full_load, falling back to the “unsafe” call for versions prior to 5.1. The full_load method uses the FullLoader, which is the default Loader when none is provided. See the pyYaml message on this deprecation: https://msg.pyyaml.org/load

class Meta[source]

Bases: object

_parse_file(file_path)[source]

Parse Yaml configuration file settings from file_path, overwriting existing config settings. If the file does not exist, returns False.

Parameters:

file_path (str) – The file system path to the Yaml configuration file.

class cement.ext.ext_yaml.YamlOutputHandler(*args, **kw)[source]

Bases: OutputHandler

This class implements the Output Handler interface. It provides Yaml output from a data dictionary and uses pyYaml to dump it to STDOUT. Please see the developer documentation on Output Handling.

This handler forces Cement to suppress console output until app.render is called (keeping the output pure Yaml). If troubleshooting issues, you will need to pass the --debug option in order to unsuppress output and see what’s happening.

class Meta[source]

Bases: object

Handler meta-data.

overridable = False

Whether or not to include yaml as an available choice to override the output_handler via command line options.

_setup(app_obj)[source]

Called during application initialization and must setup the handler object making it ready for the framework or the application to make further calls to it.

Parameters:

app (instance) – The application object.

render(data_dict, template=None, **kw)[source]

Take a data dictionary and render it as Yaml output. Note that the template option is received here per the interface, however this handler just ignores it. Additional keyword arguments passed to yaml.dump().

Parameters:

data_dict (dict) – The data dictionary to render.

Keyword Arguments:

template (str) – Ignored in this output handler implementation.

Returns:

A Yaml encoded string.

Return type:

str

cement.ext.ext_yaml.suppress_output_after_render(app, out_text)[source]

This is a post_render hook that suppresses console output again after rendering, only if the YamlOutputHandler is triggered via command line.

Parameters:

app – The application object.

cement.ext.ext_yaml.suppress_output_before_run(app)[source]

This is a post_argument_parsing hook that suppresses console output if the YamlOutputHandler is triggered via command line.

Parameters:

app – The application object.

cement.ext.ext_yaml.unsuppress_output_before_render(app, data)[source]

This is a pre_render that unsuppresses console output if the YamlOutputHandler is triggered via command line so that the Yaml is the only thing in the output.

Parameters:

app – The application object.