Commit 2e88fa44 authored by Nicolas Delaby's avatar Nicolas Delaby

replace last imports of 4Suite

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25220 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 470a76e3
......@@ -2,23 +2,12 @@
# coding=UTF-8
import httplib
import urllib,urllib2, os
from Ft.Xml import Parse
import cStringIO
import string
import socket
import time
from optparse import OptionParser
try:
from Ft.Xml.Domlette import Print, PrettyPrint
except ImportError:
class Print:
def __init__(self, *args, **kw):
raise ImportError, '4Suite-XML is not installed'
class PrettyPrint:
def __init__(self, *args, **kw):
raise ImportError, '4Suite-XML is not installed'
from lxml import etree
class OptionParser(OptionParser):
......@@ -46,7 +35,7 @@ parser.check_required("--host")
#address of this small server :
#Host = '192.168.242.247'
Host=options.host
Host = options.host
#address of the publication :
#publication_url = 'http://localhost:9080/erp5Serv'
......@@ -57,10 +46,10 @@ to_url = publication_url+"/portal_synchronizations/readResponse"
#port of this server :
#Port = 1234
Port=options.port
Port = options.port
#address of the this server :
syncml_server_url = 'http://'+Host+':'+str(Port)
syncml_server_url = 'http://%s:%s' % (Host, Port)
#socket :
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
......@@ -78,11 +67,7 @@ def nodeToString(node):
"""
return an xml string corresponding to the node
"""
buf = cStringIO.StringIO()
Print(node, stream=buf, encoding='utf-8')
xml_string = buf.getvalue()
buf.close()
return xml_string
return etree.tostring(node, encoding='utf-8')
def xml2wbxml(xml):
"""
......@@ -151,8 +136,8 @@ def getClientUrl(text):
"""
find the client url in the text and return it
"""
document = Parse(text)
client_url = document.xpath('string(//SyncHdr/Source/LocURI)').encode('utf-8')
document = etree.XML(text)
client_url = '%s' % document.xpath('string(//SyncHdr/Source/LocURI)')
return client_url
def sendResponse(text, to_url, client_url):
......@@ -166,7 +151,7 @@ def sendResponse(text, to_url, client_url):
print '\nsendResponse...'
text=wbxml2xml(text)
text = wbxml2xml(text)
text = text.replace(syncml_server_url, publication_url)
text = text.replace(client_url, syncml_server_url)
......@@ -209,7 +194,7 @@ def main():
if text.endswith('\x01\x01'):
client_url = getClientUrl(wbxml2xml(text))
response = sendResponse(text=text, to_url=to_url, client_url=client_url)
if response not in ('', None):
if response:
response = response.replace(syncml_server_url, client_url)
response = response.replace(publication_url, syncml_server_url)
print "\nresponse = \n",response
......
......@@ -1030,11 +1030,11 @@ class SynchronizationTool( SubscriptionSynchronization,
if domain.getSyncContentType() == self.CONTENT_TYPE['SYNCML_WBXML']:
text = self.wbxml2xml(text)
#LOG('readResponse, text after wbxml :\n', TRACE, text)
xml = Parse(text)
xml = etree.XML(text)
url = self.getTarget(xml)
for publication in self.getPublicationList():
if publication.getPublicationUrl()==url and \
publication.getTitle()==sync_id:
publication.getTitle() == sync_id:
if publication.getActivityEnabled():
#use activities to send SyncML data.
activity = self.getActivityType(domain=publication)
......
......@@ -42,20 +42,20 @@ class XupdateUtils(XMLSyncUtilsMixin):
Parse the xupdate and then it will call the conduit
"""
conflict_list = []
if type(xupdate) in (type('a'),type(u'a')):
if isinstance(xupdate, (str, unicode)):
xupdate = FromXml(xupdate)
for subnode in self.getElementNodeList(xupdate):
for subnode in xupdate:
selection_name = ''
if subnode.nodeName in self.XUPDATE_INSERT_OR_ADD:
conflict_list += conduit.addNode(xml=subnode, object=object, \
force=force, **kw)
elif subnode.nodeName in self.XUPDATE_DEL:
conflict_list += conduit.deleteNode(xml=subnode, object=object, \
force=force, **kw)
elif subnode.nodeName in self.XUPDATE_UPDATE:
conflict_list += conduit.updateNode(xml=subnode, object=object, \
force=force, **kw)
if subnode.xpath('name()') in self.XUPDATE_INSERT_OR_ADD:
conflict_list.extend(conduit.addNode(xml=subnode, object=object, \
force=force, **kw))
elif subnode.xpath('name()') in self.XUPDATE_DEL:
conflict_list.extend(conduit.deleteNode(xml=subnode, object=object, \
force=force, **kw))
elif subnode.xpath('name()') in self.XUPDATE_UPDATE:
conflict_list.extend(conduit.updateNode(xml=subnode, object=object, \
force=force, **kw))
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