configglue team mailing list archive
-
configglue team
-
Mailing list archive
-
Message #00018
[Merge] lp:~configglue/configglue/escape-newline-for-lists into lp:configglue
Ricardo Kirkner has proposed merging lp:~configglue/configglue/escape-newline-for-lists into lp:configglue.
Requested reviews:
Configglue developers (configglue)
Related bugs:
#637079 override LinesConfigOption value from command-line
https://bugs.launchpad.net/bugs/637079
Overview
========
This branch adds support for parsing \\n into \n characters so that lists can also be entered from the command line (where entering \n is not possible).
--
https://code.launchpad.net/~configglue/configglue/escape-newline-for-lists/+merge/35277
Your team Configglue developers is requested to review the proposed merge of lp:~configglue/configglue/escape-newline-for-lists into lp:configglue.
=== modified file 'configglue/pyschema/options.py'
--- configglue/pyschema/options.py 2010-08-04 21:00:09 +0000
+++ configglue/pyschema/options.py 2010-09-13 12:49:46 +0000
@@ -74,6 +74,8 @@
else:
value = self.item.parse(value, raw=raw)
return value
+ if isinstance(value, basestring):
+ value = value.replace('\\n', '\n')
items = [_parse_item(x) for x in value.split('\n') if len(x)]
if self.remove_duplicates:
filtered_items = []
=== modified file 'tests/pyschema/test_options.py'
--- tests/pyschema/test_options.py 2010-08-04 12:42:29 +0000
+++ tests/pyschema/test_options.py 2010-09-13 12:49:46 +0000
@@ -202,6 +202,17 @@
self.assertEquals({'__main__': {'foo': [{'bar': 'baz'}]}},
parser.values())
+ def test_parse_escaped_newline(self):
+ class MySchema(Schema):
+ foo = LinesConfigOption(item=StringConfigOption())
+
+ config = StringIO('[__main__]\nfoo = a\\nb')
+ parser = SchemaConfigParser(MySchema())
+ parser.readfp(config)
+
+ self.assertEqual(parser.values(), {'__main__': {'foo': ['a', 'b']}})
+
+
class TestTupleConfigOption(unittest.TestCase):
def test_init(self):
opt = TupleConfigOption(2)