summaryrefslogtreecommitdiffstats
path: root/ipalib
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 /ipalib
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
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/cli.py1
-rw-r--r--ipalib/frontend.py20
-rw-r--r--ipalib/parameters.py61
3 files changed, 1 insertions, 81 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.