Exemplo n.º 1
0
    def yaml_set_start_comment(self, comment, indent=0):
        # type: (Any, Any) -> None
        """overwrites any preceding comment lines on an object
        expects comment to be without `#` and possible have multiple lines
        """
        from ruyaml.error import CommentMark
        from ruyaml.tokens import CommentToken

        pre_comments = self._yaml_get_pre_comment()
        if comment[-1] == '\n':
            comment = comment[:-1]  # strip final newline if there
        start_mark = CommentMark(indent)
        for com in comment.split('\n'):
            pre_comments.append(
                CommentToken('# ' + com + '\n', start_mark, None))
Exemplo n.º 2
0
    def yaml_add_eol_comment(self, comment, key=NoComment, column=None):
        # type: (Any, Optional[Any], Optional[Any]) -> None
        """
        there is a problem as eol comments should start with ' #'
        (but at the beginning of the line the space doesn't have to be before
        the #. The column index is for the # mark
        """
        from ruyaml.error import CommentMark
        from ruyaml.tokens import CommentToken

        if column is None:
            try:
                column = self._yaml_get_column(key)
            except AttributeError:
                column = 0
        if comment[0] != '#':
            comment = '# ' + comment
        if column is None:
            if comment[0] == '#':
                comment = ' ' + comment
                column = 0
        start_mark = CommentMark(column)
        ct = [CommentToken(comment, start_mark), None]
        self._yaml_add_eol_comment(ct, key=key)
Exemplo n.º 3
0
 def comment_token(s, mark):
     # type: (Any, Any) -> Any
     # handle empty lines as having no comment
     return CommentToken(('# ' if s else "") + s + '\n', mark)