Commit 0f6857b1 authored by Aurel's avatar Aurel

cleanup SyncML Signature class

remove useless commented code
improve method comments
parent 67230753
...@@ -41,20 +41,17 @@ _MARKER = [] ...@@ -41,20 +41,17 @@ _MARKER = []
class SyncMLSignature(XMLObject): class SyncMLSignature(XMLObject):
""" """
status -- SENT, CONFLICT... A Signature represent a document that is synchronized
md5_object -- An MD5 value of a given document
#uid -- The UID of the document It contains as attribute the xml representation of the object which is used
id -- the ID of the document to generate the diff of the object between two synchronization
gid -- the global id of the document
rid -- the uid of the document on the remote database, It also contains the list of conflict as sub-objects when it happens
only needed on the server.
xml -- the xml of the object at the time where it was synchronized
""" """
meta_type = 'ERP5 Signature' meta_type = 'ERP5 Signature'
portal_type = 'SyncML Signature' portal_type = 'SyncML Signature'
isIndexable = ConstantGetter('isIndexable', value=False) isIndexable = ConstantGetter('isIndexable', value=False)
# Make sure RAD generated accessors at the class level
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
...@@ -72,12 +69,11 @@ class SyncMLSignature(XMLObject): ...@@ -72,12 +69,11 @@ class SyncMLSignature(XMLObject):
security.declareProtected(Permissions.ModifyPortalContent, 'setData') security.declareProtected(Permissions.ModifyPortalContent, 'setData')
def setData(self, value): def setData(self, value):
""" """
set the XML corresponding to the object Set the XML corresponding to the object
""" """
if value: if value:
# convert the string to Pdata # convert the string to Pdata
pdata_wrapper = PdataHelper(self.getPortalObject(), value) pdata_wrapper = PdataHelper(self.getPortalObject(), value)
#data, size = pdata_wrapper()
self._setData(pdata_wrapper) self._setData(pdata_wrapper)
self.setTemporaryData(None) # We make sure that the data will not be erased self.setTemporaryData(None) # We make sure that the data will not be erased
self.setContentMd5(pdata_wrapper.getContentMd5()) self.setContentMd5(pdata_wrapper.getContentMd5())
...@@ -88,7 +84,7 @@ class SyncMLSignature(XMLObject): ...@@ -88,7 +84,7 @@ class SyncMLSignature(XMLObject):
security.declareProtected(Permissions.AccessContentsInformation, 'getData') security.declareProtected(Permissions.AccessContentsInformation, 'getData')
def getData(self, default=_MARKER): def getData(self, default=_MARKER):
""" """
get the XML corresponding to the object Get the XML corresponding to the object
""" """
if self.hasData(): if self.hasData():
return str(self._baseGetData()) return str(self._baseGetData())
...@@ -101,9 +97,9 @@ class SyncMLSignature(XMLObject): ...@@ -101,9 +97,9 @@ class SyncMLSignature(XMLObject):
'setTemporaryData') 'setTemporaryData')
def setTemporaryData(self, value): def setTemporaryData(self, value):
""" """
This is the xml temporarily saved, it will This is the xml temporarily saved, it will
be stored with setXML when we will receive be stored with setXML when we will receive
the confirmation of synchronization the confirmation of synchronization
""" """
if value: if value:
self._setTemporaryData(PdataHelper(self.getPortalObject(), value)) self._setTemporaryData(PdataHelper(self.getPortalObject(), value))
...@@ -114,7 +110,7 @@ class SyncMLSignature(XMLObject): ...@@ -114,7 +110,7 @@ class SyncMLSignature(XMLObject):
'getTemporaryData') 'getTemporaryData')
def getTemporaryData(self, default=_MARKER): def getTemporaryData(self, default=_MARKER):
""" """
get the temp xml Return the temp xml as string
""" """
if self.hasTemporaryData(): if self.hasTemporaryData():
return str(self._baseGetTemporaryData()) return str(self._baseGetTemporaryData())
...@@ -126,9 +122,9 @@ class SyncMLSignature(XMLObject): ...@@ -126,9 +122,9 @@ class SyncMLSignature(XMLObject):
security.declareProtected(Permissions.AccessContentsInformation, 'checkMD5') security.declareProtected(Permissions.AccessContentsInformation, 'checkMD5')
def checkMD5(self, xml_string): def checkMD5(self, xml_string):
""" """
check if the given md5_object returns the same things as Check if the given md5_object returns the same things as the one stored in
the one stored in this signature, this is very usefull this signature, this is very usefull if we want to know if an objects has
if we want to know if an objects has changed or not changed or not
Returns 1 if MD5 are equals, else it returns 0 Returns 1 if MD5 are equals, else it returns 0
""" """
if isinstance(xml_string, unicode): if isinstance(xml_string, unicode):
...@@ -138,8 +134,7 @@ class SyncMLSignature(XMLObject): ...@@ -138,8 +134,7 @@ class SyncMLSignature(XMLObject):
security.declareProtected(Permissions.ModifyPortalContent, 'setPartialData') security.declareProtected(Permissions.ModifyPortalContent, 'setPartialData')
def setPartialData(self, value): def setPartialData(self, value):
""" """
Set the partial string we will have to Set the partial string we will have to deliver in the future
deliver in the future
""" """
if value: if value:
if not isinstance(value, PdataHelper): if not isinstance(value, PdataHelper):
...@@ -153,9 +148,8 @@ class SyncMLSignature(XMLObject): ...@@ -153,9 +148,8 @@ class SyncMLSignature(XMLObject):
security.declareProtected(Permissions.ModifyPortalContent, 'setLastData') security.declareProtected(Permissions.ModifyPortalContent, 'setLastData')
def setLastData(self, value): def setLastData(self, value):
""" """
This is the xml temporarily saved, it will This is the xml temporarily saved, it will be stored with setXML when we
be stored with setXML when we will receive will receive the confirmation of synchronization
the confirmation of synchronization
""" """
if value: if value:
self._setLastData(PdataHelper(self.getPortalObject(), value)) self._setLastData(PdataHelper(self.getPortalObject(), value))
...@@ -166,7 +160,7 @@ class SyncMLSignature(XMLObject): ...@@ -166,7 +160,7 @@ class SyncMLSignature(XMLObject):
'getPartialData') 'getPartialData')
def getPartialData(self, default=_MARKER): def getPartialData(self, default=_MARKER):
""" """
get the patial xml Return the patial xml as string
""" """
if self.hasPartialData(): if self.hasPartialData():
return str(self._baseGetPartialData()) return str(self._baseGetPartialData())
...@@ -175,7 +169,8 @@ class SyncMLSignature(XMLObject): ...@@ -175,7 +169,8 @@ class SyncMLSignature(XMLObject):
else: else:
return self._baseGetPartialData(default) return self._baseGetPartialData(default)
security.declareProtected(Permissions.ModifyPortalContent, 'appendPartialData') security.declareProtected(Permissions.ModifyPortalContent,
'appendPartialData')
def appendPartialData(self, value): def appendPartialData(self, value):
""" """
Append the partial string we will have to deliver in the future Append the partial string we will have to deliver in the future
...@@ -192,36 +187,11 @@ class SyncMLSignature(XMLObject): ...@@ -192,36 +187,11 @@ class SyncMLSignature(XMLObject):
self.setPartialData(value) self.setPartialData(value)
self.setLastDataPartialData(last_data) self.setLastDataPartialData(last_data)
#security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.ModifyPortalContent,
#'getFirstChunkPdata') 'getFirstPdataChunk')
#def getFirstChunkPdata(self, size_lines):
#"""
#"""
#chunk = [self.getPartialData().data]
#size = chunk[0].count('\n')
#current = self.getPartialData()
#next = current.next
#while size < size_lines and next is not None:
#current = next
#size += current.data.count('\n')
#chunk.append(current.data)
#next = current.next
#if size == size_lines:
#self.setPartialData(next)
#elif size > size_lines:
#overflow = size - size_lines
#data_list = chunk[-1].split('\n')
#chunk[-1] = '\n'.join(data_list[:-overflow])
#current.data = '\n'.join(data_list[-overflow:])
#self.setPartialData(current)
#return ''.join(chunk)
def getFirstPdataChunk(self, max_len): def getFirstPdataChunk(self, max_len):
""" """
""" """
#chunk, rest_in_queue = self._baseGetPartialData().\
#getFirstPdataChunkAndRestInQueue(max_len)
partial_data = self._baseGetPartialData() partial_data = self._baseGetPartialData()
chunk = partial_data[:max_len] chunk = partial_data[:max_len]
rest_in_queue = partial_data[max_len:] rest_in_queue = partial_data[max_len:]
...@@ -233,9 +203,8 @@ class SyncMLSignature(XMLObject): ...@@ -233,9 +203,8 @@ class SyncMLSignature(XMLObject):
'setSubscriberXupdate') 'setSubscriberXupdate')
def setSubscriberXupdate(self, value): def setSubscriberXupdate(self, value):
""" """
This is the xml temporarily saved, it will This is the xml temporarily saved, it will be stored with setXML when we
be stored with setXML when we will receive will receive the confirmation of synchronization
the confirmation of synchronization
""" """
if value: if value:
self._setSubscriberXupdate(PdataHelper(self.getPortalObject(), value)) self._setSubscriberXupdate(PdataHelper(self.getPortalObject(), value))
...@@ -246,7 +215,7 @@ class SyncMLSignature(XMLObject): ...@@ -246,7 +215,7 @@ class SyncMLSignature(XMLObject):
'getSubscriberXupdate') 'getSubscriberXupdate')
def getSubscriberXupdate(self, default=_MARKER): def getSubscriberXupdate(self, default=_MARKER):
""" """
get the patial xml Return the patial xml as string
""" """
if self.hasSubscriberXupdate(): if self.hasSubscriberXupdate():
return str(self._baseGetSubscriberXupdate()) return str(self._baseGetSubscriberXupdate())
...@@ -259,9 +228,8 @@ class SyncMLSignature(XMLObject): ...@@ -259,9 +228,8 @@ class SyncMLSignature(XMLObject):
'setPublisherXupdate') 'setPublisherXupdate')
def setPublisherXupdate(self, value): def setPublisherXupdate(self, value):
""" """
This is the xml temporarily saved, it will This is the xml temporarily saved, it will be stored with setXML when we
be stored with setXML when we will receive will receive the confirmation of synchronization
the confirmation of synchronization
""" """
if value: if value:
self._setPublisherXupdate(PdataHelper(self.getPortalObject(), value)) self._setPublisherXupdate(PdataHelper(self.getPortalObject(), value))
...@@ -272,7 +240,7 @@ class SyncMLSignature(XMLObject): ...@@ -272,7 +240,7 @@ class SyncMLSignature(XMLObject):
'getPublisherXupdate') 'getPublisherXupdate')
def getPublisherXupdate(self, default=_MARKER): def getPublisherXupdate(self, default=_MARKER):
""" """
get the patial xml Return the partial xml as string
""" """
if self.hasPublisherXupdate(): if self.hasPublisherXupdate():
return str(self._baseGetPublisherXupdate()) return str(self._baseGetPublisherXupdate())
...@@ -281,7 +249,6 @@ class SyncMLSignature(XMLObject): ...@@ -281,7 +249,6 @@ class SyncMLSignature(XMLObject):
else: else:
return self._baseGetPublisherXupdate(default) return self._baseGetPublisherXupdate(default)
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'reset') 'reset')
def reset(self, no_conflict=False): def reset(self, no_conflict=False):
...@@ -300,46 +267,34 @@ class SyncMLSignature(XMLObject): ...@@ -300,46 +267,34 @@ class SyncMLSignature(XMLObject):
if self.getValidationState() != 'not_synchronized': if self.getValidationState() != 'not_synchronized':
self.drift() self.drift()
security.declareProtected(Permissions.ModifyPortalContent,
'getConflictList')
def getConflictList(self): def getConflictList(self):
""" """
Return the actual action for a partial synchronization Return the actual action for a partial synchronization
""" """
return self.contentValues() return self.contentValues()
# returned_conflict_list = []
# if getattr(self, 'conflict_list', None) is None:
# return returned_conflict_list
# if len(self.conflict_list)>0:
# returned_conflict_list.extend(self.conflict_list)
# return returned_conflict_list
security.declareProtected(Permissions.ModifyPortalContent,
'setConflictList')
def setConflictList(self, conflict_list): def setConflictList(self, conflict_list):
""" """
Return the actual action for a partial synchronization XXX is it still usefull ?
""" """
return return
# if conflict_list is None or conflict_list == []:
# self.resetConflictList()
# else:
# self.conflict_list = conflict_list
security.declareProtected(Permissions.ModifyPortalContent,
'resetConflictList')
def resetConflictList(self): def resetConflictList(self):
""" """
Return the actual action for a partial synchronization XXX is it still usefull ?
""" """
return return
#self.conflict_list = PersistentMapping()
security.declareProtected(Permissions.ModifyPortalContent,
'delConflict')
def delConflict(self, conflict): def delConflict(self, conflict):
""" """
Delete provided conflict object Delete provided conflict object
""" """
self.manage_delObjects([conflict.getId(),]) self.manage_delObjects([conflict.getId(),])
# conflict_list = []
# for c in self.getConflictList():
# #LOG('delConflict, c==conflict',0,c==aq_base(conflict))
# if c != aq_base(conflict):
# conflict_list += [c]
# if conflict_list != []:
# self.setConflictList(conflict_list)
# else:
# self.resetConflictList()
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