summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2013-02-14 11:49:47 -0500
committerMartin Kosek <mkosek@redhat.com>2013-02-22 17:20:35 +0100
commit3a96cbc5184688830edf79e4831f729a1bf7aa44 (patch)
tree7374fd13c7b7fee9bac141a5f36118cc1826fca4
parentb4915bd2fde861279ba18acf940d7a5880a58ba6 (diff)
downloadfreeipa.git-3a96cbc5184688830edf79e4831f729a1bf7aa44.tar.gz
freeipa.git-3a96cbc5184688830edf79e4831f729a1bf7aa44.tar.xz
freeipa.git-3a96cbc5184688830edf79e4831f729a1bf7aa44.zip
Drop support for CSV in the CLI client
Ticket: https://fedorahosted.org/freeipa/ticket/3352 Design: http://freeipa.org/page/V3/Drop_CSV
-rw-r--r--ipalib/cli.py1
-rw-r--r--ipalib/frontend.py20
-rw-r--r--ipalib/parameters.py61
-rw-r--r--tests/test_cmdline/test_cli.py8
-rw-r--r--tests/test_ipalib/test_parameters.py17
5 files changed, 5 insertions, 102 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index f1d2f874..c3926c36 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -1044,7 +1044,6 @@ class cli(backend.Executioner):
kw = self.parse(cmd, argv)
if self.env.interactive:
self.prompt_interactively(cmd, kw)
- kw = cmd.split_csv(**kw)
if self.env.interactive:
try:
callbacks = cmd.get_callbacks('interactive_prompt')
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 06259823..0331dc52 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -560,26 +560,6 @@ 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.
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index 9fed0fd5..a934a8fb 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -102,7 +102,6 @@ a more detailed description for clarity.
import re
import decimal
import base64
-import csv
from xmlrpclib import MAXINT, MININT
from types import NoneType
@@ -355,7 +354,7 @@ class Param(ReadOnly):
parameter is not `required`
- sortorder: used to sort a list of parameters for Command. See
`Command.finalize()` for further information
- - csv: this multivalue attribute is given in CSV format
+ - csv: this multivalue attribute used to be given in CSV format in CLI
"""
# This is a dummy type so that most of the functionality of Param can be
@@ -675,64 +674,6 @@ class Param(ReadOnly):
kw.update(overrides)
return klass(name, *self.rules, **kw)
- # The following 2 functions were taken from the Python
- # documentation at http://docs.python.org/library/csv.html
- def __utf_8_encoder(self, unicode_csv_data):
- for line in unicode_csv_data:
- yield line.encode('utf-8')
-
- def __unicode_csv_reader(self, unicode_csv_data, dialect=csv.excel, **kwargs):
- # csv.py doesn't do Unicode; encode temporarily as UTF-8:
- csv_reader = csv.reader(self.__utf_8_encoder(unicode_csv_data),
- dialect=dialect, delimiter=',', quotechar='"',
- skipinitialspace=True,
- **kwargs)
- try:
- for row in csv_reader:
- # decode UTF-8 back to Unicode, cell by cell:
- yield [unicode(cell, 'utf-8') for cell in row]
- except csv.Error, e:
- raise ValidationError(
- name=self.get_param_name(),
- value=unicode_csv_data,
- error=_("Improperly formatted CSV value (%s)" % e)
- )
-
- def split_csv(self, value):
- """Split CSV strings into individual values.
-
- For CSV params, ``value`` is a tuple of strings. Each of these is split
- on commas, and the results are concatenated into one tuple.
-
- For example::
-
- >>> param = Param('telephones', multivalue=True, csv=True)
- >>> param.split_csv((u'1, 2', u'3', u'4, 5, 6'))
- (u'1', u'2', u'3', u'4', u'5', u'6')
-
- If ``value`` is not a tuple (or list), it is only split::
-
- >>> param = Param('telephones', multivalue=True, csv=True)
- >>> param.split_csv(u'1, 2, 3')
- (u'1', u'2', u'3')
-
- For non-CSV params, return the value unchanged.
- """
- if self.csv:
- if type(value) not in (tuple, list):
- value = (value,)
- newval = []
- for v in value:
- if isinstance(v, basestring):
- lines = unicode(v).splitlines()
- for row in self.__unicode_csv_reader(lines):
- newval.extend(row)
- else:
- newval.append(v)
- return tuple(newval)
- else:
- return value
-
def normalize(self, value):
"""
Normalize ``value`` using normalizer callback.
diff --git a/tests/test_cmdline/test_cli.py b/tests/test_cmdline/test_cli.py
index 4d730d58..388c54e2 100644
--- a/tests/test_cmdline/test_cli.py
+++ b/tests/test_cmdline/test_cli.py
@@ -72,13 +72,13 @@ class TestCLIParsing(object):
version=API_VERSION)
def test_sudocmdgroup_add_member(self):
- # Test CSV splitting is done correctly
+ # Test CSV splitting is not done
self.check_command(
# The following is as it would appear on the command line:
- r'sudocmdgroup-add-member tcmdgroup1 --sudocmds=abc,\"de,f\",\\,g',
+ r'sudocmdgroup-add-member tcmdgroup1 --sudocmds=ab,c --sudocmds=d',
'sudocmdgroup_add_member',
cn=u'tcmdgroup1',
- sudocmd=[u'abc', u'de,f', u'\\', u'g'],
+ sudocmd=[u'ab,c', u'd'],
raw=False,
all=False,
version=API_VERSION)
@@ -122,7 +122,7 @@ class TestCLIParsing(object):
'dnsrecord_add',
dnszoneidnsname=u'test-example.com',
idnsname=u'ns',
- arecord=[u'1.2.3.4'],
+ arecord=u'1.2.3.4',
structured=False,
force=False,
raw=False,
diff --git a/tests/test_ipalib/test_parameters.py b/tests/test_ipalib/test_parameters.py
index 47c5de1f..192db3da 100644
--- a/tests/test_ipalib/test_parameters.py
+++ b/tests/test_ipalib/test_parameters.py
@@ -616,23 +616,6 @@ class test_Param(ClassChecker):
assert o._convert_scalar.value is default
assert o.normalizer.value is default
- def test_split_csv(self):
- """
- Test the `ipalib.parameters.Param.split_csv` method with csv.
- """
- o = self.cls('my_list+', csv=True)
- n = o.split_csv('a,b')
- assert type(n) is tuple
- assert len(n) is 2
-
- n = o.split_csv('bar, "hi, there",foo')
- assert type(n) is tuple
- assert len(n) is 3
-
- e = raises(ValidationError, o.split_csv, '"a')
- assert e.name == 'my_list'
- assert e.error == u'Improperly formatted CSV value (newline inside string)'
-
class test_Flag(ClassChecker):
"""