Do not crash on empty --setattr, --getattr, --addattr

Also the unused `append` argument from _convert_2_dict.

https://fedorahosted.org/freeipa/ticket/2680
This commit is contained in:
Petr Viktorin
2012-04-27 06:07:16 -04:00
committed by Martin Kosek
parent 0206dbe795
commit abef5e8c02
2 changed files with 10 additions and 9 deletions

View File

@@ -791,18 +791,18 @@ last, after all sets and adds."""),
exclude='webui', exclude='webui',
) )
def _convert_2_dict(self, attrs, append=True): def _convert_2_dict(self, attrs):
""" """
Convert a string in the form of name/value pairs into a dictionary. Convert a string in the form of name/value pairs into a dictionary.
The incoming attribute may be a string or a list.
:param attrs: A list of name/value pairs :param attrs: A list of name/value pair strings, in the "name=value"
format. May also be a single string, or None.
:param append: controls whether this returns a list of values or a single
value.
""" """
newdict = {} newdict = {}
if not type(attrs) in (list, tuple): if attrs is None:
attrs = []
elif not type(attrs) in (list, tuple):
attrs = [attrs] attrs = [attrs]
for a in attrs: for a in attrs:
m = re.match("\s*(.*?)\s*=\s*(.*?)\s*$", a) m = re.match("\s*(.*?)\s*=\s*(.*?)\s*$", a)
@@ -811,7 +811,7 @@ last, after all sets and adds."""),
if len(value) == 0: if len(value) == 0:
# None means "delete this attribute" # None means "delete this attribute"
value = None value = None
if append and attr in newdict: if attr in newdict:
if type(value) in (tuple,): if type(value) in (tuple,):
newdict[attr] += list(value) newdict[attr] += list(value)
else: else:

View File

@@ -39,7 +39,8 @@ class test_attr(Declarative):
dict( dict(
desc='Create %r' % user1, desc='Create %r' % user1,
command=( command=(
'user_add', [user1], dict(givenname=u'Test', sn=u'User1') 'user_add', [user1], dict(givenname=u'Test', sn=u'User1',
setattr=None)
), ),
expected=dict( expected=dict(
value=user1, value=user1,