cement.ext.ext_json

Cement json extension module.

class cement.ext.ext_json.JsonConfigHandler(*args, **kw)[source]

Bases: ConfigParserConfigHandler

This class implements the Config Handler interface, and provides the same functionality of ConfigParserConfigHandler but with JSON configuration files.

class Meta[source]

Bases: object

Handler meta-data.

json_module = 'json'

Backend JSON library module to use (json, ujson).

_parse_file(file_path)[source]

Parse JSON 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 JSON configuration

  • file.

Returns:

bool

_setup(app)[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.

class cement.ext.ext_json.JsonOutputHandler(*args, **kw)[source]

Bases: OutputHandler

This class implements the Output Handler interface. It provides JSON output from a data dictionary using the json module of the standard library. 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 JSON). 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

json_module = 'json'

Backend JSON library module to use (json, ujson)

label = 'json'

The string identifier of this handler.

overridable = False

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

_setup(app)[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 Json output. Note that the template option is received here per the interface, however this handler just ignores it. Additional keyword arguments passed to json.dumps().

Parameters:

data_dict (dict) – The data dictionary to render.

Keyword Arguments:

template – This option is completely ignored.

Returns:

A JSON encoded string.

Return type:

str

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

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

Parameters:

app – The application object.

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

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

Parameters:

app – The application object.

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

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

Parameters:

app – The application object.