[Freeipa-devel] environment in Param(s)
Adam Young
ayoung at redhat.com
Mon Aug 1 14:00:17 UTC 2011
I don't really have the context to ACK it, but it looks a lot better to
me than the previous solution.
On 08/01/2011 09:53 AM, Alexander Bokovoy wrote:
> On 01.08.2011 16:13, Adam Young wrote:
>> OTOH, if the env is something that can change, then we should not
>> require it for the validate call. Is it possible to validate without an
>> env?
> I looked at other exceptions thrown and now pass self.cli_name if it
> exists and self.name otherwise -- this is what other validation checks
> were doing without relying on an environment. If parameter has
> self.cli_name then user would most likely to see it as exception is
> producing an error message and not used for anything else.
>
> diff --git a/ipalib/parameters.py b/ipalib/parameters.py
> index e1c0b09..e26c33e 100644
> --- a/ipalib/parameters.py
> +++ b/ipalib/parameters.py
> @@ -725,10 +725,10 @@ class Param(ReadOnly):
> """
> if value is None:
> if self.required:
> - if context == 'cli':
> - raise RequirementError(name=self.cli_name)
> - else:
> - raise RequirementError(name=self.name)
> + name = self.cli_name
> + if not name:
> + name = self.name
> + raise RequirementError(name=name)
> return
> if self.multivalue:
> if type(value) is not tuple:
> @@ -744,7 +744,10 @@ class Param(ReadOnly):
>
> def _validate_scalar(self, value, index=None):
> if type(value) is not self.type:
> - raise ValidationError(name=self.name,
> + name = self.cli_name
> + if not name:
> + name = self.name
> + raise ValidationError(name=name,
> error='need a %r; got %r (a %r)' % (
> self.type, value, type(value)
> )
> @@ -1672,10 +1675,16 @@ class AccessTime(Str):
> try:
> self._check(value)
> except ValueError, e:
> - raise ValidationError(name=self.cli_name, error=e.args[0])
> + name = self.cli_name
> + if not name:
> + name = self.name
> + raise ValidationError(name=name, error=e.args[0])
> except IndexError:
> + name = self.cli_name
> + if not name:
> + name = self.name
> raise ValidationError(
> - name=self.cli_name, error='incomplete time value'
> + name=name, error='incomplete time value'
> )
> return None
>
>
More information about the Freeipa-devel
mailing list