summaryrefslogtreecommitdiff
path: root/comments.py
diff options
context:
space:
mode:
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, ]