From f3de88b82bf5e3902c44f6c30aed065e56626ee6 Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Tue, 25 Aug 2015 21:52:09 +0200 Subject: version bump --- CHANGES | 7 +++++++ README.rst | 1 + py/__init__.py | 2 +- py/configobjwalker.py | 33 +++++++++++++++++++++++++----- test/test_yaml.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++--- 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] == '' + -- cgit v1.2.1