summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--representer.py21
-rw-r--r--test/roundtrip.py3
-rw-r--r--tokens.py4
3 files changed, 28 insertions, 0 deletions
diff --git a/representer.py b/representer.py
index 63c0d0d..c1bbb8b 100644
--- a/representer.py
+++ b/representer.py
@@ -650,7 +650,14 @@ class RoundTripRepresenter(SafeRepresenter):
try:
comment = getattr(mapping, comment_attrib)
node.comment = comment.comment
+ if node.comment and node.comment[1]:
+ for ct in node.comment[1]:
+ ct.reset()
item_comments = comment.items
+ for v in item_comments.values():
+ if v and v[1]:
+ for ct in v[1]:
+ ct.reset()
try:
node.comment.append(comment.end)
except AttributeError:
@@ -711,7 +718,14 @@ class RoundTripRepresenter(SafeRepresenter):
try:
comment = getattr(omap, comment_attrib)
node.comment = comment.comment
+ if node.comment and node.comment[1]:
+ for ct in node.comment[1]:
+ ct.reset()
item_comments = comment.items
+ for v in item_comments.values():
+ if v and v[1]:
+ for ct in v[1]:
+ ct.reset()
try:
node.comment.append(comment.end)
except AttributeError:
@@ -763,7 +777,14 @@ class RoundTripRepresenter(SafeRepresenter):
try:
comment = getattr(setting, comment_attrib)
node.comment = comment.comment
+ if node.comment and node.comment[1]:
+ for ct in node.comment[1]:
+ ct.reset()
item_comments = comment.items
+ for v in item_comments.values():
+ if v and v[1]:
+ for ct in v[1]:
+ ct.reset()
try:
node.comment.append(comment.end)
except AttributeError:
diff --git a/test/roundtrip.py b/test/roundtrip.py
index e91df9c..446e943 100644
--- a/test/roundtrip.py
+++ b/test/roundtrip.py
@@ -49,3 +49,6 @@ def round_trip(inp, outp=None, extra=None, intermediate=None):
res = round_trip_dump(data)
print('roundtrip data:\n', res, sep='')
assert res == doutp
+ res = round_trip_dump(data)
+ print('roundtrip second round data:\n', res, sep='')
+ assert res == doutp
diff --git a/tokens.py b/tokens.py
index 452803f..95a43a5 100644
--- a/tokens.py
+++ b/tokens.py
@@ -186,3 +186,7 @@ class CommentToken(Token):
def __init__(self, value, start_mark, end_mark):
Token.__init__(self, start_mark, end_mark)
self.value = value
+
+ def reset(self):
+ if hasattr(self, 'pre_done'):
+ delattr(self, 'pre_done') \ No newline at end of file