summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2015-08-25 21:52:09 +0200
committerAnthon van der Neut <anthon@mnt.org>2015-08-25 21:52:09 +0200
commitf3de88b82bf5e3902c44f6c30aed065e56626ee6 (patch)
treec4ee6f6eb186b9776d73c0f9ea6dc26319a06921
parentbac63bd181213089ddb8d044e05f242a1c496916 (diff)
downloadruamel.yaml-f3de88b82bf5e3902c44f6c30aed065e56626ee6.tar.gz
version bump0.10.5
-rw-r--r--CHANGES7
-rw-r--r--README.rst1
-rw-r--r--py/__init__.py2
-rw-r--r--py/configobjwalker.py33
-rw-r--r--test/test_yaml.py56
5 files changed, 90 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index b301d37..d2488d1 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,10 @@
+0.10.5: 2015-08-25
+- preservation of newlines after block scalars. Contributed by Sam Thursfield.
+
+0.10: 2015-06-22
+- preservation of hand crafted anchor names ( not of the form "idNNN")
+- preservation of map merges ( <<< )
+
0.9: 2015-04-18
- collections read in by the RoundTripLoader now have a ``lc`` property
that can be quired for line and column ( ``lc.line`` resp. ``lc.col``)
diff --git a/README.rst b/README.rst
index 82ad3cd..614767d 100644
--- a/README.rst
+++ b/README.rst
@@ -36,6 +36,7 @@ Major differences with PyYAML 3.11:
with smart column positioning
- collection objects (when read in via RoundTripParser) have an ``lc``
property that contains line and column info ``lc.line`` and ``lc.col``
+- preservation of whitelines after block scalars. Contributed by Sam Thursfield.
Round trip including comments
=============================
diff --git a/py/__init__.py b/py/__init__.py
index d164c2e..fadaba7 100644
--- a/py/__init__.py
+++ b/py/__init__.py
@@ -21,7 +21,7 @@ def _convert_version(tup):
return ret_val
-version_info = (0, 10, 4)
+version_info = (0, 10, 5)
__version__ = _convert_version(version_info)
del _convert_version
diff --git a/py/configobjwalker.py b/py/configobjwalker.py
index 985fd36..576adcd 100644
--- a/py/configobjwalker.py
+++ b/py/configobjwalker.py
@@ -21,22 +21,45 @@ def configobj_walker(cfg):
def _walk_section(s, level=0):
from configobj import Section
assert isinstance(s, Section)
- indent = ' ' * level
+ indent = u' ' * level
for name in s.scalars:
for c in s.comments[name]:
yield indent + c.strip()
- line = '{0}{1}: {2}'.format(indent, name, s[name])
+ x = s[name]
+ if u'\n' in x:
+ i = indent + u' '
+ x = u'|\n' + i + x.strip().replace(u'\n', u'\n' + i)
+ elif ':' in x:
+ x = u"'" + x.replace(u"'", u"''") + u"'"
+ line = u'{0}{1}: {2}'.format(indent, name, x)
c = s.inline_comments[name]
if c:
- line += ' ' + c
+ line += u' ' + c
yield line
for name in s.sections:
for c in s.comments[name]:
yield indent + c.strip()
- line = '{0}{1}:'.format(indent, name)
+ line = u'{0}{1}:'.format(indent, name)
c = s.inline_comments[name]
if c:
- line += ' ' + c
+ line += u' ' + c
yield line
for val in _walk_section(s[name], level=level+1):
yield val
+
+##def config_obj_2_rt_yaml(cfg):
+## from .comments import CommentedMap, CommentedSeq
+## from configobj import ConfigObj
+## assert isinstance(cfg, ConfigObj)
+## #for c in cfg.initial_comment:
+## # if c.strip():
+## # pass
+## cm = CommentedMap()
+## for name in s.sections:
+## cm[name] = d = CommentedMap()
+##
+##
+## #for c in cfg.final_comment:
+## # if c.strip():
+## # yield c
+## return cm
diff --git a/test/test_yaml.py b/test/test_yaml.py
index 503e153..75f2479 100644
--- a/test/test_yaml.py
+++ b/test/test_yaml.py
@@ -90,8 +90,8 @@ class TestYAML:
- baz
""")
- def test_blank_line_after_literal(self):
- round_trip("""
+ def test_blank_line_after_literal_chip(self):
+ s = """
c:
- |
This item
@@ -104,4 +104,54 @@ class TestYAML:
This item contains a blank line.
- """)
+ """
+ d = round_trip_load(dedent(s))
+ print(d)
+ round_trip(s)
+ assert d['c'][0].split('it.')[1] == '\n'
+ assert d['c'][1].split('line.')[1] == '\n'
+
+ def test_blank_line_after_literal_keep(self):
+ """ have to insert an eof marker in YAML to test this"""
+ s = """
+ c:
+ - |+
+ This item
+ has a blank line
+ following it.
+
+ - |+
+ To visually separate it from this item.
+
+ This item contains a blank line.
+
+
+ ...
+ """
+ d = round_trip_load(dedent(s))
+ print(d)
+ round_trip(s)
+ assert d['c'][0].split('it.')[1] == '\n\n'
+ assert d['c'][1].split('line.')[1] == '\n\n\n'
+
+ def test_blank_line_after_literal_strip(self):
+ s = """
+ c:
+ - |-
+ This item
+ has a blank line
+ following it.
+
+ - |-
+ To visually separate it from this item.
+
+ This item contains a blank line.
+
+
+ """
+ d = round_trip_load(dedent(s))
+ print(d)
+ round_trip(s)
+ assert d['c'][0].split('it.')[1] == ''
+ assert d['c'][1].split('line.')[1] == ''
+