pyats.utils.yaml package

Submodules

class pyats.utils.yaml.dumper.OrderedSafeDumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)

Bases: yaml.dumper.SafeDumper

Order safe dumper

static ordereddict_representer(dumper, data)
yaml_representers = {<class 'NoneType'>: <function SafeRepresenter.represent_none>, <class 'str'>: <function SafeRepresenter.represent_str>, <class 'bytes'>: <function SafeRepresenter.represent_binary>, <class 'bool'>: <function SafeRepresenter.represent_bool>, <class 'int'>: <function SafeRepresenter.represent_int>, <class 'float'>: <function SafeRepresenter.represent_float>, <class 'list'>: <function SafeRepresenter.represent_list>, <class 'tuple'>: <function SafeRepresenter.represent_list>, <class 'dict'>: <function SafeRepresenter.represent_dict>, <class 'set'>: <function SafeRepresenter.represent_set>, <class 'datetime.date'>: <function SafeRepresenter.represent_date>, <class 'datetime.datetime'>: <function SafeRepresenter.represent_datetime>, None: <function SafeRepresenter.represent_undefined>, <class 'collections.OrderedDict'>: <function OrderedSafeDumper.ordereddict_representer>}

Errors related to utils.yaml module

exception pyats.utils.yaml.exceptions.LoadError

Bases: Exception

Raised when the input loadable cannot be loaded

exception pyats.utils.yaml.exceptions.MarkupError

Bases: Exception

class pyats.utils.yaml.loader.Loader(schema=None, supported_schema_versions=None, enable_extensions=False, preprocessor=None, markupprocessor=None, postprocessor=None, preserve_order=False, advanced_datatypes=True)

Bases: object

Generic YAML loader.

Parameters
  • schema (A schema as understood by the) – schemaengine module containing the validation criteria for the content to load.

  • supported_schema_versions (A list of schema version numbers) – that are supported.

  • markupprocessor (A function that, if specified, accepts content,) – transforms that content using markup processing, and returns the content. If not specified, use the default markup processor.

  • preprocessor (A function that, if specified, accepts content,) – performs pre-validation processing and returns the content.

  • postprocessor (A function that, if specified, accepts content,) – performs post-validation processing and returns the content.

  • enable_extensions (If specified as True then allow the extends) – content key to contain an optional filename or list of filenames. The actual content is assembled by loading the raw content of each extension file in turn, starting with the last file in the list, and recursively updating content. Finally, the content of the input loadable is then updated on top. The extends key is expected to be present in the schema. If specified as False, then no extension processing is done and the extends key is not expected to be present in the schema. Defaults to False.

  • advanced_datatypes (Boolean to indicate usage of advanded data types.) – If True, will update the data with the return value of callable schema objects. Defaults to True.

load(*loadables, locations=None)
load_arbitrary(loadable, *, locations=None)
process_extensions(content, locations=None)

Recursively merge user-specified extension files, in order.

Post-process the content and look for “extends” key. If found, bring in its content and then add this file’s content on top.

Also process nested extensions if they are present (ie. extending from a file which extends from another file …).

Note

Non-file YAML input is allowed but this means extension filenames must be specified with relative or absolute pathnames.

Returns

  • The recursively updated contents of the extension files, with the

  • input content updated last (on top of the extension content).

  • For example, process_extensions(content) when the extends key

  • contains [a b c] returns (c + (b + (a + content))) where

  • a + b denotes a recursive dictionary update where b’s content

  • is added on top of a’s content.

class pyats.utils.yaml.loader.UniqueKeyLoader(stream, *, locations=None, file_name=None)

Bases: pyats.utils.locations.LocSafeLoader

Validate that the input file does not have duplicate keys.

Initialize the scanner.

construct_mapping(node, deep=False)
class pyats.utils.yaml.markup.Processor(reference=True, callable=True, env_var=True, include_file=True, ask=True, encode=True, cli_var=True, extend_list=True, yaml_loader_cls=None)

Bases: object

argv = ['-M', 'html', '.', '/ws/lsheikal-sjc/release_24.11/pypi/pyats_docs/docs/__build__/documentation']
match_ask_markup(data)
match_callable_markup(data)
match_cli_markup(data)
match_enc_markup(data)
match_env_markup(data)
match_extend_list_markup(data)
match_include_file_markup(data)
match_reference_markup(data)
p_ask_markup(match, data, index, locations=None)
p_callable_markup(match, data, index, locations=None)
p_cli_markup(match, data, index, locations=None)
p_enc_markup(match, data, index, locations=None)
p_environ_markup(match, data, index, locations=None)
p_extend_list_markup(match, data, index, locations=None)

The extend list markup allows a value to use the %EXTEND_LIST{value1,value2,..} markup.

The values are one or more references separated by a comma, the values are assumed to be referencing a list of data and the resulting data will be the extension of the lists into a single list of values.

p_file_markup(match, data, index, locations=None)
p_reference_markup(match, data, index, locations=None)
pyats.utils.yaml.markup.ask_for_input(prompt_text)