Module pychrysalide.plugins.yaml
Documentation
yaml is a module providing access to YAML content.
The parsing is provided by an external library: https://github.com/yaml/libyaml . The Python module only creates some glue to access YAML content from GObject code.
Classes
Methods
parse_from_file(filename)
Parse a YAML content in order to build the relative YAML tree.
The filename
argument is a string for a path pointing to a YAML content. This path can be either a real filename or a resource URI.
The result is a YamlNode
instance or None in case of error.
parse_from_text(text)
Parse a YAML content in order to build the relative YAML tree.
The text
argument is a string containg a markup content to parse.
The result is a YamlNode
instance or None in case of error.
Class YamlCollection
YamlCollection handles a collection of YAML nodes.
Instances can be created using the following constructor:
YamlCollection(seq=False)
Where seq
is a boolean value which defines if the collection will be a sequence or a mapping of nodes.
Hierarchy
builtins.object ╰── gi._gi.GObject ╰── pychrysalide.plugins.yaml.YamlNode ╰── pychrysalide.plugins.yaml.YamlCollection
Attributes
is_sequence
Nature of the collection: True if the collection is a sequence, False if it is a mapping of "key: value" nodes.
nodes
List of nodes contained in the current collection.
Class YamlNode
YamlNode handles a node in a YAML tree.
There are two kinds of node contents defined in the YAML specifications:
- pair, implemented by the
YamlPair
object; - sequence and mapping, implemented by the
YamlCollection
object.
Hierarchy
builtins.object ╰── gi._gi.GObject ╰── pychrysalide.plugins.yaml.YamlNode
Known subclasses:
Methods
find_first_by_path(path)
Find the first node related to a path among the node YAML children.
Paths are node keys separated by '/', such as '/my/path/to/node'. In case where the path ends with a trailing '/', the operation matches the first next met node.
The path
argument is expected to be a string value.
The function returns a YamlNode
instance, or None
if none found.
Class YamlPair
YamlPair handles a key/value pair node in a YAML tree.
Instances can be created using the following constructor:
YamlPair(key, kstyle=PLAIN, value=None, vstyle=PLAIN)
Where key
defines the name for the YAML node, and value
provides an optional direct value for the node. The kstyle
and vstyle
arguements are YamlOriginalStyle
states linking an original format to the provided relative strings.
The two style are mainly used to aggregate children values into a raw array. The following declarations are indeed equivalent and aggregate_value()
build the latter version from the former one:
a: [ 1, 2, 3 ]
a:
- 1
- 2
- 3
Hierarchy
builtins.object ╰── gi._gi.GObject ╰── pychrysalide.plugins.yaml.YamlNode ╰── pychrysalide.plugins.yaml.YamlPair
Methods
aggregate_value(self)
Provide the value linked to the YAML node, rebuilding it from inner sequenced values if necessary and possible.
The result is a string value, or None
if none available.
Attributes
children
Provide or define the collection of nodes attached to another YAML node. The collection, if defined, is handled as a YamlCollection
instance.
key
Key linked to the YAML key/value pair node, as a string value.
key_style
Original format for the YAML node Key, as a YamlOriginalStyle
value.
value
Value linked to the YAML key/value pair node, as a string value, or None
if none defined.
value_style
Original format for the YAML node Value, as a YamlOriginalStyle
value.
Even if there is no value for the node, the default style is returned: PLAIN
.
Constants
YamlOriginalStyle
Original style of scalar YAML nodes.
0 | = 0 |
1 | = 1 |
2 | = 2 |