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