Exemplo n.º 1
0
 def construct_object(node, deep=False):
     line = node.value['__line__']
     node.value = node.value['__val__']
     data = Constructor.construct_object(loader, node, deep)
     if isinstance(data, str):
         data = LineStr(data)
         data.line = line
     return data
Exemplo n.º 2
0
 def construct_object(node, deep=False):
     line = node.value['__line__']
     node.value = node.value['__val__']
     data = Constructor.construct_object(loader, node, deep)
     if isinstance(data, str):
         data = LineStr(data)
         data.line = line
     return data
Exemplo n.º 3
0
        def construct_object(node, deep=False):
            """ Invoked when PyYAML's internal nodes are converted to python types
            (e.g. ScalarNode -> str/int/float, SequenceNode -> list, MappingNode -> dictionary)
            """

            # In case we are dealing with an Alias, just convert it to a string (prepend the * again because PyYaml
            # strips it). Also add a line number.
            if isinstance(node, AliasEvent):
                data = LineStr("*" + node.anchor)
                data.line = node.line
                return data

            # retrieve previously stored line number and value, restore node.value to original value
            line = node.value['__line__']
            node.value = node.value['__val__']

            # call the original construct_object method
            data = Constructor.construct_object(loader, node, deep)

            # if the original construct_object method creating anything else then a list or dict (i.e. a str, int, float
            # datetime, etc), just wrap it in a LineStr object.
            if not (isinstance(data, dict) or isinstance(data, list)):
                if node.tag == "tag:yaml.org,2002:int":
                    data = LineInt(data)
                elif node.tag == "tag:yaml.org,2002:float":
                    data = LineFloat(data)
                else:
                    data = LineStr(data)

                # TODO(jroovers): node.start_mark.line and node.end_mark.line provide a lot of what we need. We can
                # definitely simplify this a lot. Stupid me for now finding this earlier. It doesn't provide exactly
                # what we need, especially when anchors are used (node.start_mark and node.end_mark then include
                # everything that is referenced as well). We should look into this (I've already spend 2 hrs on this
                # and wasn't able to fully figure it out)
                # data.line = node.start_mark.line
                # data.line_end = node.end_mark.line

                data.line = line
                data.line_end = node.end_mark.line

                # If the scalar node has a style, then keep that information around later
                if hasattr(node, 'style'):
                    data.style = node.style

            return data
Exemplo n.º 4
0
        def construct_object(node, deep=False):
            """ Invoked when PyYAML's internal nodes are converted to python types
            (e.g. ScalarNode -> str/int/float, SequenceNode -> list, MappingNode -> dictionary)
            """

            # In case we are dealing with an Alias, just convert it to a string (prepend the * again because PyYaml
            # strips it). Also add a line number.
            if isinstance(node, AliasEvent):
                data = LineStr("*" + node.anchor)
                data.line = node.line
                return data

            # retrieve previously stored line number and value, restore node.value to original value
            line = node.value['__line__']
            node.value = node.value['__val__']

            # call the original construct_object method
            data = Constructor.construct_object(loader, node, deep)

            # if the original construct_object method creating anything else then a list or dict (i.e. a str, int, float
            # datetime, etc), just wrap it in a LineStr object.
            if not (isinstance(data, dict) or isinstance(data, list)):
                if node.tag == "tag:yaml.org,2002:int":
                    data = LineInt(data)
                elif node.tag == "tag:yaml.org,2002:float":
                    data = LineFloat(data)
                else:
                    data = LineStr(data)

                # TODO(jroovers): node.start_mark.line and node.end_mark.line provide a lot of what we need. We can
                # definitely simplify this a lot. Stupid me for now finding this earlier. It doesn't provide exactly
                # what we need, especially when anchors are used (node.start_mark and node.end_mark then include
                # everything that is referenced as well). We should look into this (I've already spend 2 hrs on this
                # and wasn't able to fully figure it out)
                # data.line = node.start_mark.line
                # data.line_end = node.end_mark.line

                data.line = line
                data.line_end = node.end_mark.line

                # If the scalar node has a style, then keep that information around later
                if hasattr(node, 'style'):
                    data.style = node.style

            return data