Mercurial > nagslang
comparison nagslang/yamlish.py @ 380:a106d7e1415b
Colons are allowed in strings
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Fri, 06 Sep 2013 23:36:08 +0200 |
parents | 1d73867becbe |
children | 80c452f348dc |
comparison
equal
deleted
inserted
replaced
379:e2cebabf87e8 | 380:a106d7e1415b |
---|---|
98 for key, value in data.iteritems()) | 98 for key, value in data.iteritems()) |
99 | 99 |
100 def _dump_basestring(self, data): | 100 def _dump_basestring(self, data): |
101 if data in ('true', 'false', 'null'): | 101 if data in ('true', 'false', 'null'): |
102 return "'%s'" % data | 102 return "'%s'" % data |
103 if "'" in data: | 103 if "'" in data or ':' in data or data.startswith('['): |
104 return "'%s'" % data.replace("'", "''") | 104 return "'%s'" % data.replace("'", "''") |
105 if data == '': | 105 if data == '': |
106 return "''" | 106 return "''" |
107 return data | 107 return data |
108 | 108 |
121 | 121 |
122 | 122 |
123 class Parser(object): | 123 class Parser(object): |
124 _spaces_re = re.compile(r'^(\s*)(.*)') | 124 _spaces_re = re.compile(r'^(\s*)(.*)') |
125 _list_re = re.compile(r'^(-\s+)(.*)') | 125 _list_re = re.compile(r'^(-\s+)(.*)') |
126 _dict_re = re.compile(r'^((?![{[])[^-:]+):\s?(.*)') | 126 _dict_re = re.compile(r"^((?![{['])[^-:]+):\s?(.*)") |
127 _inline_list_re = re.compile(r"^([^',]+|(?:'')+|'.+?[^'](?:'')*')" | 127 _inline_list_re = re.compile(r"^([^',]+|(?:'')+|'.+?[^'](?:'')*')" |
128 r"(?:, (.*))?$") | 128 r"(?:, (.*))?$") |
129 | 129 |
130 def __init__(self): | 130 def __init__(self): |
131 # Stack of (indent level, container object) | 131 # Stack of (indent level, container object) |