Commit ac5b7154 authored by Nicolas Delaby's avatar Nicolas Delaby

remove dirty xml handling as string, make code more understandable

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29933 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ba2e30a1
...@@ -43,12 +43,14 @@ import re ...@@ -43,12 +43,14 @@ import re
import cStringIO import cStringIO
import string import string
from lxml import etree from lxml import etree
from lxml.etree import Element
parser = etree.XMLParser(remove_blank_text=True) parser = etree.XMLParser(remove_blank_text=True)
from xml.marshal.generic import loads as unmarshaler from xml.marshal.generic import loads as unmarshaler
from zLOG import LOG, INFO, DEBUG from zLOG import LOG, INFO, DEBUG
from base64 import standard_b64decode from base64 import standard_b64decode
from OFS.Image import Pdata from OFS.Image import Pdata
from zope.interface import implements from zope.interface import implements
from copy import deepcopy
class ERP5Conduit(XMLSyncUtilsMixin): class ERP5Conduit(XMLSyncUtilsMixin):
""" """
...@@ -497,7 +499,6 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -497,7 +499,6 @@ class ERP5Conduit(XMLSyncUtilsMixin):
This will change the xml in order to change the update This will change the xml in order to change the update
from the object to the subobject from the object to the subobject
""" """
from copy import deepcopy
xml_copy = deepcopy(xml) xml_copy = deepcopy(xml)
self.changeSubObjectSelect(xml_copy) self.changeSubObjectSelect(xml_copy)
return xml_copy return xml_copy
...@@ -651,7 +652,6 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -651,7 +652,6 @@ class ERP5Conduit(XMLSyncUtilsMixin):
if isinstance(xml, str): if isinstance(xml, str):
xml = etree.XML(xml, parser=parser) xml = etree.XML(xml, parser=parser)
#copy of xml object for modification #copy of xml object for modification
from copy import deepcopy
xml_copy = deepcopy(xml) xml_copy = deepcopy(xml)
if xml_copy.tag == self.xml_object_tag: if xml_copy.tag == self.xml_object_tag:
object_element = xml_copy object_element = xml_copy
...@@ -795,21 +795,17 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -795,21 +795,17 @@ class ERP5Conduit(XMLSyncUtilsMixin):
from a xupdate:element returns the element as xml from a xupdate:element returns the element as xml
""" """
if xml.xpath('name()') in self.XUPDATE_ELEMENT: if xml.xpath('name()') in self.XUPDATE_ELEMENT:
result = '<' new_node = Element(xml.attrib.get('name'), nsmap=xml.nsmap)
tag_name = xml.attrib.get('name')
result += tag_name
for subnode in xml: for subnode in xml:
if subnode.xpath('name()') == 'xupdate:attribute': if subnode.xpath('name()') == 'xupdate:attribute':
result += ' %s=' % subnode.attrib.get('name') new_node.attrib.update({subnode.attrib.get('name'): subnode.text})
result += '"%s"' % subnode.text
result += '>'
# Then dumps the xml and remove what we does'nt want # Then dumps the xml and remove what we does'nt want
xml_string = self.nodeToString(xml) new_node.extend(deepcopy(child) for child in xml.xpath('*[namespace-uri(.) != "http://www.xmldb.org/xupdate"]'))
maxi = max(xml_string.find('>') + 1, \ #Strange behaviour of lxml, xml.text return nothing when xml.text is CDATA
xml_string.rfind('</xupdate:attribute>')+len('</xupdate:attribute>')) #new_node.text = xml.text
result += xml_string[maxi:xml_string.find('</xupdate:element>')] new_node.text = xml.xpath('string(text())')
result += '</%s>' % tag_name new_node.tail = xml.tail
return self.convertToXml(result) return new_node
if xml.xpath('name()') in (self.XUPDATE_UPDATE + self.XUPDATE_DEL): if xml.xpath('name()') in (self.XUPDATE_UPDATE + self.XUPDATE_DEL):
result = u'<' result = u'<'
attribute = xml.attrib.get('select') attribute = xml.attrib.get('select')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment