[Erp5-report] r14482 - in /erp5/trunk/products/ERP5SyncML: ./ Conduit/

nobody at svn.erp5.org nobody at svn.erp5.org
Mon May 14 17:23:08 CEST 2007


Author: seb
Date: Mon May 14 17:23:07 2007
New Revision: 14482

URL: http://svn.erp5.org?rev=14482&view=rev
Log:
revert previous change until we have a nice rpm

Modified:
    erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py
    erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py
    erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py
    erp5/trunk/products/ERP5SyncML/SynchronizationTool.py
    erp5/trunk/products/ERP5SyncML/XMLSyncUtils.py

Modified: erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py?rev=14482&r1=14481&r2=14482&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py (original)
+++ erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py Mon May 14 17:23:07 2007
@@ -33,7 +33,8 @@
 from Products.ERP5SyncML.XupdateUtils import XupdateUtils
 from Products.ERP5Type.Utils import convertToUpperCase
 from Products.ERP5Type.Accessor.TypeDefinition import list_types
-from Ft.Xml import Parse
+from xml.dom.ext.reader.Sax2 import FromXml
+from xml.dom.minidom import parse, parseString
 from DateTime.DateTime import DateTime
 from email.MIMEBase import MIMEBase
 from email import Encoders
@@ -43,12 +44,10 @@
 from Globals import PersistentMapping
 import pickle
 import string
+from xml.dom.ext import PrettyPrint
 from cStringIO import StringIO
 from xml.sax.saxutils import escape, unescape
 import re, copy
-import cStringIO
-from Ft.Xml.Domlette import Print, PrettyPrint
-
 
 
 from zLOG import LOG
@@ -133,8 +132,7 @@
       return {'conflict_list':conflict_list, 'object':sub_object}
     LOG('addNode',0,'xml_reconstitued: %s' % str(xml))
     # In the case where this new node is a object to add
-    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
         for element in self.getXupdateElementList(xml):
           xml = self.getElementFromXupdate(element)
@@ -162,8 +160,7 @@
             portal_type = self.getObjectType(xml)
           elif xml.nodeName in self.XUPDATE_INSERT_OR_ADD: # Deprecated ???
             portal_type = self.getXupdateObjectType(xml) # Deprecated ???
-          sub_object = self.constructContent(object, object_id, docid, 
-              portal_type)
+          sub_object = self.constructContent(object, object_id, docid, portal_type)
         self.newObject(
                   object=sub_object,
                   xml=xml,
@@ -277,9 +274,9 @@
     LOG('updateNode, force: ',0,force)
     # we have an xupdate xml
     if xml.nodeName == 'xupdate:modifications':
-      conflict_list += self.applyXupdate(object=object, xupdate=xml, 
-          conduit=self,previous_xml=previous_xml, force=force, 
-          simulate=simulate, **kw)
+      conflict_list += self.applyXupdate(object=object,xupdate=xml,conduit=self,
+                                 previous_xml=previous_xml, force=force, simulate=simulate,
+                                 **kw)
     # we may have only the part of an xupdate
     else:
       args = {}
@@ -345,8 +342,7 @@
           #   - current_data : the data actually on this box
           isConflict = 0
           if (previous_xml is not None) and (not force): # if no previous_xml, no conflict
-            old_data = self.getObjectProperty(keyword, previous_xml, 
-                data_type=data_type)
+            old_data = self.getObjectProperty(keyword,previous_xml,data_type=data_type)
             #current_data = object.getProperty(keyword)
             current_data = self.getProperty(object, keyword)
             LOG('updateNode',0,'Conflict data: %s' % str(data))
@@ -387,7 +383,8 @@
         if keyword == 'object':
           # This is the case where we have to call addNode
           LOG('updateNode',0,'we will add sub-object')
-          conflict_list += self.addNode(xml=xml, object=object, force=force,                                        simulate=simulate, **kw)['conflict_list']
+          conflict_list += self.addNode(xml=xml,object=object,force=force,
+                                        simulate=simulate, **kw)['conflict_list']
         elif keyword == self.history_tag and not simulate:
           # This is the case where we have to call addNode
           LOG('updateNode',0,'we will add history')
@@ -400,8 +397,8 @@
           #roles = self.convertXmlValue(data,data_type='tokens')
           #object.manage_setLocalRoles(user,roles)
           xml = self.getElementFromXupdate(xml)
-          conflict_list += self.addNode(xml=xml, object=object, force=force, 
-              simulate=simulate,**kw)['conflict_list']
+          conflict_list += self.addNode(xml=xml,object=object,force=force,
+                                        simulate=simulate,**kw)['conflict_list']
       elif self.isSubObjectModification(xml):
         # We should find the object corresponding to
         # this update, so we have to look in the previous_xml
@@ -424,8 +421,8 @@
               sub_xml = self.getSubObjectXupdate(xml)
               LOG('updateNode',0,'sub_xml: %s' % str(sub_xml))
               # Then do the udpate
-              conflict_list += self.updateNode(xml=sub_xml, object=sub_object, force=force, 
-                              previous_xml=sub_previous_xml, simulate=simulate, **kw)
+              conflict_list += self.updateNode(xml=sub_xml,object=sub_object, force=force,
+                              previous_xml=sub_previous_xml,simulate=simulate, **kw)
         elif previous_xml is None and xml is not None and sub_object_id is not None:
           sub_object = None
           try:
@@ -441,8 +438,7 @@
                                              **kw)
     return conflict_list
 
-  security.declareProtected(Permissions.AccessContentsInformation, 
-      'getFormatedArgs')
+  security.declareProtected(Permissions.AccessContentsInformation,'getFormatedArgs')
   def getFormatedArgs(self, args=None):
     """
     This lookd inside the args dictionnary and then
@@ -488,21 +484,19 @@
             return 0
     return 1
 
-  security.declareProtected(Permissions.AccessContentsInformation, 
-      'getSubObjectXupdate')
+  security.declareProtected(Permissions.AccessContentsInformation,'getSubObjectXupdate')
   def getSubObjectXupdate(self, xml):
     """
     This will change the xml in order to change the update
     from the object to the subobject
     """
-    xml_copy = xml.cloneNode(True) #make a deepcopy of the node xml
-    for subnode in self.getAttributeNodeList(xml_copy):
+    xml = copy.deepcopy(xml)
+    for subnode in self.getAttributeNodeList(xml):
       if subnode.nodeName=='select':
         subnode.nodeValue = self.getSubObjectSelect(subnode.nodeValue)
-    return xml_copy
-
-  security.declareProtected(Permissions.AccessContentsInformation, 
-      'isHistoryAdd')
+    return xml
+
+  security.declareProtected(Permissions.AccessContentsInformation,'isHistoryAdd')
   def isHistoryAdd(self, xml):
     bad_list = (self.history_exp,)
     for subnode in self.getAttributeNodeList(xml):
@@ -516,8 +510,7 @@
               return -1
     return 0
 
-  security.declareProtected(Permissions.AccessContentsInformation, 
-      'isSubObjectModification')
+  security.declareProtected(Permissions.AccessContentsInformation,'isSubObjectModification')
   def isSubObjectModification(self, xml):
     """
     Check if it is a modification from an subobject
@@ -531,8 +524,7 @@
             return 1
     return 0
 
-  security.declareProtected(Permissions.AccessContentsInformation, 
-      'getSubObjectDepth')
+  security.declareProtected(Permissions.AccessContentsInformation,'getSubObjectDepth')
   def getSubObjectDepth(self, xml):
     """
     Give the Depth of a subobject modification
@@ -563,8 +555,7 @@
             return (1 - i)
     return 0
 
-  security.declareProtected(Permissions.AccessContentsInformation, 
-      'getSubObjectSelect')
+  security.declareProtected(Permissions.AccessContentsInformation,'getSubObjectSelect')
   def getSubObjectSelect(self, select):
     """
     Return a string wich is the selection for the subobject
@@ -580,8 +571,7 @@
       select = new_value
     return select
 
-  security.declareProtected(Permissions.AccessContentsInformation, 
-      'getSubObjectId')
+  security.declareProtected(Permissions.AccessContentsInformation,'getSubObjectId')
   def getSubObjectId(self, xml):
     """
     Return the id of the subobject in an xupdate modification
@@ -597,8 +587,7 @@
           return object_id
     return object_id
 
-  security.declareProtected(Permissions.AccessContentsInformation, 
-      'getHistoryIdFromSelect')
+  security.declareProtected(Permissions.AccessContentsInformation,'getHistoryIdFromSelect')
   def getHistoryIdFromSelect(self, xml):
     """
     Return the id of the subobject in an xupdate modification
@@ -615,8 +604,7 @@
           return object_id
     return object_id
 
-  security.declareProtected(Permissions.AccessContentsInformation,
-      'getSubObjectXml')
+  security.declareProtected(Permissions.AccessContentsInformation,'getSubObjectXml')
   def getSubObjectXml(self, object_id, xml):
     """
     Return the xml of the subobject which as the id object_id
@@ -636,7 +624,7 @@
     """
     for attribute in self.getAttributeNodeList(xml):
       if attribute.nodeName == param:
-        data = attribute.value
+        data = attribute.childNodes[0].data
         return self.convertXmlValue(data,data_type='string')
     return None
 
@@ -647,7 +635,7 @@
     """
     for subnode in self.getElementNodeList(xml):
       if subnode.nodeName == 'docid':
-        data = subnode.childNodes[0].value
+        data = subnode.childNodes[0].data
         return self.convertXmlValue(data)
     return None
 
@@ -681,7 +669,7 @@
       LOG('Conduit.convertToXml xml',0,repr(xml))
       if type(xml) is type(u'a'):
         xml = xml.encode('utf-8')
-      xml = Parse(xml)
+      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
@@ -823,8 +811,7 @@
       #PrettyPrint(xml,xml_string)
       #xml_string = xml_string.getvalue()
       #xml_string = unicode(xml_string,encoding='utf-8')
-      xml_string = self.nodeToString(xml)
-      #xml_string = xml.toxml(encoding='utf-8')
+      xml_string = xml.toxml(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')
@@ -858,7 +845,7 @@
       #PrettyPrint(xml,xml_string)
       #xml_string = xml_string.getvalue()
       #xml_string = unicode(xml_string,encoding='utf-8')
-      xml_string = self.nodeToString(xml)
+      xml_string = xml.toxml(encoding='utf-8')
       xml_string = unicode(xml_string,encoding='utf-8')
       maxi = xml_string.find('>')+1
       result += xml_string[maxi:xml_string.find('</%s>' % xml.nodeName)]
@@ -942,7 +929,7 @@
     """
     conflict_list = []
     if type(xupdate) in (type('a'),type(u'a')):
-      xupdate = Parse(xupdate)
+      xupdate = parseString(xupdate)
     #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
@@ -980,7 +967,7 @@
     nb_sub = len(subnode_list)
     comp = 0
     for subnode in subnode_list:
-      value = self.getAttribute(subnode, 'select')
+      value = subnode.getAttribute('select')
       if re.search(self.object_exp, value):
         comp += 1
     if nb_sub == comp:
@@ -1056,7 +1043,7 @@
     if wf_id is None: # History added by xupdate
       wf_id = self.getHistoryIdFromSelect(xml)
       LOG('addNode, workflow_history id:',0,wf_id)
-      #LOG('addNode, workflow_history xml:',0,xml.toxml())#toxml isn't in 4Suite
+      LOG('addNode, workflow_history xml:',0,xml.toxml())
       LOG('addNode, workflow_history xml.getElmentNodeList:',0,self.getElementNodeList(xml))
       xml = self.getElementNodeList(xml)[0]
     LOG('addNode, workflow_history id:',0,wf_id)
@@ -1165,13 +1152,3 @@
 #        conflict.setRemoteValue(status)
 #        conflict_list += [conflict]
 #    return conflict_list
-
-  def nodeToString(self, node):
-    """
-    return an xml string corresponding to the node
-    """
-    buf = cStringIO.StringIO()
-    Print(node, stream=buf, encoding='utf-8')
-    xml_string = buf.getvalue()
-    buf.close() 
-    return xml_string

Modified: erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py?rev=14482&r1=14481&r2=14482&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py (original)
+++ erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py Mon May 14 17:23:07 2007
@@ -29,7 +29,8 @@
 import smtplib # to send emails
 from Publication import Publication,Subscriber
 from Subscription import Signature
-from Ft.Xml import Parse
+from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml
+from xml.dom.minidom import parse, parseString
 from XMLSyncUtils import XMLSyncUtils
 from Conduit.ERP5Conduit import ERP5Conduit
 from Products.CMFCore.utils import getToolByName
@@ -220,7 +221,7 @@
 
     if xml_client is not None:
       if isinstance(xml_client, str) or isinstance(xml_client, unicode):
-        xml_client = Parse(xml_client)
+        xml_client = parseString(xml_client)
       first_node = xml_client.childNodes[0]
 
       if first_node.nodeName != "SyncML":

Modified: erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py?rev=14482&r1=14481&r2=14482&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py (original)
+++ erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py Mon May 14 17:23:07 2007
@@ -28,7 +28,9 @@
 
 import smtplib # to send emails
 from Subscription import Subscription,Signature
-from Ft.Xml import Parse
+from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml
+from xml.dom.minidom import parse, parseString
+from xml.dom.ext import PrettyPrint
 from XMLSyncUtils import XMLSyncUtils
 import commands
 from Conduit.ERP5Conduit import ERP5Conduit
@@ -97,7 +99,7 @@
     else:
       xml_client = msg
       if isinstance(xml_client, str) or isinstance(xml_client, unicode):
-        xml_client = Parse(xml_client)
+        xml_client = parseString(xml_client)
         next_status = self.getNextSyncBodyStatus(xml_client, None)
         #LOG('readResponse, next status :',0,next_status)
         if next_status is not None:

Modified: erp5/trunk/products/ERP5SyncML/SynchronizationTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/SynchronizationTool.py?rev=14482&r1=14481&r2=14482&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/SynchronizationTool.py (original)
+++ erp5/trunk/products/ERP5SyncML/SynchronizationTool.py Mon May 14 17:23:07 2007
@@ -40,7 +40,8 @@
 from Publication import Publication,Subscriber
 from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
 from Subscription import Subscription,Signature
-from Ft.Xml import Parse
+from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml
+from xml.dom.minidom import parse, parseString
 from Products.ERP5Type import Permissions
 from PublicationSynchronization import PublicationSynchronization
 from SubscriptionSynchronization import SubscriptionSynchronization
@@ -49,6 +50,7 @@
 from AccessControl.SecurityManagement import noSecurityManager
 from AccessControl.User import UnrestrictedUser
 from Acquisition import aq_base
+from xml.parsers.expat import ExpatError # parseString error
 import urllib
 import urllib2
 import socket
@@ -972,7 +974,7 @@
         commands.getstatusoutput('rm -f /tmp/%s.gz.gpg' % filename)
       # Get the target and then find the corresponding publication or
       # Subscription
-      xml = Parse(text)
+      xml = parseString(text)
       #XXX this function is not very optimized and should be improved
       url = self.getTarget(xml)
       for publication in self.getPublicationList():

Modified: erp5/trunk/products/ERP5SyncML/XMLSyncUtils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/XMLSyncUtils.py?rev=14482&r1=14481&r2=14482&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/XMLSyncUtils.py (original)
+++ erp5/trunk/products/ERP5SyncML/XMLSyncUtils.py Mon May 14 17:23:07 2007
@@ -29,7 +29,8 @@
 import smtplib
 from Products.ERP5SyncML.SyncCode import SyncCode
 from Products.ERP5SyncML.Subscription import Signature
-from Ft.Xml import Parse
+from xml.dom.ext.reader.Sax2 import FromXml
+from xml.dom.minidom import parse, parseString
 from DateTime import DateTime
 from cStringIO import StringIO
 from xml.dom.ext import PrettyPrint
@@ -300,17 +301,28 @@
     We will retrieve the session id of the message
     """
     session_id = 0
-    session_id = xml.xpath('string(/SyncML/SyncHdr/SessionID)')
-    session_id = int(session_id)
+    for subnode in self.getElementNodeList(xml):
+      if subnode.nodeName == 'SyncML':
+        for subnode1 in self.getElementNodeList(subnode):
+          if subnode1.nodeName == 'SyncHdr':
+            for subnode2 in self.getElementNodeList(subnode1):
+              if subnode2.nodeName == 'SessionID':
+                session_id = int(subnode2.childNodes[0].data)
     return session_id
     
+    
   def getMessageId(self, xml):
     """
     We will retrieve the message id of the message
     """
     message_id = 0
-    message_id = xml.xpath('string(/SyncML/SyncHdr/MsgID)')
-    message_id = int(message_id)
+    for subnode in self.getElementNodeList(xml):
+      if subnode.nodeName == 'SyncML':
+        for subnode1 in self.getElementNodeList(subnode):
+          if subnode1.nodeName == 'SyncHdr':
+            for subnode2 in self.getElementNodeList(subnode1):
+              if subnode2.nodeName == 'MsgID':
+                message_id = int(subnode2.childNodes[0].data)
     return message_id
 
   def getTarget(self, xml):
@@ -318,9 +330,17 @@
     return the target in the SyncHdr section
     """
     url = ''
-    url = xml.xpath('string(/SyncML/SyncHdr/Target/LocURI)')
-    url = url.encode('utf-8')
+    for subnode in self.getElementNodeList(xml):
+      if subnode.nodeName == 'SyncML':
+        for subnode1 in self.getElementNodeList(subnode):
+          if subnode1.nodeName == 'SyncHdr':
+            for subnode2 in self.getElementNodeList(subnode1):
+              if subnode2.nodeName == 'Target':
+                for subnode3 in self.getElementNodeList(subnode2):
+                  if subnode3.nodeName == 'LocURI':
+                    url = subnode3.childNodes[0].data
     return url
+
 
   def getAlertLastAnchor(self, xml_stream):
     """
@@ -331,8 +351,23 @@
 
     # Get informations from the body
     client_body = first_node.childNodes[3]
-    last_anchor = client_body.xpath('string(/Alert/Item/Meta/Anchor/Last)')
-    last_anchor = last_anchor.encode('utf-8')
+    for subnode in client_body.childNodes:
+      if subnode.nodeType == subnode.ELEMENT_NODE and \
+          subnode.nodeName == "Alert":
+        for subnode2 in subnode.childNodes:
+          if subnode2.nodeType == subnode2.ELEMENT_NODE and \
+              subnode2.nodeName == "Item":
+            for subnode3 in subnode2.childNodes:
+              if subnode3.nodeType == subnode3.ELEMENT_NODE and \
+                  subnode3.nodeName == "Meta":
+                for subnode4 in subnode3.childNodes:
+                  if subnode4.nodeType == subnode4.ELEMENT_NODE and \
+                      subnode4.nodeName == "Anchor":
+                    for subnode5 in subnode4.childNodes:
+                      # Get the last time we had a synchronization
+                     if subnode5.nodeType == subnode5.ELEMENT_NODE and \
+                         subnode5.nodeName == "Last":
+                        last_anchor = subnode5.childNodes[0].data
     return last_anchor
 
   def getAlertNextAnchor(self, xml_stream):
@@ -346,33 +381,61 @@
 
     # Get informations from the body
     client_body = first_node.childNodes[3]
-    next_anchor = client_body.xpath('string(/Alert/Item/Meta/Anchor/Next)')
-    next_anchor = next_anchor.encode('utf-8')
-    return next_anchor
+    if client_body.nodeName != "SyncBody":
+      print "This is not a SyncML Body"
+    for subnode in client_body.childNodes:
+      if subnode.nodeType == subnode.ELEMENT_NODE and \
+          subnode.nodeName == "Alert":
+        for subnode2 in subnode.childNodes:
+          if subnode2.nodeType == subnode2.ELEMENT_NODE and \
+              subnode2.nodeName == "Item":
+            for subnode3 in subnode2.childNodes:
+              if subnode3.nodeType == subnode3.ELEMENT_NODE and \
+                  subnode3.nodeName == "Meta":
+                for subnode4 in subnode3.childNodes:
+                 if subnode4.nodeType == subnode4.ELEMENT_NODE and \
+                     subnode4.nodeName == "Anchor":
+                    for subnode5 in subnode4.childNodes:
+                      # Get the last time we had a synchronization
+                      if subnode5.nodeType == subnode5.ELEMENT_NODE and \
+                          subnode5.nodeName == "Next":
+                        next_anchor = subnode5.childNodes[0].data
+                        return next_anchor
 
   def getStatusTarget(self, xml):
     """
       Return the value of the alert code inside the xml_stream
     """
-    return xml.xpath('string(TargetRef)')
+    # Get informations from the body
+    if xml.nodeName=='Status':
+      for subnode in xml.childNodes:
+        if subnode.nodeType == subnode.ELEMENT_NODE and \
+            subnode.nodeName == 'TargetRef':
+          return subnode.childNodes[0].data
+    return None
 
   def getStatusCode(self, xml):
     """
       Return the value of the alert code inside the xml_stream
     """
-    status_code = xml.xpath('string(Data)')
-    if status_code not in ('', None, []):
-      return int(status_code)
+    # Get informations from the body
+    if xml.nodeName=='Status':
+      for subnode in xml.childNodes:
+        if subnode.nodeType == subnode.ELEMENT_NODE and \
+            subnode.nodeName == 'Data':
+          return int(subnode.childNodes[0].data)
     return None
 
   def getStatusCommand(self, xml):
     """
       Return the value of the command inside the xml_stream
     """
+    # Get informations from the body
     if xml.nodeName=='Status':
-      return xml.xpath('string(//Status/Cmd)')
-    else:
-      return None
+      for subnode in xml.childNodes:
+        if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == 'Cmd':
+          return subnode.childNodes[0].data
+    return None
 
   def getCred(self, xml):
     """
@@ -381,61 +444,111 @@
     format=''
     type=''
     data=''
+    
 
     first_node = xml.childNodes[0]
-    format = first_node.xpath('string(/SyncML/SyncHdr/Cred/Meta/Format)')
-    type = first_node.xpath('string(/SyncML/SyncHdr/Cred/Meta/Type)')
-    data = first_node.xpath('string(/SyncML/SyncHdr/Cred/Data)')
-
-    format = format.encode('utf-8')
-    type = type.encode('utf-8')
-    data = data.encode('utf-8')
+    if first_node.nodeName != "SyncML":
+      print "This is not a SyncML message"
+    # Get informations from the header
+    xml_header = first_node.childNodes[1]
+    if xml_header.nodeName != "SyncHdr":
+      LOG('PubSyncModif',0,'This is not a SyncML Header')
+      raise ValueError, "Sorry, This is not a SyncML Header"
+
+    for subnode in xml_header.childNodes:
+      if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName=='Cred':
+        for subnode2 in subnode.childNodes:
+          if subnode2.nodeType == subnode2.ELEMENT_NODE and \
+              subnode2.nodeName == 'Meta':
+            for subnode3 in subnode2.childNodes:
+              if subnode3.nodeType == subnode3.ELEMENT_NODE and \
+                  subnode3.nodeName == 'Format':
+                    if len(subnode3.childNodes) > 0:
+                      format=subnode3.childNodes[0].data
+              if subnode3.nodeType == subnode3.ELEMENT_NODE and \
+                  subnode3.nodeName == 'Type':
+                    if len(subnode3.childNodes) > 0:
+                      type=subnode3.childNodes[0].data
+          if subnode2.nodeType == subnode2.ELEMENT_NODE and \
+              subnode2.nodeName == 'Data':
+                if len(subnode2.childNodes) > 0:
+                  data=subnode2.childNodes[0].data
     return (format, type, data)
 
   def getAlertCode(self, xml_stream):
     """
       Return the value of the alert code inside the full syncml message
     """
-    alert_code = xml_stream.xpath('string(SyncML/SyncBody/Alert/Data)')
-    if alert_code not in (None, ''):
-      return int(alert_code)
-    else:
-      return None
+    # Get informations from the body
+    first_node = xml_stream.childNodes[0]
+    client_body = first_node.childNodes[3]
+    if client_body.nodeName != "SyncBody":
+      LOG('XMLSyncUtils.getAlertCode',0,"This is not a SyncML Body")
+      raise ValueError, "Sorry, This is not a SyncML Body"
+    alert = 0
+    for subnode in client_body.childNodes:
+      if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName=='Alert':
+        for subnode1 in subnode.childNodes:
+          if subnode1.nodeType == subnode1.ELEMENT_NODE and subnode1.nodeName == 'Data':
+            return int(subnode1.childNodes[0].data)
+    return None
 
   def checkCred(self, xml_stream):
     """
       Check if there's a Cred section in the xml_stream
     """
-    cred = False 
-    if xml_stream.xpath('string(SyncML/SyncHdr/Cred)') not in ('', None, []):
-      cred = True
+    first_node = xml_stream.childNodes[0]
+    # Get informations from the header
+    xml_header = first_node.childNodes[1]
+    if xml_header.nodeName != "SyncHdr":
+      LOG('PubSyncModif',0,'This is not a SyncML Header')
+      raise ValueError, "Sorry, This is not a SyncML Header"
+    cred = 0
+    for subnode in xml_header.childNodes:
+      if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == "Cred":
+        cred=1
     return cred
 
   def checkAlert(self, xml_stream):
     """
       Check if there's an Alert section in the xml_stream
     """
-    alert = False
-    if xml_stream.xpath('string(SyncML/SyncBody/Alert)') not in ('', None, []):
-      alert = True
+    first_node = xml_stream.childNodes[0]
+    client_body = first_node.childNodes[3]
+    if client_body.nodeName != "SyncBody":
+      print "This is not a SyncML Body"
+    alert = 0
+    for subnode in client_body.childNodes:
+      if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == "Alert":
+        alert = 1
     return alert
 
   def checkSync(self, xml_stream):
     """
       Check if there's an Sync section in the xml_xtream
     """
-    sync = False
-    if xml_stream.xpath('string(SyncML/SyncBody/Sync)') not in ('', None, []):
-      sync = True
-    return sync
+    first_node = xml_stream.childNodes[0]
+    client_body = first_node.childNodes[3]
+    if client_body.nodeName != "SyncBody":
+      LOG('checkSync',0,"This is not a SyncML Body")
+      raise ValueError, "Sorry, This is not a SyncML Body"
+    for subnode in client_body.childNodes:
+      if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == "Sync":
+        return 1
+    return 0
 
   def CheckStatus(self, xml_stream):
     """
       Check if there's a Status section in the xml_xtream
     """
-    status = False
-    if xml_stream.xpath('string(SyncML/SyncBody/Status)') not in ('', None, []):
-      status = True
+    first_node = xml_stream.childNodes[0]
+    client_body = first_node.childNodes[3]
+    if client_body.nodeName != "SyncBody":
+      print "This is not a SyncML Body"
+    status = None
+    for subnode in client_body.childNodes:
+      if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == "Status":
+        status = "1"
     return status
 
   def getNextSyncAction(self, xml_stream, last_action):
@@ -450,22 +563,18 @@
       print "This is not a SyncML Body"
     next_action = None
     for subnode in client_body.childNodes:
-      if subnode.nodeType == subnode.ELEMENT_NODE and \
-          subnode.nodeName == "Sync":
+      if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == "Sync":
         # if we didn't use this method before
         if last_action == None and len(subnode.childNodes) > 1:
           next_action = subnode.childNodes[1]
         else:
           found = None
           for subnode2 in subnode.childNodes:
-            if subnode2.nodeType == subnode.ELEMENT_NODE and \
-                subnode2 != last_action and found is None:
+            if subnode2.nodeType == subnode.ELEMENT_NODE and subnode2 != last_action and found is None:
               pass
-            elif subnode2.nodeType == subnode.ELEMENT_NODE and \
-                subnode2 == last_action and found is None:
+            elif subnode2.nodeType == subnode.ELEMENT_NODE and subnode2 == last_action and found is None:
               found = 1
-            elif subnode2.nodeType == subnode.ELEMENT_NODE and \
-                found is not None:
+            elif subnode2.nodeType == subnode.ELEMENT_NODE and found is not None:
               next_action = subnode2
               break
     return next_action
@@ -484,8 +593,7 @@
     next_status = None
     found = None
     for subnode in client_body.childNodes:
-      if subnode.nodeType == subnode.ELEMENT_NODE and \
-          subnode.nodeName == "Status":
+      if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == "Status":
         # if we didn't use this method before
         if last_status == None:
           next_status = subnode
@@ -501,11 +609,9 @@
       Return the node starting with <object....> of the action
     """
     for subnode in action.childNodes:
-      if subnode.nodeType == subnode.ELEMENT_NODE and \
-          subnode.nodeName == 'Item':
+      if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == 'Item':
         for subnode2 in subnode.childNodes:
-          if subnode2.nodeType == subnode2.ELEMENT_NODE and \
-              subnode2.nodeName == 'Data':
+          if subnode2.nodeType == subnode2.ELEMENT_NODE and subnode2.nodeName == 'Data':
             for subnode3 in subnode2.childNodes:
               #if subnode3.nodeType == subnode3.ELEMENT_NODE and subnode3.nodeName == 'object':
               if subnode3.nodeType == subnode3.ELEMENT_NODE:
@@ -516,11 +622,9 @@
       Return the node starting with <object....> of the action
     """
     for subnode in action.childNodes:
-      if subnode.nodeType == subnode.ELEMENT_NODE and \
-          subnode.nodeName == 'Item':
+      if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == 'Item':
         for subnode2 in subnode.childNodes:
-          if subnode2.nodeType == subnode2.ELEMENT_NODE and \
-              subnode2.nodeName == 'Data':
+          if subnode2.nodeType == subnode2.ELEMENT_NODE and subnode2.nodeName == 'Data':
             for subnode3 in subnode2.childNodes:
               #if subnode3.nodeType == subnode3.ELEMENT_NODE and subnode3.nodeName == 'object':
               if subnode3.nodeType == subnode3.COMMENT_NODE:
@@ -535,40 +639,60 @@
 
     return None
 
+
+  def getAttributeNodeList(self, node):
+    """
+      Return attributesNodes that are ElementNode XXX may be not needed at all
+    """
+    subnode_list = []
+    for subnode in node.attributes:
+      if subnode.nodeType == subnode.ATTRIBUTE_NODE:
+        subnode_list += [subnode]
+    return subnode_list
+
   def getActionId(self, action):
     """
       Return the rid of the object described by the action
     """
     for subnode in action.childNodes:
-      if subnode.nodeType == subnode.ELEMENT_NODE and \
-          subnode.nodeName == 'Item':
+      if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == 'Item':
         for subnode2 in subnode.childNodes:
-          if subnode2.nodeType == subnode2.ELEMENT_NODE and \
-              subnode2.nodeName == 'Source':
+          if subnode2.nodeType == subnode2.ELEMENT_NODE and subnode2.nodeName == 'Source':
             for subnode3 in subnode2.childNodes:
-              if subnode3.nodeType == subnode3.ELEMENT_NODE and \
-                  subnode3.nodeName == 'LocURI':
+              if subnode3.nodeType == subnode3.ELEMENT_NODE and subnode3.nodeName == 'LocURI':
                 return str(subnode3.childNodes[0].data)
 
   def checkActionMoreData(self, action):
     """
       Return the rid of the object described by the action
     """
-    if action.xpath('Item/MoreData'):
-      return True
-    return False
+    for subnode in action.childNodes:
+      if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == 'Item':
+        for subnode2 in subnode.childNodes:
+          if subnode2.nodeType == subnode2.ELEMENT_NODE and subnode2.nodeName == 'MoreData':
+            return 1
+    return 0
 
   def getActionType(self, action):
     """
       Return the type of the object described by the action
     """
-    return action.xpath('string(Meta/Type)')
+    for subnode in action.childNodes:
+      if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == 'Meta':
+        for subnode2 in subnode.childNodes:
+          if subnode2.nodeType == subnode2.ELEMENT_NODE and subnode2.nodeName == 'Type':
+            return str(subnode2.childNodes[0].data)
 
   def getElementNodeList(self, node):
     """
       Return childNodes that are ElementNode
     """
-    return node.xpath('*')
+    #return node.getElementsByTagName('*')
+    subnode_list = []
+    for subnode in node.childNodes or []:
+      if subnode.nodeType == subnode.ELEMENT_NODE:
+        subnode_list += [subnode]
+    return subnode_list
 
   def getTextNodeList(self, node):
     """
@@ -579,12 +703,16 @@
       if subnode.nodeType == subnode.TEXT_NODE:
         subnode_list += [subnode]
     return subnode_list
-  
+
   def getAttributeNodeList(self, node):
     """
       Return childNodes that are ElementNode
     """
-    return node.xpath('@*')
+    attribute_list = []
+    for subnode in node.attributes.values() or []:
+      if subnode.nodeType == subnode.ATTRIBUTE_NODE:
+        attribute_list += [subnode]
+    return attribute_list
 
   def getSyncMLData(self, domain=None,remote_xml=None,cmd_id=0,
                           subscriber=None,destination_path=None,
@@ -637,8 +765,7 @@
       #if gid_generator is not None:
       #  object_gid = gid_generator()
       force = 0
-      if syncml_data.count('\n') < self.MAX_LINES and not \
-          object.id.startswith('.'): # If not we have to cut
+      if syncml_data.count('\n') < self.MAX_LINES and not object.id.startswith('.'): # If not we have to cut
         #LOG('getSyncMLData',0,'xml_mapping: %s' % str(domain.xml_mapping))
         #LOG('getSyncMLData',0,'code: %s' % str(self.getAlertCode(remote_xml)))
         #LOG('getSyncMLData',0,'gid_list: %s' % str(local_gid_list))
@@ -654,13 +781,11 @@
         # For the case it was never synchronized, we have to send everything
         if signature is not None and signature.getXMLMapping()==None:
           pass
-        elif signature == None or (signature.getXML() == None and \
-            signature.getStatus() != self.PARTIAL) or \
-            self.getAlertCode(remote_xml) == self.SLOW_SYNC:
+        elif signature==None or (signature.getXML()==None and signature.getStatus()!=self.PARTIAL) or \
+            self.getAlertCode(remote_xml)==self.SLOW_SYNC:
           #LOG('PubSyncModif',0,'Current object.getPath: %s' % object.getPath())
           LOG('getSyncMLData',0,'no signature for gid: %s' % object_gid)
-          xml_object = self.getXMLObject(object=object, 
-              xml_mapping=domain.xml_mapping)
+          xml_object = self.getXMLObject(object=object,xml_mapping=domain.xml_mapping)
           xml_string = xml_object
           signature = Signature(gid=object_gid,id=object.getId(),object=object)
           signature.setTempXML(xml_object)
@@ -681,15 +806,14 @@
             status =self.PARTIAL
             signature.setAction('Add')
             xml_string = '<!--' + short_string + '-->'
-          syncml_data += self.addXMLObject(cmd_id=cmd_id, object=object, 
-              gid=object_gid, xml_string=xml_string, more_data=more_data)
+          syncml_data += self.addXMLObject(cmd_id=cmd_id, object=object,gid=object_gid,
+                                  xml_string=xml_string, more_data=more_data)
           cmd_id += 1
           signature.setStatus(status)
           subscriber.addSignature(signature)
         elif signature.getStatus()==self.NOT_SYNCHRONIZED \
             or signature.getStatus()==self.PUB_CONFLICT_MERGE: # We don't have synchronized this object yet
-          xml_object = self.getXMLObject(object=object, 
-              xml_mapping=domain.xml_mapping)
+          xml_object = self.getXMLObject(object=object,xml_mapping=domain.xml_mapping)
           #LOG('getSyncMLData',0,'checkMD5: %s' % str(signature.checkMD5(xml_object)))
           #LOG('getSyncMLData',0,'getStatus: %s' % str(signature.getStatus()))
           if signature.getStatus()==self.PUB_CONFLICT_MERGE:
@@ -718,8 +842,8 @@
               signature.setAction('Replace')
               xml_string = '<!--' + short_string + '-->'
             signature.setStatus(status)
-            syncml_data += self.replaceXMLObject(cmd_id=cmd_id, object=object, 
-                gid=object_gid, xml_string=xml_string, more_data=more_data)
+            syncml_data += self.replaceXMLObject(cmd_id=cmd_id,object=object,gid=object_gid,
+                                                xml_string=xml_string, more_data=more_data)
             cmd_id += 1
             signature.setTempXML(xml_object)
           # Now we can apply the xupdate from the subscriber
@@ -727,11 +851,10 @@
           #LOG('getSyncMLData subscriber_xupdate',0,subscriber_xupdate)
           if subscriber_xupdate is not None:
             old_xml = signature.getXML()
-            conduit.updateNode(xml=subscriber_xupdate, object=object, 
-                previous_xml=old_xml, force=(domain.getDomainType==self.SUB), 
-                simulate=0)
-            xml_object = self.getXMLObject(object=object, 
-                xml_mapping=domain.xml_mapping)
+            conduit.updateNode(xml=subscriber_xupdate, object=object,
+                              previous_xml=old_xml,force=(domain.getDomainType==self.SUB),
+                              simulate=0)
+            xml_object = self.getXMLObject(object=object,xml_mapping=domain.xml_mapping)
             signature.setTempXML(xml_object)
           if set_synchronized: # We have to do that after this previous update
             # We should not have this case when we are in CONFLICT_MERGE
@@ -767,11 +890,11 @@
           xml_string = '<!--' + xml_string + '-->'
           signature.setStatus(status)
           if signature.getAction()=='Replace':
-            syncml_data += self.replaceXMLObject(cmd_id=cmd_id, object=object,
-                gid=object_gid, xml_string=xml_string, more_data=more_data)
+            syncml_data += self.replaceXMLObject(cmd_id=cmd_id,object=object,gid=object_gid,
+                                                xml_string=xml_string, more_data=more_data)
           elif signature.getAction()=='Add':
-            syncml_data += self.addXMLObject(cmd_id=cmd_id, object=object, 
-                gid=object_gid, xml_string=xml_string, more_data=more_data)
+            syncml_data += self.addXMLObject(cmd_id=cmd_id, object=object,gid=object_gid,
+                                    xml_string=xml_string, more_data=more_data)
     return (syncml_data,xml_confirmation,cmd_id)
 
   def applyActionList(self, domain=None, subscriber=None,destination_path=None,
@@ -795,8 +918,7 @@
       object = domain.getObjectFromGid(object_gid)
       if signature == None:
         LOG('applyActionList, signature is None',0,signature)
-        signature = Signature(gid=object_gid, status=self.NOT_SYNCHRONIZED, 
-            object=object).__of__(subscriber)
+        signature = Signature(gid=object_gid,status=self.NOT_SYNCHRONIZED,object=object).__of__(subscriber)
         subscriber.addSignature(signature)
       force = signature.getForce()
       LOG('applyActionList',0,'object: %s' % repr(object))
@@ -810,7 +932,7 @@
             data_subnode = partial_data
           LOG('SyncModif',0,'data_subnode: %s' % data_subnode)
           #data_subnode = FromXml(data_subnode)
-          data_subnode = Parse(data_subnode)
+          data_subnode = parseString(data_subnode)
           data_subnode = data_subnode.childNodes[0] # Because we just created a new xml
           # document, with childNodes[0] a DocumentType and childNodes[1] the Element Node
         else:
@@ -820,13 +942,12 @@
           if object is None:
             object_id = domain.generateNewIdWithGenerator(object=destination_path,gid=object_gid)
             #if object_id is not None:
-            add_data = conduit.addNode(xml=data_subnode, 
-                object=destination_path, object_id=object_id)
+            add_data = conduit.addNode(xml=data_subnode, object=destination_path,
+                                             object_id=object_id)
             conflict_list += add_data['conflict_list']
             # Retrieve directly the object from addNode
             object = add_data['object']
             LOG('XMLSyncUtils, in ADD add_data',0,add_data)
-            signature.setPath(object.getPhysicalPath())
             LOG('applyActionList',0,'object after add: %s' % repr(object))
           else:
             #Object was retrieve but need to be updated without recreated
@@ -891,11 +1012,11 @@
 
         elif next_action.nodeName == 'Delete':
           object_id = signature.getId()
-          conduit.deleteNode(xml=self.getDataSubNode(next_action), 
-              object=destination_path, object_id=object_id)
+          conduit.deleteNode(xml=self.getDataSubNode(next_action), object=destination_path,
+                             object_id=object_id)
           subscriber.delSignature(object_gid)
-          xml_confirmation += self.SyncMLConfirmation(cmd_id, 
-              object_gid,status_code,'Delete')
+          xml_confirmation += self.SyncMLConfirmation(cmd_id,
+                                      object_gid,status_code,'Delete')
       else: # We want to retrieve more data
         signature.setStatus(self.PARTIAL)
         #LOG('SyncModif',0,'setPartialXML: %s' % str(previous_partial))
@@ -905,8 +1026,8 @@
         signature.setPartialXML(previous_partial)
         #LOG('SyncModif',0,'previous_partial: %s' % str(previous_partial))
         LOG('SyncModif',0,'waiting more data for :%s' % signature.getId())
-        xml_confirmation += self.SyncMLConfirmation(cmd_id, object_gid, 
-            self.WAITING_DATA, next_action.nodeName)
+        xml_confirmation += self.SyncMLConfirmation(cmd_id,object_gid,
+                                                self.WAITING_DATA,next_action.nodeName)
       if conflict_list != [] and signature is not None:
         # We had a conflict
         signature.setStatus(self.CONFLICT)
@@ -1000,13 +1121,11 @@
     if domain.domain_type == self.PUB:
       simulate = 1
       for subnode in xml_header.childNodes:
-        if subnode.nodeType == subnode.ELEMENT_NODE and \
-                              subnode.nodeName == "Source":
-          for subnode2 in subnode.childNodes:
-            if subnode2.nodeType == subnode2.ELEMENT_NODE and \
-                                  subnode2.nodeName == 'LocURI':
-              subscription_url = str(subnode2.childNodes[0].data)
-              subscriber = domain.getSubscriber(subscription_url)
+        if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == "Source":
+	  for subnode2 in subnode.childNodes:
+	    if subnode2.nodeType == subnode2.ELEMENT_NODE and subnode2.nodeName == 'LocURI':
+	      subscription_url = str(subnode2.childNodes[0].data)
+      subscriber = domain.getSubscriber(subscription_url)
 
     # We have to check if this message was not already, this can be dangerous
     # to update two times the same object
@@ -1023,8 +1142,7 @@
               xml=last_xml,domain=domain)
         elif domain.domain_type == self.SUB:
           self.sendResponse(from_url=domain.subscription_url, 
-              to_url=domain.publication_url, sync_id=domain.getTitle(), 
-              xml=last_xml, domain=domain)
+              to_url=domain.publication_url, sync_id=domain.getTitle(), xml=last_xml,domain=domain)
       return {'has_response':has_response,'xml':last_xml}
     subscriber.setLastSentMessage('')
 
@@ -1046,8 +1164,7 @@
                                   globals(), locals(), [''])
       conduit = getattr(conduit_module, conduit_name)()
     # Then apply the list of actions
-    (xml_confirmation,has_next_action,cmd_id) = self.applyActionList(
-                                         cmd_id=cmd_id,
+    (xml_confirmation,has_next_action,cmd_id) = self.applyActionList(cmd_id=cmd_id,
                                          domain=domain,
                                          destination_path=destination_path,
                                          subscriber=subscriber,
@@ -1061,9 +1178,8 @@
     
     # syncml header
     if domain.domain_type == self.PUB:
-      xml(self.SyncMLHeader(subscriber.getSessionId(), 
-        subscriber.incrementMessageId(), subscriber.getSubscriptionUrl(), 
-        domain.getPublicationUrl()))
+      xml(self.SyncMLHeader(subscriber.getSessionId(), subscriber.incrementMessageId(),
+          subscriber.getSubscriptionUrl(), domain.getPublicationUrl()))
     elif domain.domain_type == self.SUB:
       xml(self.SyncMLHeader(domain.getSessionId(), domain.incrementMessageId(),
         domain.getPublicationUrl(), domain.getSubscriptionUrl()))
@@ -1076,11 +1192,11 @@
     if has_next_action == 0 and not \
       (domain.domain_type==self.SUB and alert_code==self.SLOW_SYNC):
       (syncml_data,xml_confirmation,cmd_id) = self.getSyncMLData(domain=domain,
-                               remote_xml=remote_xml,
-                               subscriber=subscriber,
-                               destination_path=destination_path,
-                               cmd_id=cmd_id,xml_confirmation=xml_confirmation,
-                               conduit=conduit)
+                                       remote_xml=remote_xml,
+                                       subscriber=subscriber,
+                                       destination_path=destination_path,
+                                       cmd_id=cmd_id,xml_confirmation=xml_confirmation,
+                                       conduit=conduit)
 
     # syncml body
     xml(' <SyncBody>\n')




More information about the Erp5-report mailing list