Commit 2cbe6a3f authored by Nicolas Delaby's avatar Nicolas Delaby

Enable parser option to remove Whitespace between nodes that do not contain data

It's usefull to have pretty_print working when serialize


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25285 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 09991337
......@@ -41,6 +41,7 @@ from xml.sax.saxutils import escape, unescape
import re
import cStringIO
from lxml import etree
parser = etree.XMLParser(remove_blank_text=True)
from xml.marshal.generic import loads as unmarshaler
from zLOG import LOG, INFO, DEBUG
......@@ -644,7 +645,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
if isinstance(xml, (str, unicode)):
if isinstance(xml, unicode):
xml = xml.encode('utf-8')
xml = etree.XML(xml)
xml = etree.XML(xml, parser=parser)
# If we have the xml from the node erp5, we just take the subnode
if xml.tag == 'erp5':
xml = xml[0]
......@@ -850,7 +851,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
"""
conflict_list = []
if isinstance(xupdate, (str, unicode)):
xupdate = etree.XML(xupdate)
xupdate = etree.XML(xupdate, parser=parser)
#When xupdate mix different object, (like object and his subobject) we need to treat them separatly
if self.isMixedXupdate(xupdate):
#return to updateNode with only one line
......
......@@ -8,6 +8,7 @@ import socket
import time
from optparse import OptionParser
from lxml import etree
parser = etree.XMLParser(remove_blank_text=True)
class OptionParser(OptionParser):
......@@ -136,7 +137,7 @@ def getClientUrl(text):
"""
find the client url in the text and return it
"""
document = etree.XML(text)
document = etree.XML(text, parser=parser)
client_url = '%s' % document.xpath('string(//SyncHdr/Source/LocURI)')
return client_url
......
......@@ -61,6 +61,7 @@ from DateTime import DateTime
from zLOG import LOG, TRACE, DEBUG, INFO
from lxml import etree
parser = etree.XMLParser(remove_blank_text=True)
class TimeoutHTTPConnection(httplib.HTTPConnection):
"""
......@@ -1034,7 +1035,7 @@ class SynchronizationTool( SubscriptionSynchronization,
if domain.getSyncContentType() == self.CONTENT_TYPE['SYNCML_WBXML']:
text = self.wbxml2xml(text)
#LOG('readResponse, text after wbxml :\n', TRACE, text)
xml = etree.XML(text)
xml = etree.XML(text, parser=parser)
url = self.getTarget(xml)
for publication in self.getPublicationList():
if publication.getPublicationUrl() == url and \
......
......@@ -36,6 +36,8 @@ from zLOG import LOG, INFO
from lxml import etree
from lxml.etree import Element
from lxml.builder import E
parser = etree.XMLParser(remove_blank_text=True)
from xml.dom import minidom
try:
......@@ -340,7 +342,7 @@ class XMLSyncUtilsMixin(SyncCode):
"""
data_node = Element('Data')
if media_type == self.MEDIA_TYPE['TEXT_XML'] and isinstance(xml_string, str):
data_node.append(etree.XML(xml_string))
data_node.append(etree.XML(xml_string, parser=parser))
elif media_type == self.MEDIA_TYPE['TEXT_XML'] and \
not isinstance(xml_string, str):
#xml_string could be Partial element if partial XML
......@@ -396,7 +398,7 @@ class XMLSyncUtilsMixin(SyncCode):
if not isinstance(xml_string, (str, unicode)):
data_node.append(xml_string)
else:
data_node.append(etree.XML(xml_string))
data_node.append(etree.XML(xml_string, parser=parser))
xml = (E.Replace(
E.CmdID('%s' % cmd_id),
E.Meta(
......@@ -672,7 +674,7 @@ class XMLSyncUtilsMixin(SyncCode):
syncml_data = kw.get('syncml_data','')
result = {'finished':1}
if isinstance(remote_xml, (str, unicode)):
remote_xml = etree.XML(remote_xml)
remote_xml = etree.XML(remote_xml, parser=parser)
if domain.isOneWayFromServer():
#Do not set object_path_list, subscriber send nothing
subscriber.setRemainingObjectPathList([])
......@@ -968,7 +970,7 @@ class XMLSyncUtilsMixin(SyncCode):
data_subnode = partial_data
#LOG('applyActionList', DEBUG, 'data_subnode: %s' % data_subnode)
if subscriber.getMediaType() == self.MEDIA_TYPE['TEXT_XML']:
data_subnode = etree.XML(data_subnode)
data_subnode = etree.XML(data_subnode, parser=parser)
else:
if subscriber.getMediaType() != self.MEDIA_TYPE['TEXT_XML']:
data_subnode = self.getDataText(action)
......@@ -1306,7 +1308,7 @@ class XMLSyncUtils(XMLSyncUtilsMixin):
domain.activate(activity='SQLQueue',
tag=domain.getId(),
priority=self.PRIORITY).activateSyncModif(
domain_relative_url = domain.getRelativeUrl(),
domain_relative_url=domain.getRelativeUrl(),
remote_xml=remote_xml,
subscriber_relative_url=subscriber.getRelativeUrl(),
cmd_id=cmd_id,
......@@ -1384,7 +1386,7 @@ class XMLSyncUtils(XMLSyncUtilsMixin):
xml_confirmation = result['xml_confirmation']
cmd_id = result['cmd_id']
cmd_id_before_getsyncmldata = kw['cmd_id_before_getsyncmldata']
remote_xml = etree.XML(kw['remote_xml'])
remote_xml = etree.XML(kw['remote_xml'], parser=parser)
xml_list = kw['xml_list']
has_status_list = kw['has_status_list']
has_response = kw['has_response']
......@@ -1501,7 +1503,7 @@ class XMLSyncUtils(XMLSyncUtilsMixin):
if xml_client is not None:
if isinstance(xml_client, (str, unicode)):
xml_client = etree.XML(xml_client)
xml_client = etree.XML(xml_client, parser=parser)
if xml_client.tag != "SyncML":
LOG('PubSync', INFO, 'This is not a SyncML Message')
raise ValueError, "Sorry, This is not a SyncML Message"
......@@ -1571,7 +1573,7 @@ class XMLSyncUtils(XMLSyncUtilsMixin):
else:
xml_client = msg
if isinstance(xml_client, (str, unicode)):
xml_client = etree.XML(xml_client)
xml_client = etree.XML(xml_client, parser=parser)
status_list = self.getSyncBodyStatusList(xml_client)
if status_list:
status_code_syncHdr = status_list[0]['code']
......@@ -1598,7 +1600,7 @@ class XMLSyncUtils(XMLSyncUtilsMixin):
else:
response = self.SubSyncModif(subscription, xml_client)
else:
response = self.SubSyncModif(subscription, xml_client)
response = self.SubSyncModif(subscription, xml_client)
if RESPONSE is not None:
RESPONSE.redirect('manageSubscriptions')
......
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