Create a method in Signature to send data chunks

when the xml_partial is too long.
Use the pointers of Pdata for it and not of simple string.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29310 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7fd9f29f
...@@ -65,10 +65,10 @@ class Signature(Folder, SyncCode, File): ...@@ -65,10 +65,10 @@ class Signature(Folder, SyncCode, File):
id=None, id=None,
rid=None, rid=None,
status=None, status=None,
xml_string='', xml_string=None,
object=None): object=None):
Folder.__init__(self, id) Folder.__init__(self, id)
File.__init__(self, id, '', xml_string) File.__init__(self, id, '', '')
if object is not None: if object is not None:
self.setPath(object.getPhysicalPath()) self.setPath(object.getPhysicalPath())
self.setObjectId(object.getId()) self.setObjectId(object.getId())
...@@ -188,7 +188,7 @@ class Signature(Folder, SyncCode, File): ...@@ -188,7 +188,7 @@ class Signature(Folder, SyncCode, File):
if xml is not None: if xml is not None:
# convert the string to Pdata if the big size # convert the string to Pdata if the big size
file = cStringIO.StringIO(xml) file = cStringIO.StringIO(xml)
self.xml, size = self._read_data(file) self.xml, size = self.getParentValue()._read_data(file)
self.setTempXML(None) # We make sure that the xml will not be erased self.setTempXML(None) # We make sure that the xml will not be erased
self.setMD5(xml) self.setMD5(xml)
else: else:
...@@ -223,7 +223,7 @@ class Signature(Folder, SyncCode, File): ...@@ -223,7 +223,7 @@ class Signature(Folder, SyncCode, File):
""" """
if xml is not None: if xml is not None:
file = cStringIO.StringIO(xml) file = cStringIO.StringIO(xml)
self.temp_xml, size = self._read_data(file) self.temp_xml, size = self.getParentValue()._read_data(file)
else: else:
self.temp_xml = None self.temp_xml = None
...@@ -353,7 +353,7 @@ class Signature(Folder, SyncCode, File): ...@@ -353,7 +353,7 @@ class Signature(Folder, SyncCode, File):
xml = xml.decode('utf-8').encode('ascii','xmlcharrefreplace') xml = xml.decode('utf-8').encode('ascii','xmlcharrefreplace')
# convert the string to Pdata if the big size # convert the string to Pdata if the big size
file = cStringIO.StringIO(xml) file = cStringIO.StringIO(xml)
self.partial_xml, size = self._read_data(file) self.partial_xml, size = self.getParentValue()._read_data(file)
if not isinstance(self.partial_xml, Pdata): if not isinstance(self.partial_xml, Pdata):
self.partial_xml = Pdata(self.partial_xml) self.partial_xml = Pdata(self.partial_xml)
self.last_data_partial_xml = self.partial_xml.getLastPdata() self.last_data_partial_xml = self.partial_xml.getLastPdata()
...@@ -372,7 +372,7 @@ class Signature(Folder, SyncCode, File): ...@@ -372,7 +372,7 @@ class Signature(Folder, SyncCode, File):
xml = xml.decode('utf-8').encode('ascii','xmlcharrefreplace') xml = xml.decode('utf-8').encode('ascii','xmlcharrefreplace')
file = cStringIO.StringIO(xml) file = cStringIO.StringIO(xml)
xml_append, size = self._read_data(file) xml_append, size = self.getParentValue()._read_data(file)
if not isinstance(xml_append, Pdata): if not isinstance(xml_append, Pdata):
xml_append = Pdata(xml_append) xml_append = Pdata(xml_append)
last_data = xml_append.getLastPdata() last_data = xml_append.getLastPdata()
...@@ -381,7 +381,36 @@ class Signature(Folder, SyncCode, File): ...@@ -381,7 +381,36 @@ class Signature(Folder, SyncCode, File):
else: else:
self.partial_xml = xml_append self.partial_xml = xml_append
self.last_data_partial_xml = last_data self.last_data_partial_xml = last_data
def getFirstChunkPdata(self, size_lines):
"""
"""
chunk = list()
chunk.append(self.partial_xml.data)
size = chunk[0].count('\n')
index = 0
Pdata = next = self.partial_xml.next
while size < size_lines:
Pdata = next
size += Pdata.data.count('\n')
chunk.append(Pdata.data)
index += 1
next = Pdata.next
if size == size_lines:
self.partial_xml = next
elif size > size_lines:
data_list = chunk[index].split('\n')
chunk[index] = '\n'.join(data_list[:size_lines])
if Pdata is not None:
Pdata.data = '\n'.join(data_list[size_lines:])
self.partial_xml = Pdata
else:
self.partial_xml.data = '\n'.join(data_list[size_lines:])
return ''.join(chunk)
def getPartialXML(self): def getPartialXML(self):
""" """
Set the partial string we will have to Set the partial string we will have to
......
...@@ -36,6 +36,7 @@ from Products.ERP5Type.Core.Folder import Folder ...@@ -36,6 +36,7 @@ from Products.ERP5Type.Core.Folder import Folder
from Products.ERP5Type.Base import Base from Products.ERP5Type.Base import Base
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type import PropertySheet from Products.ERP5Type import PropertySheet
from OFS.Image import File
from DateTime import DateTime from DateTime import DateTime
from zLOG import LOG, DEBUG, INFO from zLOG import LOG, DEBUG, INFO
import md5 import md5
...@@ -55,7 +56,7 @@ def addSubscription( self, id, title='', REQUEST=None ): ...@@ -55,7 +56,7 @@ def addSubscription( self, id, title='', REQUEST=None ):
#class Subscription(Folder, SyncCode, Implicit, Folder, Impli): #class Subscription(Folder, SyncCode, Implicit, Folder, Impli):
from XMLSyncUtils import XMLSyncUtils from XMLSyncUtils import XMLSyncUtils
class Subscription(Folder, XMLSyncUtils): class Subscription(Folder, XMLSyncUtils, File):
""" """
Subscription hold the definition of a master ODB Subscription hold the definition of a master ODB
from/to which a selection of objects will be synchronised from/to which a selection of objects will be synchronised
...@@ -88,8 +89,11 @@ class Subscription(Folder, XMLSyncUtils): ...@@ -88,8 +89,11 @@ class Subscription(Folder, XMLSyncUtils):
last_anchor - it defines the id of the last synchronisation last_anchor - it defines the id of the last synchronisation
next_anchor - it defines the id of the current synchronisation next_anchor - it defines the id of the current synchronisation
""" Subscription inherit of File because the Signature use method _read_data
which have the need of a __r_jar not None.
During the initialization of a Signature this __p_jar is None
"""
meta_type = 'ERP5 Subscription' meta_type = 'ERP5 Subscription'
portal_type = 'SyncML Subscription' # may be useful in the future... portal_type = 'SyncML Subscription' # may be useful in the future...
......
...@@ -781,8 +781,8 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -781,8 +781,8 @@ class XMLSyncUtilsMixin(SyncCode):
signature = Signature(id=gid, object=object).__of__(subscriber) signature = Signature(id=gid, object=object).__of__(subscriber)
signature.setTempXML(xml_string) signature.setTempXML(xml_string)
if xml_string.count('\n') > self.MAX_LINES: if xml_string.count('\n') > self.MAX_LINES:
xml_string, rest_string = self.cutXML(xml_string)
more_data = 1 more_data = 1
xml_string, rest_string = self.cutXML(xml_string)
signature.setPartialXML(rest_string) signature.setPartialXML(rest_string)
status = self.PARTIAL status = self.PARTIAL
signature.setAction('Add') signature.setAction('Add')
...@@ -822,8 +822,8 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -822,8 +822,8 @@ class XMLSyncUtilsMixin(SyncCode):
xml_string = self.getXupdateObject(xml_object, signature.getXML()) xml_string = self.getXupdateObject(xml_object, signature.getXML())
if xml_string.count('\n') > self.MAX_LINES: if xml_string.count('\n') > self.MAX_LINES:
# This make comment fails, so we need to replace # This make comment fails, so we need to replace
xml_string, rest_string = self.cutXML(xml_string)
more_data = 1 more_data = 1
xml_string, rest_string = self.cutXML(xml_string)
signature.setPartialXML(rest_string) signature.setPartialXML(rest_string)
status = self.PARTIAL status = self.PARTIAL
signature.setAction('Replace') signature.setAction('Replace')
...@@ -876,19 +876,23 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -876,19 +876,23 @@ class XMLSyncUtilsMixin(SyncCode):
signature.setStatus(self.SYNCHRONIZED) signature.setStatus(self.SYNCHRONIZED)
elif signature.getStatus() == self.PARTIAL: elif signature.getStatus() == self.PARTIAL:
xml_string = signature.getPartialXML() xml_string = signature.getPartialXML()
xml_to_send = Element('Partial')
xml_to_send.text = etree.CDATA(xml_string.decode('utf-8'))
if(subscriber.getMediaType() != self.MEDIA_TYPE['TEXT_XML']): if(subscriber.getMediaType() != self.MEDIA_TYPE['TEXT_XML']):
xml_to_send = conduit.getXMLFromObjectWithId(object,\ xml_to_send = conduit.getXMLFromObjectWithId(object,\
xml_mapping=domain.getXMLMapping()) xml_mapping=domain.getXMLMapping())
elif xml_string.count('\n') > self.MAX_LINES: elif xml_string.count('\n') > self.MAX_LINES:
xml_to_send, rest_string = self.cutXML(xml_string)
more_data = 1 more_data = 1
signature.setPartialXML(rest_string) # Receive the chunk of partial xml
short_string = signature.getFirstChunkPdata(self.MAX_LINES)
xml_to_send = etree.Element('Partial')
xml_to_send.text = etree.CDATA(short_string.decode('utf-8'))
status = self.PARTIAL status = self.PARTIAL
else:
xml_to_send = Element('Partial')
xml_to_send.text = etree.CDATA(xml_string.decode('utf-8'))
signature.setStatus(status) signature.setStatus(status)
if signature.getAction() == 'Replace': if signature.getAction() == 'Replace':
rid = signature.getRid()#in fisrt, we try with rid if there is one rid = signature.getRid()
# In first, we try with rid if there is one
gid = signature.getGid() gid = signature.getGid()
syncml_data_list.append(self.replaceXMLObject( syncml_data_list.append(self.replaceXMLObject(
cmd_id=cmd_id, cmd_id=cmd_id,
......
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