summaryrefslogtreecommitdiff
path: root/comments.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2016-02-27 10:15:02 +0100
committerAnthon van der Neut <anthon@mnt.org>2016-02-27 10:15:02 +0100
commit2f9cdc98cc0adea615cb2180481c7780eef48f97 (patch)
treeff710ad0913ced7c241f0445e95e6eefeb24ae1b /comments.py
parentacc0b296466c5364569b1df8402d2cb95ca01915 (diff)
downloadruamel.yaml-2f9cdc98cc0adea615cb2180481c7780eef48f97.tar.gz
pep8 compliance, util.load_yaml_guess_indent0.11.2
Diffstat (limited to 'comments.py')
-rw-r--r--comments.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/comments.py b/comments.py
index 7cac4f6..8e5ebb8 100644
--- a/comments.py
+++ b/comments.py
@@ -3,9 +3,6 @@
from __future__ import absolute_import
from __future__ import print_function
-__all__ = ["CommentedSeq", "CommentedMap", "CommentedOrderedMap",
- "CommentedSet", 'comment_attrib', 'merge_attrib']
-
"""
stuff to deal with comments and formatting on dict/list/ordereddict/set
these are not really related, formatting could be factored out as
@@ -14,6 +11,10 @@ a separate base
from collections import MutableSet
+__all__ = ["CommentedSeq", "CommentedMap", "CommentedOrderedMap",
+ "CommentedSet", 'comment_attrib', 'merge_attrib']
+
+
try:
from .compat import ordereddict
except ImportError:
@@ -24,6 +25,7 @@ format_attrib = '_yaml_format'
line_col_attrib = '_yaml_line_col'
anchor_attrib = '_yaml_anchor'
merge_attrib = '_yaml_merge'
+tag_attrib = '_yaml_tag'
class Comment(object):
@@ -140,6 +142,14 @@ class Anchor(object):
self.always_dump = False
+class Tag(object):
+ """store tag information for roundtripping"""
+ attrib = tag_attrib
+
+ def __init__(self):
+ self.value = None
+
+
class CommentedBase(object):
@property
def ca(self):
@@ -245,6 +255,15 @@ class CommentedBase(object):
self.anchor.value = value
self.anchor.always_dump = always_dump
+ @property
+ def tag(self):
+ if not hasattr(self, Tag.attrib):
+ setattr(self, Tag.attrib, Tag())
+ return getattr(self, Tag.attrib)
+
+ def yaml_set_tag(self, value):
+ self.tag.value = value
+
class CommentedSeq(list, CommentedBase):
__slots__ = [Comment.attrib, ]