Commit 9f6a786b authored by Sebastien Robin's avatar Sebastien Robin

use faster xml libraries


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@868 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b4fe14b3
...@@ -34,6 +34,7 @@ from Products.ERP5SyncML.XupdateUtils import XupdateUtils ...@@ -34,6 +34,7 @@ from Products.ERP5SyncML.XupdateUtils import XupdateUtils
from Products.ERP5Type.Utils import convertToUpperCase from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type.Accessor.TypeDefinition import list_types from Products.ERP5Type.Accessor.TypeDefinition import list_types
from xml.dom.ext.reader.Sax2 import FromXml from xml.dom.ext.reader.Sax2 import FromXml
from xml.dom.minidom import parse, parseString
from DateTime.DateTime import DateTime from DateTime.DateTime import DateTime
from email.MIMEBase import MIMEBase from email.MIMEBase import MIMEBase
from email import Encoders from email import Encoders
...@@ -127,6 +128,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -127,6 +128,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
LOG('addNode',0,'xml.nodeName: %s' % xml.nodeName) LOG('addNode',0,'xml.nodeName: %s' % xml.nodeName)
LOG('addNode',0,'getSubObjectDepth: %i' % self.getSubObjectDepth(xml)) LOG('addNode',0,'getSubObjectDepth: %i' % self.getSubObjectDepth(xml))
LOG('addNode',0,'isHistoryAdd: %i' % self.isHistoryAdd(xml)) LOG('addNode',0,'isHistoryAdd: %i' % self.isHistoryAdd(xml))
LOG('addNode xml',0,repr(xml.toxml()))
if xml.nodeName in self.XUPDATE_INSERT_OR_ADD and self.getSubObjectDepth(xml)==0: if xml.nodeName in self.XUPDATE_INSERT_OR_ADD and self.getSubObjectDepth(xml)==0:
if self.isHistoryAdd(xml)!=-1: # bad hack XXX to be removed if self.isHistoryAdd(xml)!=-1: # bad hack XXX to be removed
for element in self.getXupdateElementList(xml): for element in self.getXupdateElementList(xml):
...@@ -200,11 +202,15 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -200,11 +202,15 @@ class ERP5Conduit(XMLSyncUtilsMixin):
previous_xml=sub_previous_xml, force=force, previous_xml=sub_previous_xml, force=force,
simulate=simulate, **kw) simulate=simulate, **kw)
elif xml.nodeName == self.history_tag or self.isHistoryAdd(xml)>0: elif xml.nodeName == self.history_tag or self.isHistoryAdd(xml)>0:
LOG('addNode, workflow_history isHistoryAdd:',0,self.isHistoryAdd(xml))
# We want to add a workflow action # We want to add a workflow action
wf_tool = getToolByName(object,'portal_workflow') wf_tool = getToolByName(object,'portal_workflow')
wf_id = self.getAttribute(xml,'id') wf_id = self.getAttribute(xml,'id')
if wf_id is None: # History added by xupdate if wf_id is None: # History added by xupdate
wf_id = self.getHistoryIdFromSelect(xml) wf_id = self.getHistoryIdFromSelect(xml)
LOG('addNode, workflow_history id:',0,wf_id)
LOG('addNode, workflow_history xml:',0,xml.toxml())
LOG('addNode, workflow_history xml.getElmentNodeList:',0,self.getElementNodeList(xml))
xml = self.getElementNodeList(xml)[0] xml = self.getElementNodeList(xml)[0]
LOG('addNode, workflow_history id:',0,wf_id) LOG('addNode, workflow_history id:',0,wf_id)
LOG('addNode, workflow_history xml:',0,xml) LOG('addNode, workflow_history xml:',0,xml)
...@@ -221,7 +227,8 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -221,7 +227,8 @@ class ERP5Conduit(XMLSyncUtilsMixin):
wf_tool.setStatusOf(wf_id,object,status) wf_tool.setStatusOf(wf_id,object,status)
#else: #else:
# conflict_list += wf_conflict_list # conflict_list += wf_conflict_list
elif xml.nodeName in self.local_role_list and not simulate: #elif xml.nodeName in self.local_role_list or self.isLocalRole(xml)>0 and not simulate:
elif xml.nodeName in self.local_role_list:
# We want to add a local role # We want to add a local role
roles = self.convertXmlValue(xml.childNodes[0].data,data_type='tokens') roles = self.convertXmlValue(xml.childNodes[0].data,data_type='tokens')
user = self.getAttribute(xml,'id') user = self.getAttribute(xml,'id')
...@@ -305,9 +312,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -305,9 +312,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
LOG('updateNode, force: ',0,force) LOG('updateNode, force: ',0,force)
# we have an xupdate xml # we have an xupdate xml
if xml.nodeName == 'xupdate:modifications': if xml.nodeName == 'xupdate:modifications':
#xupdate_utils = XupdateUtils() conflict_list += self.applyXupdate(object=object,xupdate=xml,conduit=self,
xupdate_utils = self
conflict_list += xupdate_utils.applyXupdate(object=object,xupdate=xml,conduit=self,
previous_xml=previous_xml, force=force, simulate=simulate, previous_xml=previous_xml, force=force, simulate=simulate,
**kw) **kw)
# we may have only the part of an xupdate # we may have only the part of an xupdate
...@@ -501,7 +506,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -501,7 +506,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
security.declareProtected(Permissions.AccessContentsInformation,'isHistoryAdd') security.declareProtected(Permissions.AccessContentsInformation,'isHistoryAdd')
def isHistoryAdd(self, xml): def isHistoryAdd(self, xml):
bad_list = (self.history_exp) bad_list = (self.history_exp,)
for subnode in self.getAttributeNodeList(xml): for subnode in self.getAttributeNodeList(xml):
if subnode.nodeName=='select': if subnode.nodeName=='select':
value = subnode.nodeValue value = subnode.nodeValue
...@@ -668,8 +673,12 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -668,8 +673,12 @@ class ERP5Conduit(XMLSyncUtilsMixin):
if xml is a string, convert it to a node if xml is a string, convert it to a node
""" """
if type(xml) in (type('a'),type(u'a')): if type(xml) in (type('a'),type(u'a')):
xml = FromXml(xml) LOG('Conduit.convertToXml xml',0,repr(xml))
xml = xml.childNodes[1] # Because we just created a new xml if xml is type(u'a'):
xml = xml.encode('utf-8')
xml = parseString(xml)
LOG('Conduit.convertToXml not failed',0,'ok')
xml = xml.childNodes[0] # Because we just created a new xml
# If we have the xml from the node erp5, we just take the subnode # If we have the xml from the node erp5, we just take the subnode
if xml.nodeName=='erp5': if xml.nodeName=='erp5':
xml = self.getElementNodeList(xml)[0] xml = self.getElementNodeList(xml)[0]
...@@ -693,7 +702,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -693,7 +702,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
""" """
Retrieve the portal type from an xml Retrieve the portal type from an xml
""" """
p_type = None p_type = None # use getElementsByTagName !!!! XXX
for subnode in self.getAttributeNodeList(xml): for subnode in self.getAttributeNodeList(xml):
if subnode.nodeName=='type': if subnode.nodeName=='type':
p_type = subnode.nodeValue p_type = subnode.nodeValue
...@@ -801,23 +810,27 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -801,23 +810,27 @@ class ERP5Conduit(XMLSyncUtilsMixin):
from a xupdate:element returns the element as xml from a xupdate:element returns the element as xml
""" """
if xml.nodeName in self.XUPDATE_EL: if xml.nodeName in self.XUPDATE_EL:
result = u'<' result = unicode('<',encoding='utf-8')
result += xml.attributes[0].nodeValue result += xml.attributes.values()[0].nodeValue
for subnode in self.getElementNodeList(xml): #getElementNodeList for subnode in self.getElementNodeList(xml): #getElementNodeList
if subnode.nodeName == 'xupdate:attribute': if subnode.nodeName == 'xupdate:attribute':
result += ' ' + subnode.attributes[0].nodeValue + '=' result += ' ' + subnode.attributes.values()[0].nodeValue + '='
result += '"' + subnode.childNodes[0].nodeValue + '"' result += '"' + subnode.childNodes[0].nodeValue + '"'
result += '>' 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 = StringIO() #xml_string = StringIO()
PrettyPrint(xml,xml_string) #PrettyPrint(xml,xml_string)
xml_string = xml_string.getvalue() #xml_string = xml_string.getvalue()
#xml_string = unicode(xml_string,encoding='utf-8')
xml_string = xml.toxml(encoding='utf-8')
xml_string = unicode(xml_string,encoding='utf-8') xml_string = unicode(xml_string,encoding='utf-8')
#if type(xml_string) is type (u'a'):
# xml_string = xml_string.encode('utf-8')
maxi = max(xml_string.find('>')+1,\ maxi = max(xml_string.find('>')+1,\
xml_string.rfind('</xupdate:attribute>')+len('</xupdate:attribute>')) xml_string.rfind('</xupdate:attribute>')+len('</xupdate:attribute>'))
result += xml_string[maxi:xml_string.find('</xupdate:element>')] result += xml_string[maxi:xml_string.find('</xupdate:element>')]
result += '</' + xml.attributes[0].nodeValue + '>' result += '</' + xml.attributes.values()[0].nodeValue + '>'
return self.convertToXml(result) return self.convertToXml(result.encode('utf-8'))
if xml.nodeName in (self.XUPDATE_UPDATE+self.XUPDATE_DEL): if xml.nodeName in (self.XUPDATE_UPDATE+self.XUPDATE_DEL):
result = u'<' result = u'<'
for subnode in self.getAttributeNodeList(xml): for subnode in self.getAttributeNodeList(xml):
...@@ -839,9 +852,11 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -839,9 +852,11 @@ class ERP5Conduit(XMLSyncUtilsMixin):
result += ' id=%s' % select_id result += ' id=%s' % select_id
result += '>' 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 = StringIO() #xml_string = StringIO()
PrettyPrint(xml,xml_string) #PrettyPrint(xml,xml_string)
xml_string = xml_string.getvalue() #xml_string = xml_string.getvalue()
#xml_string = unicode(xml_string,encoding='utf-8')
xml_string = xml.toxml(encoding='utf-8')
xml_string = unicode(xml_string,encoding='utf-8') xml_string = unicode(xml_string,encoding='utf-8')
maxi = xml_string.find('>')+1 maxi = xml_string.find('>')+1
result += xml_string[maxi:xml_string.find('</%s>' % xml.nodeName)] result += xml_string[maxi:xml_string.find('</%s>' % xml.nodeName)]
...@@ -926,7 +941,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -926,7 +941,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
""" """
conflict_list = [] conflict_list = []
if type(xupdate) in (type('a'),type(u'a')): if type(xupdate) in (type('a'),type(u'a')):
xupdate = FromXml(xupdate) xupdate = parseString(xupdate)
for subnode in self.getElementNodeList(xupdate): for subnode in self.getElementNodeList(xupdate):
sub_xupdate = self.getSubObjectXupdate(subnode) sub_xupdate = self.getSubObjectXupdate(subnode)
......
...@@ -30,6 +30,7 @@ import smtplib # to send emails ...@@ -30,6 +30,7 @@ import smtplib # to send emails
from Publication import Publication,Subscriber from Publication import Publication,Subscriber
from Subscription import Signature from Subscription import Signature
from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml
from xml.dom.minidom import parse, parseString
from XMLSyncUtils import XMLSyncUtils from XMLSyncUtils import XMLSyncUtils
from Conduit.ERP5Conduit import ERP5Conduit from Conduit.ERP5Conduit import ERP5Conduit
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
...@@ -118,8 +119,8 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -118,8 +119,8 @@ class PublicationSynchronization(XMLSyncUtils):
if xml_client is not None: if xml_client is not None:
if type(xml_client) in (type('a'),type(u'a')): if type(xml_client) in (type('a'),type(u'a')):
xml_client = FromXml(xml_client) xml_client = parseString(xml_client)
first_node = xml_client.childNodes[1] first_node = xml_client.childNodes[0]
if first_node.nodeName != "SyncML": if first_node.nodeName != "SyncML":
LOG('PubSync',0,'This is not a SyncML Message') LOG('PubSync',0,'This is not a SyncML Message')
......
...@@ -253,6 +253,7 @@ class Signature(SyncCode): ...@@ -253,6 +253,7 @@ class Signature(SyncCode):
self.setXML(self.getTempXML()) self.setXML(self.getTempXML())
self.setTempXML(None) self.setTempXML(None)
self.setSubscriberXupdate(None) self.setSubscriberXupdate(None)
self.setPublisherXupdate(None)
if len(self.getConflictList())>0: if len(self.getConflictList())>0:
self.resetConflictList() self.resetConflictList()
elif status in (self.PUB_CONFLICT_MERGE,self.SENT): elif status in (self.PUB_CONFLICT_MERGE,self.SENT):
...@@ -690,7 +691,6 @@ class Subscription(SyncCode, Implicit): ...@@ -690,7 +691,6 @@ class Subscription(SyncCode, Implicit):
to the query to the query
""" """
destination = self.getDestination() destination = self.getDestination()
LOG('getObjectList',0,'this is a log')
query = self.getQuery() query = self.getQuery()
query_list = [] query_list = []
if type(query) is type('a'): if type(query) is type('a'):
...@@ -699,9 +699,11 @@ class Subscription(SyncCode, Implicit): ...@@ -699,9 +699,11 @@ class Subscription(SyncCode, Implicit):
query_list = query_method() query_list = query_method()
if callable(query): if callable(query):
query_list = query(destination) query_list = query(destination)
return filter(lambda x: x.id.find('conflict_copy')<0,query_list)
# if query is not None: # if query is not None:
# query_list = query() # query_list = query()
return query_list # return query_list
def generateNewId(self, object=None,gid=None): def generateNewId(self, object=None,gid=None):
""" """
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
import smtplib # to send emails import smtplib # to send emails
from Subscription import Subscription,Signature from Subscription import Subscription,Signature
from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml
from xml.dom.minidom import parse, parseString
from xml.dom.ext import PrettyPrint from xml.dom.ext import PrettyPrint
from XMLSyncUtils import XMLSyncUtils from XMLSyncUtils import XMLSyncUtils
import commands import commands
...@@ -95,7 +96,7 @@ class SubscriptionSynchronization(XMLSyncUtils): ...@@ -95,7 +96,7 @@ class SubscriptionSynchronization(XMLSyncUtils):
else: else:
xml_client = msg xml_client = msg
if type(xml_client) in (type('a'),type(u'a')): if type(xml_client) in (type('a'),type(u'a')):
xml_client = FromXml(xml_client) xml_client = parseString(xml_client)
response = self.SubSyncModif(self.getSubscription(id),xml_client) response = self.SubSyncModif(self.getSubscription(id),xml_client)
......
...@@ -98,4 +98,10 @@ class SyncCode(Persistent): ...@@ -98,4 +98,10 @@ class SyncCode(Persistent):
object_exp = "/object\[@id='.*'\]" object_exp = "/object\[@id='.*'\]"
sub_sub_object_exp = "/object\[@id='.*'\]/object\[@id='.*'\]/" sub_sub_object_exp = "/object\[@id='.*'\]/object\[@id='.*'\]/"
history_exp = "/%s\[@id='.*'\]" % history_tag history_exp = "/%s\[@id='.*'\]" % history_tag
local_role_exp = "/%s\[@id='.*'\]" % local_role_tag
local_group_exp = "/%s\[@id='.*'\]" % local_group_tag
bad_local_role_exp = "/%s\[@id='.*'\]/" % local_role_tag
bad_local_group_exp = "/%s\[@id='.*'\]/" % local_group_tag
bad_history_exp = "/%s\[@id='.*'\]/" % history_tag bad_history_exp = "/%s\[@id='.*'\]/" % history_tag
local_role_and_group_list = (local_group_exp,local_role_exp)
bad_local_role_and_group_list = (bad_local_group_exp,bad_local_role_exp)
...@@ -38,6 +38,7 @@ from Products.ERP5SyncML import _dtmldir ...@@ -38,6 +38,7 @@ from Products.ERP5SyncML import _dtmldir
from Publication import Publication,Subscriber from Publication import Publication,Subscriber
from Subscription import Subscription,Signature from Subscription import Subscription,Signature
from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml
from xml.dom.minidom import parse, parseString
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from PublicationSynchronization import PublicationSynchronization from PublicationSynchronization import PublicationSynchronization
from SubscriptionSynchronization import SubscriptionSynchronization from SubscriptionSynchronization import SubscriptionSynchronization
...@@ -744,7 +745,7 @@ class SynchronizationTool( UniqueObject, SimpleItem, ...@@ -744,7 +745,7 @@ class SynchronizationTool( UniqueObject, SimpleItem,
commands.getstatusoutput('rm -f /tmp/%s.gz.gpg' % filename) commands.getstatusoutput('rm -f /tmp/%s.gz.gpg' % filename)
# Get the target and then find the corresponding publication or # Get the target and then find the corresponding publication or
# Subscription # Subscription
xml = FromXml(text) xml = parseString(text)
url = '' url = ''
for subnode in self.getElementNodeList(xml): for subnode in self.getElementNodeList(xml):
if subnode.nodeName == 'SyncML': if subnode.nodeName == 'SyncML':
......
...@@ -30,6 +30,7 @@ import smtplib ...@@ -30,6 +30,7 @@ import smtplib
from Products.ERP5SyncML.SyncCode import SyncCode from Products.ERP5SyncML.SyncCode import SyncCode
from Products.ERP5SyncML.Subscription import Signature from Products.ERP5SyncML.Subscription import Signature
from xml.dom.ext.reader.Sax2 import FromXml from xml.dom.ext.reader.Sax2 import FromXml
from xml.dom.minidom import parse, parseString
from cStringIO import StringIO from cStringIO import StringIO
from xml.dom.ext import PrettyPrint from xml.dom.ext import PrettyPrint
import random import random
...@@ -128,7 +129,6 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): ...@@ -128,7 +129,6 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
msg = header + msg msg = header + msg
LOG('SubSendMail',0,'from: %s, to: %s' % (fromaddr,toaddr)) LOG('SubSendMail',0,'from: %s, to: %s' % (fromaddr,toaddr))
server = smtplib.SMTP('localhost') server = smtplib.SMTP('localhost')
#server.set_debuglevel(1)
server.sendmail(fromaddr, toaddr, msg) server.sendmail(fromaddr, toaddr, msg)
# if we want to send the email to someone else (debugging) # if we want to send the email to someone else (debugging)
#server.sendmail(fromaddr, "seb@localhost", msg) #server.sendmail(fromaddr, "seb@localhost", msg)
...@@ -161,12 +161,9 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): ...@@ -161,12 +161,9 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
xml = "" xml = ""
xml += ' <Delete>\n' xml += ' <Delete>\n'
xml += ' <CmdID>%s</CmdID>\n' % cmd_id xml += ' <CmdID>%s</CmdID>\n' % cmd_id
#xml += ' <Meta><Type>%s</Type></Meta>\n' % object.portal_type
xml += ' <Item>\n' xml += ' <Item>\n'
xml += ' <Source><LocURI>%s</LocURI></Source>\n' % object_gid xml += ' <Source><LocURI>%s</LocURI></Source>\n' % object_gid
xml += ' <Data>\n' xml += ' <Data>\n'
#xml += xml_object # We have to send the data, because it allows to
# wich object to delete (it could be clever things
xml += ' </Data>\n' xml += ' </Data>\n'
xml += ' </Item>\n' xml += ' </Item>\n'
xml += ' </Delete>\n' xml += ' </Delete>\n'
...@@ -233,14 +230,10 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): ...@@ -233,14 +230,10 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
Return the value of the last anchor, in the Return the value of the last anchor, in the
alert section of the xml_stream alert section of the xml_stream
""" """
first_node = xml_stream.childNodes[1] first_node = xml_stream.childNodes[0]
#if first_node.nodeName != "SyncML":
# print "This is not a SyncML message"
# Get informations from the body # Get informations from the body
client_body = first_node.childNodes[3] client_body = first_node.childNodes[3]
#if client_body.nodeName != "SyncBody":
# print "This is not a SyncML Body"
for subnode in client_body.childNodes: for subnode in client_body.childNodes:
if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == "Alert": if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == "Alert":
for subnode2 in subnode.childNodes: for subnode2 in subnode.childNodes:
...@@ -260,7 +253,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): ...@@ -260,7 +253,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
Return the value of the next anchor, in the Return the value of the next anchor, in the
alert section of the xml_stream alert section of the xml_stream
""" """
first_node = xml_stream.childNodes[1] first_node = xml_stream.childNodes[0]
if first_node.nodeName != "SyncML": if first_node.nodeName != "SyncML":
print "This is not a SyncML message" print "This is not a SyncML message"
...@@ -320,7 +313,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): ...@@ -320,7 +313,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
Return the value of the alert code inside the full syncml message Return the value of the alert code inside the full syncml message
""" """
# Get informations from the body # Get informations from the body
first_node = xml_stream.childNodes[1] first_node = xml_stream.childNodes[0]
client_body = first_node.childNodes[3] client_body = first_node.childNodes[3]
if client_body.nodeName != "SyncBody": if client_body.nodeName != "SyncBody":
LOG('XMLSyncUtils.getAlertCode',0,"This is not a SyncML Body") LOG('XMLSyncUtils.getAlertCode',0,"This is not a SyncML Body")
...@@ -336,7 +329,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): ...@@ -336,7 +329,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
""" """
Check if there's an Alert section in the xml_xtream Check if there's an Alert section in the xml_xtream
""" """
first_node = xml_stream.childNodes[1] first_node = xml_stream.childNodes[0]
client_body = first_node.childNodes[3] client_body = first_node.childNodes[3]
if client_body.nodeName != "SyncBody": if client_body.nodeName != "SyncBody":
print "This is not a SyncML Body" print "This is not a SyncML Body"
...@@ -350,7 +343,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): ...@@ -350,7 +343,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
""" """
Check if there's an Sync section in the xml_xtream Check if there's an Sync section in the xml_xtream
""" """
first_node = xml_stream.childNodes[1] first_node = xml_stream.childNodes[0]
client_body = first_node.childNodes[3] client_body = first_node.childNodes[3]
if client_body.nodeName != "SyncBody": if client_body.nodeName != "SyncBody":
LOG('checkSync',0,"This is not a SyncML Body") LOG('checkSync',0,"This is not a SyncML Body")
...@@ -363,7 +356,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): ...@@ -363,7 +356,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
""" """
Check if there's a Status section in the xml_xtream Check if there's a Status section in the xml_xtream
""" """
first_node = xml_stream.childNodes[1] first_node = xml_stream.childNodes[0]
client_body = first_node.childNodes[3] client_body = first_node.childNodes[3]
if client_body.nodeName != "SyncBody": if client_body.nodeName != "SyncBody":
print "This is not a SyncML Body" print "This is not a SyncML Body"
...@@ -379,7 +372,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): ...@@ -379,7 +372,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
then it returns the next action (could be "add", "replace", then it returns the next action (could be "add", "replace",
"delete"). "delete").
""" """
first_node = xml_stream.childNodes[1] first_node = xml_stream.childNodes[0]
client_body = first_node.childNodes[3] client_body = first_node.childNodes[3]
if client_body.nodeName != "SyncBody": if client_body.nodeName != "SyncBody":
print "This is not a SyncML Body" print "This is not a SyncML Body"
...@@ -407,7 +400,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): ...@@ -407,7 +400,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
then it returns the next action (could be "add", "replace", then it returns the next action (could be "add", "replace",
"delete"). "delete").
""" """
first_node = xml_stream.childNodes[1] first_node = xml_stream.childNodes[0]
client_body = first_node.childNodes[3] client_body = first_node.childNodes[3]
if client_body.nodeName != "SyncBody": if client_body.nodeName != "SyncBody":
LOG('getNextSyncBodyStatus',0,"This is not a SyncML Body") LOG('getNextSyncBodyStatus',0,"This is not a SyncML Body")
...@@ -505,6 +498,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): ...@@ -505,6 +498,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
""" """
Return childNodes that are ElementNode Return childNodes that are ElementNode
""" """
#return node.getElementsByTagName('*')
subnode_list = [] subnode_list = []
for subnode in node.childNodes or []: for subnode in node.childNodes or []:
if subnode.nodeType == subnode.ELEMENT_NODE: if subnode.nodeType == subnode.ELEMENT_NODE:
...@@ -526,7 +520,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): ...@@ -526,7 +520,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
Return childNodes that are ElementNode Return childNodes that are ElementNode
""" """
attribute_list = [] attribute_list = []
for subnode in node.attributes or []: for subnode in node.attributes.values() or []:
if subnode.nodeType == subnode.ATTRIBUTE_NODE: if subnode.nodeType == subnode.ATTRIBUTE_NODE:
attribute_list += [subnode] attribute_list += [subnode]
return attribute_list return attribute_list
...@@ -717,7 +711,8 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject): ...@@ -717,7 +711,8 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
if partial_data != None: if partial_data != None:
data_subnode = signature.getPartialXML() + partial_data data_subnode = signature.getPartialXML() + partial_data
LOG('SyncModif',0,'data_subnode: %s' % data_subnode) LOG('SyncModif',0,'data_subnode: %s' % data_subnode)
data_subnode = FromXml(data_subnode) #data_subnode = FromXml(data_subnode)
data_subnode = parseString(data_subnode)
data_subnode = data_subnode.childNodes[1] # Because we just created a new xml data_subnode = data_subnode.childNodes[1] # Because we just created a new xml
# document, with childNodes[0] a DocumentType and childNodes[1] the Element Node # document, with childNodes[0] a DocumentType and childNodes[1] the Element Node
else: else:
...@@ -879,7 +874,7 @@ class XMLSyncUtils(XMLSyncUtilsMixin): ...@@ -879,7 +874,7 @@ class XMLSyncUtils(XMLSyncUtilsMixin):
# Get the destination folder # Get the destination folder
destination_path = self.unrestrictedTraverse(domain.getDestinationPath()) destination_path = self.unrestrictedTraverse(domain.getDestinationPath())
first_node = remote_xml.childNodes[1] first_node = remote_xml.childNodes[0]
# Get informations from the header # Get informations from the header
xml_header = first_node.childNodes[1] xml_header = first_node.childNodes[1]
if xml_header.nodeName != "SyncHdr": if xml_header.nodeName != "SyncHdr":
......
...@@ -404,6 +404,14 @@ class TestERP5SyncML(ERP5TypeTestCase): ...@@ -404,6 +404,14 @@ class TestERP5SyncML(ERP5TypeTestCase):
state_list = portal_sync.getSynchronizationState(person) state_list = portal_sync.getSynchronizationState(person)
for state in state_list: for state in state_list:
self.failUnless(state[1]==state[0].SYNCHRONIZED) self.failUnless(state[1]==state[0].SYNCHRONIZED)
# Check for each signature that the tempXML is None
for sub in portal_sync.getSubscriptionList():
for m in sub.getSignatureList():
self.assertEquals(m.getTempXML(),None)
for pub in portal_sync.getPublicationList():
for sub in pub.getSubscriberList():
for m in sub.getSignatureList():
self.assertEquals(m.getTempXML(),None)
def checkSynchronizationStateIsConflict(self, quiet=0, run=run_all_test): def checkSynchronizationStateIsConflict(self, quiet=0, run=run_all_test):
portal_sync = self.getSynchronizationTool() portal_sync = self.getSynchronizationTool()
...@@ -931,6 +939,7 @@ class TestERP5SyncML(ERP5TypeTestCase): ...@@ -931,6 +939,7 @@ class TestERP5SyncML(ERP5TypeTestCase):
self.failUnless(person1_c1.getFormat()==self.format4) self.failUnless(person1_c1.getFormat()==self.format4)
self.failUnless(person1_c2.getFormat()==self.format4) self.failUnless(person1_c2.getFormat()==self.format4)
def testSynchronizeWorkflowHistory(self, quiet=0, run=run_all_test): def testSynchronizeWorkflowHistory(self, quiet=0, run=run_all_test):
""" """
We will do a synchronization, then we will edit two times We will do a synchronization, then we will edit two times
......
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