Exemple #1
0
    def _yatiml_savorize(cls, node: yatiml.Node) -> None:
        # enum.Enum has a __members__ attribute which contains its
        # members, which we reverse here to make a look-up table that
        # converts values in the YAML file to names expected by YAtiML.
        yaml_to_python = {
                v.value: v.name for v in cls.__members__.values()}

        # Remember that the node can be anything here. We only convert
        # if it's a string with an expected value, otherwise we leave
        # it alone so that a useful error message can be generated.
        if node.is_scalar(str):
            if node.get_value() in yaml_to_python:
                node.set_value(yaml_to_python[node.get_value()])
Exemple #2
0
    def yatiml_savorize(cls, node: yatiml.Node) -> None:
        text = str(node.get_value())
        parts = text.split('.')
        node.make_mapping()

        # We need to make a yaml.SequenceNode by hand here, since
        # set_attribute doesn't take lists as an argument.
        start_mark = yaml.error.StreamMark('generated node', 0, 0, 0)
        end_mark = yaml.error.StreamMark('generated node', 0, 0, 0)
        item_nodes = list()
        for part in parts[:-1]:
            item_nodes.append(
                yaml.ScalarNode('tag:yaml.org,2002:str', part, start_mark,
                                end_mark))
        ynode = yaml.SequenceNode('tag:yaml.org,2002:seq', item_nodes,
                                  start_mark, end_mark)
        node.set_attribute('namespaces', ynode)
        node.set_attribute('name', parts[-1])
Exemple #3
0
 def _yatiml_sweeten(cls, node: yatiml.Node) -> None:
     # Here we just use cls.__members__ directly to convert.
     node.set_value(cls.__members__[node.get_value()].value)
 def _yatiml_savorize(cls, node: yatiml.Node) -> None:
     yaml_to_py = {v._value_: v._name_ for v in cls.__members__.values()}
     if node.is_scalar(str):
         node.set_value(yaml_to_py.get(node.get_value()))
Exemple #5
0
 def yatiml_savorize(cls, node: yatiml.Node) -> None:
     text = str(node.get_value())
     node.make_mapping()
     node.set_attribute('digits', int(text[0:4]))
     node.set_attribute('letters', text[5:7])
Exemple #6
0
 def yatiml_sweeten(self, node: yatiml.Node) -> None:
     node.set_value(node.get_value().lower())  # type: ignore
Exemple #7
0
 def yatiml_savorize(self, node: yatiml.Node) -> None:
     if node.is_scalar(str):
         node.set_value(node.get_value().upper())  # type: ignore
Exemple #8
0
 def _yatiml_sweeten(cls, node: yatiml.Node) -> None:
     node.set_value(node.get_value().lower())
Exemple #9
0
 def _yatiml_savorize(cls, node: yatiml.Node) -> None:
     if node.is_scalar(str):
         node.set_value(node.get_value().upper())