示例#1
0
 def compose_node(self, parent, index):
     line = self.line
     node = Composer.compose_node(self, parent, index)
     # The line number where the previous token has ended (plus empty lines)
     node.__line_start__ = line + 1
     node.__line_end__ = self.line
     return node
示例#2
0
    def compose_node(self, parent, index):
        # Stash the associated locations on the YAML node
        ret = Composer.compose_node(self, parent, index)
        ret.__lineno__ = self.line
        ret.__linepos__ = self.column

        return ret
 def compose_node(parent, index):
     # the line number where the previous token has ended (plus empty lines)
     line = loader.line
     node = Composer.compose_node(loader, parent, index)
     node.__file__ = file
     node.__line__ = line + 1
     return node
示例#4
0
 def compose_node(self, parent: yaml.nodes.Node,
                  index: int) -> yaml.nodes.Node:
     # the line number where the previous token has ended (plus empty lines)
     line = self.line
     node = Composer.compose_node(self, parent, index)
     node._start_line = line + 1
     return node
示例#5
0
 def compose_node(parent: yaml.nodes.Node, index: int) -> yaml.nodes.Node:
     # the line number where the previous token has ended (plus empty lines)
     line = loader.line
     node = Composer.compose_node(loader, parent, index)
     if not isinstance(node, yaml.nodes.Node):
         raise RuntimeError("Unexpected yaml data.")
     setattr(node, '__line__', line + 1)
     return node
示例#6
0
 def compose_node(parent, index):
     # the line number where the previous token has ended (plus empty lines)
     line = loader.line
     column = loader.column
     node = Composer.compose_node(loader, parent, index)
     node.__line__ = line + 1
     node.__column__ = column + 1
     node.__basename__ = basename
     node.__location__ = basename+":"+str(line + 1)
     return node
示例#7
0
 def compose_node(self, parent, index):
     # the line number where the previous token has ended (plus empty lines)
     node = Composer.compose_node(self, parent, index)
     if isinstance(node, MappingNode):
         node.__datasource__ = self.name
         try:
             (cur_line, cur_column) = self.__mapping_starts.pop()
         except:
             cur_line = None
             cur_column = None
         node.__line__   = cur_line
         node.__column__ = cur_column
     return node
示例#8
0
 def compose_node(self, parent, index):
     # the line number where the previous token has ended (plus empty lines)
     node = Composer.compose_node(self, parent, index)
     if isinstance(node, MappingNode):
         node.__datasource__ = self.name
         try:
             (cur_line, cur_column) = self.__mapping_starts.pop()
         except:
             cur_line = None
             cur_column = None
         node.__line__ = cur_line
         node.__column__ = cur_column
     return node
示例#9
0
        def compose_node(parent, index):
            # the line number where the previous token has ended (plus empty lines)
            line = loader.line
            node = Composer.compose_node(loader, parent, index)

            # TODO(jroovers): special case -> document better
            if isinstance(node.value, list) and len(node.value) > 0:
                if not isinstance(node.value[0], tuple):
                    # Processing a real yaml list -> substract 1
                    for list_node in node.value:
                        list_node.value['__line__'] -= 1

            node.value = {"__line__": line, "__val__": node.value}

            return node
示例#10
0
        def compose_node(parent, index):
            # the line number where the previous token has ended (plus empty lines)
            line = loader.line
            node = Composer.compose_node(loader, parent, index)

            # TODO(jroovers): special case -> document better
            if isinstance(node.value, list) and len(node.value) > 0:
                if not isinstance(node.value[0], tuple):
                    # Processing a real yaml list -> substract 1
                    for list_node in node.value:
                        list_node.value['__line__'] -= 1

            node.value = {"__line__": line, "__val__": node.value}

            return node
示例#11
0
        def compose_node(parent, index):
            """ Invoked when a new node (key, value or compound (dict, list) type) is created. """
            line = loader.line  # the line number where the previous token has ended (plus empty lines)

            # If we get an alias, just return the alias event, we then know how to handle it in construct_object.
            # This allows us to not follow aliases which is handy in many cases.
            # https://github.com/yaml/pyyaml/blob/a7daab723352e68a209479b781b2f03c47e5179a/lib/yaml/composer.py#L64
            if loader.check_event(AliasEvent):
                event = loader.get_event()
                event.line = line  # Do make sure we associate a line number with the alias
                return event

            # call the original compose_node
            node = Composer.compose_node(loader, parent, index)

            # In case we are dealing with a yaml list, the line numbers turn out to be off by 1 which we need to fix.
            # What the parser will do is first invoke this method with every item in the list and then invoke it again
            # with the entire list. At that point we can iterate over the list and substract 1 from the line numbers
            # of the items in the list.
            # For single items in a list, Composer.compose_node(...) returns a ScalarNode. node.value is then of type
            # str, int, float, etc. For the entire list, Composer.compose_node(...) will return a SequenceNode with
            # node.value being of type 'list'. So by checking for the type of node.value, we can figure out whether
            # we are currently processing an item in a list or the actual list itself.
            # The only additional required check is making sure that in case node.value is a list, the items in
            # node.value are not tuples (because if they are, we are dealing with a nested dictionary instead of a
            # normal list). We can do this by checking whether node.value[0] is an instance of tuple or not.
            if isinstance(node.value, list) and len(node.value) > 0:
                if not isinstance(node.value[0], tuple):
                    # We're processing a real yaml list -> substract 1 from the line numbers in the list
                    for list_node in node.value:
                        list_node.value['__line__'] -= 1

            if not isinstance(node.value, dict):
                # replace the value of the node with a dictionary that contains both the line number and value
                node.value = {"__line__": line, "__val__": node.value}

            return node
示例#12
0
        def compose_node(parent, index):
            """ Invoked when a new node (key, value or compound (dict, list) type) is created. """
            line = loader.line  # the line number where the previous token has ended (plus empty lines)

            # If we get an alias, just return the alias event, we then know how to handle it in construct_object.
            # This allows us to not follow aliases which is handy in many cases.
            # https://github.com/yaml/pyyaml/blob/a7daab723352e68a209479b781b2f03c47e5179a/lib/yaml/composer.py#L64
            if loader.check_event(AliasEvent):
                event = loader.get_event()
                event.line = line  # Do make sure we associate a line number with the alias
                return event

            # call the original compose_node
            node = Composer.compose_node(loader, parent, index)

            # In case we are dealing with a yaml list, the line numbers turn out to be off by 1 which we need to fix.
            # What the parser will do is first invoke this method with every item in the list and then invoke it again
            # with the entire list. At that point we can iterate over the list and substract 1 from the line numbers
            # of the items in the list.
            # For single items in a list, Composer.compose_node(...) returns a ScalarNode. node.value is then of type
            # str, int, float, etc. For the entire list, Composer.compose_node(...) will return a SequenceNode with
            # node.value being of type 'list'. So by checking for the type of node.value, we can figure out whether
            # we are currently processing an item in a list or the actual list itself.
            # The only additional required check is making sure that in case node.value is a list, the items in
            # node.value are not tuples (because if they are, we are dealing with a nested dictionary instead of a
            # normal list). We can do this by checking whether node.value[0] is an instance of tuple or not.
            if isinstance(node.value, list) and len(node.value) > 0:
                if not isinstance(node.value[0], tuple):
                    # We're processing a real yaml list -> substract 1 from the line numbers in the list
                    for list_node in node.value:
                        list_node.value['__line__'] -= 1

            if not isinstance(node.value, dict):
                # replace the value of the node with a dictionary that contains both the line number and value
                node.value = {"__line__": line, "__val__": node.value}

            return node
示例#13
0
 def compose_node(self, parent, index):
     # the line number where the previous token has ended (plus empty lines)
     node = Composer.compose_node(self, parent, index)
     node.__lineno__ = self.line + 1
     return node
示例#14
0
 def compose_node(parent, index):
     line = loader.line
     node = Composer.compose_node(loader, parent, index)
     node.__line__ = line + 1
     return node
示例#15
0
 def compose_node(parent, index):
     node = Composer.compose_node(loader, parent, index)
     self.parse_message(node, loader.line)
     return node
示例#16
0
 def compose_node(parent, index):
     # the line number where the previous token has ended (plus empty lines)
     line = loader.line
     node = Composer.compose_node(loader, parent, index)
     node.__line__ = line + 1
     return node
示例#17
0
 def compose_node(self, parent, index):
     # the line number where the previous token has ended (plus empty lines)
     node = Composer.compose_node(self.loader, parent, index)
     return node