mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-24 16:10:02 -06:00
333: Param.convert() now uses name Param.__multivalue() helper method as Param.normalize()
This commit is contained in:
parent
6bedb15674
commit
1125d420bd
@ -105,16 +105,18 @@ class Param(plugable.ReadOnly):
|
||||
self.rules = (type_.validate,) + rules
|
||||
lock(self)
|
||||
|
||||
def __if_multivalue(self, value, scalar):
|
||||
def __multivalue(self, value, scalar):
|
||||
if self.multivalue:
|
||||
if type(value) in (tuple, list):
|
||||
if len(value) == 0:
|
||||
return None
|
||||
return tuple(scalar(v) for v in value)
|
||||
return (scalar(value),) # tuple
|
||||
return tuple(
|
||||
scalar(v, i) for (i, v) in enumerate(value)
|
||||
)
|
||||
return (scalar(value, 0),) # tuple
|
||||
return scalar(value)
|
||||
|
||||
def __normalize_scalar(self, value):
|
||||
def __normalize_scalar(self, value, index=None):
|
||||
if not isinstance(value, basestring):
|
||||
return value
|
||||
try:
|
||||
@ -140,7 +142,7 @@ class Param(plugable.ReadOnly):
|
||||
"""
|
||||
if self.__normalize is None:
|
||||
return value
|
||||
return self.__if_multivalue(value, self.__normalize_scalar)
|
||||
return self.__multivalue(value, self.__normalize_scalar)
|
||||
|
||||
def __convert_scalar(self, value, index=None):
|
||||
if value is None:
|
||||
@ -153,13 +155,7 @@ class Param(plugable.ReadOnly):
|
||||
return converted
|
||||
|
||||
def convert(self, value):
|
||||
if self.multivalue:
|
||||
if type(value) in (tuple, list):
|
||||
return tuple(
|
||||
self.__convert_scalar(v, i) for (i, v) in enumerate(value)
|
||||
)
|
||||
return (self.__convert_scalar(value, 0),) # tuple
|
||||
return self.__convert_scalar(value)
|
||||
return self.__multivalue(value, self.__convert_scalar)
|
||||
|
||||
|
||||
|
||||
|
@ -163,6 +163,7 @@ class test_Param(ClassChecker):
|
||||
|
||||
# Scenario 2: multivalue=True
|
||||
o = self.cls(name, type_, multivalue=True)
|
||||
assert o.convert([]) is None
|
||||
for none in [None, (7, None)]:
|
||||
e = raises(TypeError, o.convert, none)
|
||||
assert str(e) == 'value cannot be None'
|
||||
|
Loading…
Reference in New Issue
Block a user