Commit 2f7d0ece authored by Aurel's avatar Aurel

fix unicode errors & do some cleanup

parent 8b7fde47
......@@ -32,7 +32,7 @@ import unittest
from zLOG import LOG
from Testing import ZopeTestCase
from AccessControl.SecurityManagement import newSecurityManager
import os
class TestOxatisSynchronization(ERP5TypeTestCase):
"""
......
......@@ -132,6 +132,8 @@ class SyncMLSignature(XMLObject):
if we want to know if an objects has changed or not
Returns 1 if MD5 are equals, else it returns 0
"""
if isinstance(xml_string, unicode):
xml_string = xml_string.encode('utf-8')
return ((md5.new(xml_string).hexdigest()) == self.getContentMd5())
security.declareProtected(Permissions.ModifyPortalContent, 'setPartialData')
......
......@@ -2165,7 +2165,7 @@ class SynchronizationTool(BaseTool):
if reset:
#After a reset we want copy the LAST XML view on Signature.
#this implementation is not sufficient, need to be improved.
if not isinstance(xml_object, str):
if not isinstance(xml_object, (str, unicode)):
xml_object = etree.tostring(xml_object, encoding='utf-8',
pretty_print=True)
else:
......@@ -2174,9 +2174,11 @@ class SynchronizationTool(BaseTool):
domain.getXmlBindingGeneratorMethodId(),
context_document=subscriber.getPath())
#if signature.getValidationState() != 'synchronized':
if isinstance(xml_object, unicode):
xml_object = xml_object.encode('utf-8')
signature.synchronize()
signature.setReference(object.getPath())
signature.setData(xml_object)
signature.setData(str(xml_object))
xml_confirmation_list.append(self.SyncMLConfirmation(
cmd_id=cmd_id,
cmd='Add',
......
......@@ -26,7 +26,6 @@
##############################################################################
from Products.ERP5TioSafe.Conduit.TioSafeBaseConduit import TioSafeBaseConduit
from lxml import etree
class AccountERP5IntegrationConduit(TioSafeBaseConduit):
"""
......
......@@ -51,20 +51,24 @@ class TioSafeBaseConduit(ERP5Conduit):
XXX name of method is not good, because content is not necessarily XML
return a xml with id replaced by a new id
"""
if isinstance(xml, str):
xml = etree.XML(xml, parser=parser)
if isinstance(xml, str) or isinstance(xml, unicode):
xml = etree.XML(str(xml), parser=parser)
else:
# copy of xml object for modification
xml = deepcopy(xml)
object_element = xml.find('object')
if object_element:
if object_element and object_element != -1:
if attribute_name == 'id':
del object_element.attrib['gid']
else:
del object_element.attrib['id']
object_element.attrib[attribute_name] = new_id
if as_string:
try:
return etree.tostring(xml, pretty_print=True, encoding="utf-8")
except:
import pdb
pdb.set_trace()
return xml
def _generateConflict(self, path, tag, xml, current_value, new_value, signature):
......
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2009 Nexedi SA and Contributors. All Rights Reserved.
# Hervé Poulain <herve@nexedi.com>
# Hervé Poulain <herve@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
......@@ -27,7 +28,7 @@
##############################################################################
from Products.ERP5TioSafe.Conduit.TioSafeBaseConduit import TioSafeBaseConduit
from lxml import etree
class TioSafeNodeConduit(TioSafeBaseConduit):
"""
......@@ -369,5 +370,3 @@ class TioSafeNodeConduit(TioSafeBaseConduit):
new_document = document.context.person_module[document.getId()]
document.updateProperties(new_document)
return conflict_list
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