commit a784fea75d133073ff4e0fc9e8e5ecee127c9c06 Author: Radek Pazdera rpazdera@redhat.com Date: Thu Sep 19 15:15:31 2013 +0200
schema: Fixing address and alias bugs
The scheme cover situations when we omit the value of the address tag and replace it with text instead:
<address value="1.2.3.4/32"/> <address>1.2.3.4/32</address>
The same problem occured with defining aliases. This patch fixes those issues.
Signed-off-by: Radek Pazdera rpazdera@redhat.com Signed-off-by: Jiri Pirko jiri@resnulli.us
lnst/Common/XmlParser.py | 5 +++-- lnst/Common/XmlTemplates.py | 8 ++++++-- schema-recipe.rng | 12 ++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) --- diff --git a/lnst/Common/XmlParser.py b/lnst/Common/XmlParser.py index e50a2f2..51f7273 100644 --- a/lnst/Common/XmlParser.py +++ b/lnst/Common/XmlParser.py @@ -109,10 +109,11 @@ class XmlParser(object): return attr in element.attrib
def _get_attribute(self, element, attr): - return self._template_proc.expand_functions(element.attrib[attr]) + text = element.attrib[attr].strip() + return self._template_proc.expand_functions(text)
def _get_content(self, element): - text = etree.tostring(element, method="text") + text = etree.tostring(element, method="text").strip() return self._template_proc.expand_functions(text)
def _expand_xinclude(self, elem, base_url=""): diff --git a/lnst/Common/XmlTemplates.py b/lnst/Common/XmlTemplates.py index a2afd05..1d7a9fd 100644 --- a/lnst/Common/XmlTemplates.py +++ b/lnst/Common/XmlTemplates.py @@ -22,6 +22,7 @@ rpazdera@redhat.com (Radek Pazdera) """
import re +from lxml import etree from lnst.Common.XmlProcessing import XmlTemplateString
class XmlTemplateError(Exception): @@ -319,8 +320,11 @@ class XmlTemplates:
if element.tag == "define": for alias in element.getchildren(): - name = alias.attrib["name"] - value = alias.attrib["value"] + name = alias.attrib["name"].strip() + if "value" in alias.attrib: + value = alias.attrib["value"].strip() + else: + value = etree.tostring(element, method="text").strip() self.define_alias(name, value) parent = element.getparent() parent.remove(element) diff --git a/schema-recipe.rng b/schema-recipe.rng index 7e417cb..34ab1fd 100644 --- a/schema-recipe.rng +++ b/schema-recipe.rng @@ -21,8 +21,10 @@ <oneOrMore> <element name="alias"> <attribute name="name"/> - <attribute name="value"/> - <text/> + <choice> + <attribute name="value"/> + <text/> + </choice> </element> </oneOrMore> </element> @@ -248,8 +250,10 @@
<zeroOrMore> <element name="address"> - <attribute name="value"/> - <text/> + <choice> + <attribute name="value"/> + <text/> + </choice> </element> </zeroOrMore> </interleave>
lnst-developers@lists.fedorahosted.org