[elbe-devel] [PATCH] elbexml: add check XML boolean helper
Benedikt Spranger
b.spranger at linutronix.de
Thu Jul 5 09:32:01 CEST 2018
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>
---
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
More information about the elbe-devel
mailing list