[Erp5-report] r35817 nicolas - /erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon May 31 18:28:07 CEST 2010


Author: nicolas
Date: Mon May 31 18:28:05 2010
New Revision: 35817

URL: http://svn.erp5.org?rev=35817&view=rev
Log:
Add new parameter for replaceIdFromXML to specify id of replacement attribute

Modified:
    erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py

Modified: erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py?rev=35817&r1=35816&r2=35817&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py [utf8] (original)
+++ erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py [utf8] Mon May 31 18:28:05 2010
@@ -625,21 +625,21 @@
         return self.convertXmlValue(subnode)
     return None
 
-  def replaceIdFromXML(self, xml, new_id):
+  def replaceIdFromXML(self, xml, attribute_name, new_id, as_string=True):
     """
       return a xml with id replace by a new id
     """
-    if xml is not None and new_id is not None:
-      if isinstance(xml, str):
-        xml = etree.XML(xml, parser=parser)
+    if isinstance(xml, str):
+      xml = etree.XML(xml, parser=parser)
+    else:
       #copy of xml object for modification
-      xml_copy = deepcopy(xml)
-      if xml_copy.tag == self.xml_object_tag:
-        object_element = xml_copy
-      else:
-        object_element = xml_copy.xpath('//object')[0]
-      object_element.attrib['id'] = new_id
-      return etree.tostring(xml_copy)
+      xml = deepcopy(xml)
+    object_element = xml.find('object')
+    del object_element.attrib['id']
+    object_element.attrib[attribute_name] = new_id
+    if as_string:
+      return etree.tostring(xml)
+    return xml
 
   def getXMLFromObjectWithId(self, object, xml_mapping):
     """
@@ -653,20 +653,20 @@
       xml = func()
     return xml
 
-  def getXMLFromObjectWithGid(self, object, gid, xml_mapping=None):
+  def getXMLFromObjectWithGid(self, object, gid, xml_mapping, as_string=True):
     """
       return the xml with Gid of Object
     """
+    xml_with_id = self.getXMLFromObjectWithId(object, xml_mapping)
+    return self.replaceIdFromXML(xml_with_id, 'gid', gid, as_string=as_string)
+
+
+  def getXMLFromObjectWithRid(self, object, rid, xml_mapping, as_string=True):
+    """
+      return the xml with Rid of Object
+    """
     xml_id = self.getXMLFromObjectWithId(object, xml_mapping)
-    xml_gid = self.replaceIdFromXML(xml_id, gid)
-    return xml_gid
-
-  def getXMLFromObjectWithRid(self, object, rid, xml_mapping=None):
-    """
-      return the xml with Rid of Object
-    """
-    xml_id = self.getXMLFromObjectWithId(object, xml_mapping)
-    xml_rid = self.replaceIdFromXML(xml_id, rid)
+    xml_rid = self.replaceIdFromXML(xml_id, 'rid', rid, as_string=as_string)
     return xml_rid
 
   security.declareProtected(Permissions.AccessContentsInformation,'convertToXml')




More information about the Erp5-report mailing list