Commit e8ee7d63 authored by Nicolas Delaby's avatar Nicolas Delaby

Get rid of Partial nodes which is not compliant with SyncML1.2 specification


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35808 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b10439fa
...@@ -657,9 +657,8 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -657,9 +657,8 @@ class XMLSyncUtilsMixin(SyncCode):
line_list = xml_string.split('\n') line_list = xml_string.split('\n')
short_string = '\n'.join(line_list[:self.MAX_LINES]) short_string = '\n'.join(line_list[:self.MAX_LINES])
rest_string = '\n'.join(line_list[self.MAX_LINES:]) rest_string = '\n'.join(line_list[self.MAX_LINES:])
xml_tree = E.Partial() xml_string = etree.CDATA(short_string.decode('utf-8'))
xml_tree.text = etree.CDATA(short_string.decode('utf-8')) return xml_string, rest_string
return xml_tree, rest_string
def getSyncMLData(self, domain=None, remote_xml=None, cmd_id=0, def getSyncMLData(self, domain=None, remote_xml=None, cmd_id=0,
subscriber=None, xml_confirmation_list=None, conduit=None, subscriber=None, xml_confirmation_list=None, conduit=None,
...@@ -858,20 +857,18 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -858,20 +857,18 @@ class XMLSyncUtilsMixin(SyncCode):
cmd='Replace')) cmd='Replace'))
signature.setStatus(self.SYNCHRONIZED) signature.setStatus(self.SYNCHRONIZED)
elif signature.getStatus() == self.PARTIAL: elif signature.getStatus() == self.PARTIAL:
xml_string = signature.getPartialXML(default='')
if(subscriber.getMediaType() != self.MEDIA_TYPE['TEXT_XML']):
xml_to_send = conduit.getXMLFromObjectWithId(object,\
xml_mapping=domain.getXMLMapping())
elif xml_string.count('\n') > self.MAX_LINES:
more_data = 1
# Receive the chunk of partial xml # Receive the chunk of partial xml
short_string = signature.getFirstChunkPdata(self.MAX_LINES) if subscriber.getMediaType() != self.MEDIA_TYPE['TEXT_XML']:
xml_to_send = E.Partial() xml_string = conduit.getXMLFromObjectWithId(object,
xml_to_send.text = etree.CDATA(short_string.decode('utf-8')) xml_mapping=domain.getXMLMapping())
status = self.PARTIAL
else: else:
xml_to_send = E.Partial() # Wrapp it into CDATA
xml_to_send.text = etree.CDATA(xml_string.decode('utf-8')) xml_string = signature.getPartialXML(default='')
if xml_string.count('\n') > self.MAX_LINES:
more_data = True
status = self.PARTIAL
xml_string = signature.getFirstChunkPdata(self.MAX_LINES)
xml_string = etree.CDATA(xml_string)
signature.setStatus(status) signature.setStatus(status)
if signature.getAction() == 'Replace': if signature.getAction() == 'Replace':
rid = signature.getRid() rid = signature.getRid()
...@@ -882,7 +879,7 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -882,7 +879,7 @@ class XMLSyncUtilsMixin(SyncCode):
object=object, object=object,
gid=gid, gid=gid,
rid=rid, rid=rid,
xml_string=xml_to_send, xml_string=xml_string,
more_data=more_data, more_data=more_data,
media_type=subscriber.getMediaType())) media_type=subscriber.getMediaType()))
elif signature.getAction() == 'Add': elif signature.getAction() == 'Add':
...@@ -892,7 +889,7 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -892,7 +889,7 @@ class XMLSyncUtilsMixin(SyncCode):
cmd_id=cmd_id, cmd_id=cmd_id,
object=object, object=object,
gid=gid, gid=gid,
xml_string=xml_to_send, xml_string=xml_string,
more_data=more_data, more_data=more_data,
media_type=subscriber.getMediaType())) media_type=subscriber.getMediaType()))
if not more_data: if not more_data:
...@@ -957,20 +954,26 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -957,20 +954,26 @@ class XMLSyncUtilsMixin(SyncCode):
signature.setObjectId(object_id) signature.setObjectId(object_id)
subscriber.addSignature(signature) subscriber.addSignature(signature)
force = signature.getForce() force = signature.getForce()
partial_node = action.find('.//{%(ns)s}Item/{%(ns)s}Data/{%(ns)s}Partial' % {'ns': SYNCML_NAMESPACE}) data_node = action.find('.//{%(ns)s}Item/{%(ns)s}Data'\
partial_data = partial_node is not None and partial_node.text or '' % {'ns': SYNCML_NAMESPACE})
if data_node is not None:
if len(data_node):
data = etree.tostring(data_node[0])
else:
data = data_node.text or ''
else:
data = ''
if not self.checkActionMoreData(action): if not self.checkActionMoreData(action):
# This is the last chunk of a partial xml
# or this is just an entire data chunk
data_subnode = None data_subnode = None
if partial_node is not None: if signature.hasPartialXML():
if not partial_data: # rebuild the entire data
data_subnode = signature.getPartialXML(default='') signature.appendPartialXML(data)
signature.setPartialXML(None) # fetch data as string
elif signature.hasPartialXML():
signature.appendPartialXML(partial_data)
data_subnode = signature.getPartialXML() data_subnode = signature.getPartialXML()
# clear partial data cache on Signature
signature.setPartialXML(None) signature.setPartialXML(None)
else:
data_subnode = partial_data
#LOG('applyActionList', DEBUG, 'data_subnode: %s' % data_subnode) #LOG('applyActionList', DEBUG, 'data_subnode: %s' % data_subnode)
if subscriber.getMediaType() == self.MEDIA_TYPE['TEXT_XML']: if subscriber.getMediaType() == self.MEDIA_TYPE['TEXT_XML']:
data_subnode = etree.XML(data_subnode, parser=parser) data_subnode = etree.XML(data_subnode, parser=parser)
......
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