[elbe-devel] [PATCH] elbexml: add check XML boolean helper

Manuel Traut manut at linutronix.de
Thu Jul 5 09:37:43 CEST 2018


Hi Bene,

On Thu, Jul 05, 2018 at 09:32:01AM +0200, Benedikt Spranger wrote:
> XML boolean attributes are specified as case sensitiv "true" or "1" for
> a true and "false" or "0" for a false value. Other values are not
> allowed and are rejected by validation. Non stated attributes defaults to
> false.
> 
> elbexml (or better the underlaying lxml) refer None for non existing
> attributes. Add a helper to check XML boolean values.
> 
> Signed-off-by: Benedikt Spranger <b.spranger at linutronix.de>
> Reviewed-by: Manuel Traut <manut at linutronix.de>

thanks, i picked it up for devel/elbe-3.0

> ---
>  elbepack/treeutils.py | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/elbepack/treeutils.py b/elbepack/treeutils.py
> index 6a2b5ac9..9cdf2f32 100644
> --- a/elbepack/treeutils.py
> +++ b/elbepack/treeutils.py
> @@ -140,6 +140,15 @@ class etree(ebase):
>          self.et._setroot(retval.et)
>          return retval
>  
> +    def check_boolean(self, node, attributename):
> +        attr = node.get(attributename)
> +        if attr is None:
> +            return False
> +        elif attr in ['true', '1']:
> +            return True
> +        elif attr in ['false', '0']:
> +            return False
> +
>      @property
>      def root(self):
>          return elem(self.et.getroot())
> -- 
> 2.18.0
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel



More information about the elbe-devel mailing list