mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
parameters: introduce no_convert keyword argument
When set to true, the argument causes params to not convert unicode values to the param type. This will allow thin client to properly handle params which can be converted from unicode to the param type only on the server, e.g. because of a normalizer. https://fedorahosted.org/freeipa/ticket/4739 Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
parent
98ede1b0e8
commit
0e989e2a28
@ -414,6 +414,7 @@ class Param(ReadOnly):
|
||||
('sortorder', int, 2), # see finalize()
|
||||
('option_group', unicode, None),
|
||||
('cli_metavar', str, None),
|
||||
('no_convert', bool, False),
|
||||
|
||||
# The 'default' kwarg gets appended in Param.__init__():
|
||||
# ('default', self.type, None),
|
||||
@ -808,18 +809,26 @@ class Param(ReadOnly):
|
||||
|
||||
:param value: A proposed value for this parameter.
|
||||
"""
|
||||
if not self.no_convert:
|
||||
convert = self._convert_scalar
|
||||
else:
|
||||
def convert(value):
|
||||
if isinstance(value, unicode):
|
||||
return value
|
||||
return self._convert_scalar(value)
|
||||
|
||||
if _is_null(value):
|
||||
return
|
||||
if self.multivalue:
|
||||
if type(value) not in (tuple, list):
|
||||
value = (value,)
|
||||
values = tuple(
|
||||
self._convert_scalar(v) for v in value if not _is_null(v)
|
||||
convert(v) for v in value if not _is_null(v)
|
||||
)
|
||||
if len(values) == 0:
|
||||
return
|
||||
return values
|
||||
return self._convert_scalar(value)
|
||||
return convert(value)
|
||||
|
||||
def _convert_scalar(self, value, index=None):
|
||||
"""
|
||||
|
@ -152,6 +152,7 @@ ipa_class_members = {
|
||||
'alwaysask',
|
||||
'sortorder',
|
||||
'option_group',
|
||||
'no_convert',
|
||||
],
|
||||
'ipalib.parameters.Bool': [
|
||||
'truths',
|
||||
|
Loading…
Reference in New Issue
Block a user