arjuna.tpi.parser.yaml module

Classes to assist in YAML Parsing.

class arjuna.tpi.parser.yaml.Yaml

Bases: object

classmethod from_file(file_path, *, allow_any=False)

Creates a Yaml object from file.

Parameters:file_path – Absolute path of the yaml file.
Keyword Arguments:
 allow_any – If True, if the object can not be coverted to a YamlDict/YamlList, same object is returned, else an Exception is raised.
Returns:Arjuna’s YamlDict or YamlList object or the same object for allow_any = True
classmethod from_object(yobj, *, allow_any=False)

Convert a Python object to a YamlDict/YamlList object if applicable.

Any iterable which is not a dict is converted to a YamlList.

Parameters:yobj – dict or list or a compatible Python object.
Keyword Arguments:
 allow_any – If True, if the object can not be coverted, same object is returned, else an Exception is raised.
classmethod from_str(ystr, *, name='yaml', allow_any=False)

Creates a Yaml object from a YAML string.

Parameters:ystr – A string representing a compatible Python object.
Keyword Arguments:
 allow_any – If True, if the object can not be coverted to a YamlDict/YamlList, same object is returned, else an Exception is raised.
Returns:Arjuna’s YamlDict or YamlList object or the same object for allow_any = True
class arjuna.tpi.parser.yaml.YamlDict(pydict)

Bases: arjuna.tpi.helper.arjtype.CIStringDict, arjuna.tpi.parser.yaml.YamlElement

Encapsulates Dictionary object in Json.

Parameters:pydict – Python dict.

Note

Supports dictionary methods as well as . access for key.

Also supports == operator. Right operand can be a Python dict or a YamlDict object.

as_map()

A copy of the Python dict that this object wraps.

get_section(name, *, strict=True, as_yaml_str=False, allow_any=False)

Get Yaml object for a section/key name.

Parameters:name – Name of section/key
Keyword Arguments:
 strict – If True, raises Exception when name is not present, else returns None. Default is True.
has_section(name)

Check if a key/section name is present. You can also use the ‘in’ operator instead, like a Python dict.

items()

dictitems object containing key-value pairs in this object.

raw_object

A copy of the Python dict that this object wraps.

section_names

All section/key names in this object.

size

Number of key-value pairs in this object.

validate_sections_present(*, atleast_one=False)

Validate the presence of arbitrary section/key names.

Parameters:section_names – arbitrary section/key names
Keyword Arguments:
 atleast_one – If True, it is expected that atleast one of the sections is present, else all are expected to be present.
class arjuna.tpi.parser.yaml.YamlElement(pydict_or_list)

Bases: object

Abstract Json Element. Base class for YamlList and YamlDict.

as_str()

Get string representation of this Yaml Element.

is_empty()
class arjuna.tpi.parser.yaml.YamlList(pylist)

Bases: arjuna.tpi.parser.yaml.YamlElement, json.encoder.JSONEncoder

Encapsulates a list object in YAML.

Parameters:pylist – Python list

Note

Supports indexing just like a Python list.

Also supports == operator. Right operand can be a Python list or a YamlList object.

default(o)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
raw_object

A copy of the Python list that this object wraps.

size

Number of objects in this list.

arjuna.tpi.parser.yaml.join_tag(loader, node)