From dddebe23507749486fb09d219f0da4f483ba4e79 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Thu, 23 Feb 2012 07:29:47 -0500 Subject: Only split CSV in the client, quote instead of escaping Splitting on commas is not an idempotent operation: 'a,b\,c' -> ('a', 'b,c') -> ('a', 'b', 'c') That means we can't do it when the call is forwarded, so this is only done on the CLI. The UI already sends values as a tuple. Replace escaping in the csv parser with quoting. Quoted strings can have embedded commas instead of having to escape them. This prevents the csv parser from eating all escape characters. Also, document Param's csv arguments, and update tests. https://fedorahosted.org/freeipa/ticket/2417 https://fedorahosted.org/freeipa/ticket/2227 --- ipalib/frontend.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'ipalib/frontend.py') diff --git a/ipalib/frontend.py b/ipalib/frontend.py index da25b4c1a..47c72d1ab 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -557,6 +557,26 @@ class Command(HasParam): if name in params: yield(name, params[name]) + def split_csv(self, **kw): + """ + Return a dictionary of values where values are decoded from CSV. + + For example: + + >>> class my_command(Command): + ... takes_options = ( + ... Param('flags', multivalue=True, csv=True), + ... ) + ... + >>> c = my_command() + >>> c.finalize() + >>> c.split_csv(flags=u'public,replicated') + {'flags': (u'public', u'replicated')} + """ + return dict( + (k, self.params[k].split_csv(v)) for (k, v) in kw.iteritems() + ) + def normalize(self, **kw): """ Return a dictionary of normalized values. -- cgit