changeset 380:a106d7e1415b

Colons are allowed in strings
author Stefano Rivera <stefano@rivera.za.net>
date Fri, 06 Sep 2013 23:36:08 +0200
parents e2cebabf87e8
children e0d27a11f49a
files nagslang/tests/test_yamlish.py nagslang/yamlish.py
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/nagslang/tests/test_yamlish.py	Fri Sep 06 23:11:37 2013 +0200
+++ b/nagslang/tests/test_yamlish.py	Fri Sep 06 23:36:08 2013 +0200
@@ -108,6 +108,14 @@
             0.7: -0.7,
         })
 
+    def test_dictish_string(self):
+        self.roundtrip({
+            'strings': [
+                'Foo: bar',
+                'Baz: qux',
+            ],
+        })
+
     def test_tuples(self):
         if self.from_pyyaml:
             raise SkipTest("Can't parse PyYAML tuples")
--- a/nagslang/yamlish.py	Fri Sep 06 23:11:37 2013 +0200
+++ b/nagslang/yamlish.py	Fri Sep 06 23:36:08 2013 +0200
@@ -100,7 +100,7 @@
     def _dump_basestring(self, data):
         if data in ('true', 'false', 'null'):
             return "'%s'" % data
-        if "'" in data:
+        if "'" in data or ':' in data or data.startswith('['):
             return "'%s'" % data.replace("'", "''")
         if data == '':
             return "''"
@@ -123,7 +123,7 @@
 class Parser(object):
     _spaces_re = re.compile(r'^(\s*)(.*)')
     _list_re = re.compile(r'^(-\s+)(.*)')
-    _dict_re = re.compile(r'^((?![{[])[^-:]+):\s?(.*)')
+    _dict_re = re.compile(r"^((?![{['])[^-:]+):\s?(.*)")
     _inline_list_re = re.compile(r"^([^',]+|(?:'')+|'.+?[^'](?:'')*')"
                                  r"(?:, (.*))?$")