예제 #1
0
    def yatiml_sweeten(self, node: yatiml.Node) -> None:
        namespace_nodes = node.get_attribute('namespaces').seq_items()
        namespaces = list(map(yatiml.Node.get_value, namespace_nodes))
        namespace_str = '.'.join(namespaces)

        name = node.get_attribute('name').get_value()
        node.set_value('{}.{}'.format(namespace_str, name))
예제 #2
0
def test_set_value(class_node: yatiml.Node) -> None:
    assert class_node.is_mapping()
    class_node.set_value(42)
    assert class_node.is_scalar(int)
    assert class_node.yaml_node.value == '42'
    class_node.set_value(True)
    assert class_node.is_scalar(bool)
    assert class_node.yaml_node.value == 'true'
예제 #3
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()])
예제 #4
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()))
예제 #6
0
 def yatiml_sweeten(self, node: yatiml.Node) -> None:
     digits = node.get_attribute('digits').get_value()
     letters = node.get_attribute('letters').get_value()
     node.set_value('{} {}'.format(digits, letters))
예제 #7
0
 def yatiml_sweeten(self, node: yatiml.Node) -> None:
     node.set_value(node.get_value().lower())  # type: ignore
예제 #8
0
 def yatiml_savorize(self, node: yatiml.Node) -> None:
     if node.is_scalar(str):
         node.set_value(node.get_value().upper())  # type: ignore
예제 #9
0
 def _yatiml_sweeten(cls, node: yatiml.Node) -> None:
     node.set_value(node.get_value().lower())
예제 #10
0
 def _yatiml_savorize(cls, node: yatiml.Node) -> None:
     if node.is_scalar(str):
         node.set_value(node.get_value().upper())