[Erp5-report] r14982 - /erp5/trunk/products/ERP5SyncML/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Jun 26 16:49:40 CEST 2007
Author: seb
Date: Tue Jun 26 16:49:39 2007
New Revision: 14982
URL: http://svn.erp5.org?rev=14982&view=rev
Log:
- replace xpath for loops with xpath expression
- delete an old function : getNextSyncBodyStatus
Modified:
erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py
erp5/trunk/products/ERP5SyncML/Subscription.py
erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py
erp5/trunk/products/ERP5SyncML/SynchronizationTool.py
erp5/trunk/products/ERP5SyncML/XMLSyncUtils.py
Modified: erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py?rev=14982&r1=14981&r2=14982&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py (original)
+++ erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py Tue Jun 26 16:49:39 2007
@@ -38,6 +38,7 @@
IAuthenticationPlugin
from AccessControl.SecurityManagement import newSecurityManager
import commands
+from DateTime import DateTime
from zLOG import LOG
class PublicationSynchronization(XMLSyncUtils):
@@ -225,10 +226,9 @@
"""
This is the synchronization method for the server
"""
- #LOG('PubSync',0,'Starting... id: %s' % str(id))
+ LOG('PubSync',0,'Starting... publication: %s' % str(publication))
# Read the request from the client
xml_client = msg
- publication
if xml_client is None:
xml_client = self.readResponse(from_url=publication.getPublicationUrl())
#LOG('PubSync',0,'Starting... msg: %s' % str(xml_client))
@@ -249,13 +249,7 @@
if client_header.nodeName != "SyncHdr":
#LOG('PubSync',0,'This is not a SyncML Header')
raise ValueError, "Sorry, This is not a SyncML Header"
- for subnode in client_header.childNodes:
- if subnode.nodeType == subnode.ELEMENT_NODE and \
- subnode.nodeName == "Source":
- for subnode2 in subnode.childNodes:
- if subnode2.nodeType == subnode2.ELEMENT_NODE and \
- subnode2.nodeName == "LocURI":
- subscription_url = str(subnode2.childNodes[0].data)
+ subscription_url = self.getSourceURI(client_header)
# Get the subscriber or create it if not already in the list
subscriber = publication.getSubscriber(subscription_url)
if subscriber == None:
@@ -265,8 +259,6 @@
# first synchronization
result = self.PubSyncInit(publication,xml_client,subscriber=subscriber,
sync_type=self.SLOW_SYNC)
-
-
elif self.checkAlert(xml_client) and \
alert_code in (self.TWO_WAY,self.SLOW_SYNC):
result = self.PubSyncInit(publication=publication,
Modified: erp5/trunk/products/ERP5SyncML/Subscription.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/Subscription.py?rev=14982&r1=14981&r2=14982&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/Subscription.py (original)
+++ erp5/trunk/products/ERP5SyncML/Subscription.py Tue Jun 26 16:49:39 2007
@@ -1016,6 +1016,7 @@
signature = self.getSignatureFromGid(gid)
# First look if we do already have the mapping between
# the id and the gid
+ #XXX Slow !!!
object_list = self.getObjectList()
destination = self.getDestination()
if signature is not None and signature.getObjectId() is not None:
@@ -1040,10 +1041,12 @@
"""
object_list = self.getObjectList()
#XXX very slow with lot of objects
+ o = None
for object in object_list:
if object.getId() == id:
- return object
- return None
+ o = object
+ break
+ return o
# def setOneWaySyncFromServer(self,value):
# """
Modified: erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py?rev=14982&r1=14981&r2=14982&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py (original)
+++ erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py Tue Jun 26 16:49:39 2007
@@ -31,6 +31,7 @@
from XMLSyncUtils import XMLSyncUtils, Parse
import commands
from Conduit.ERP5Conduit import ERP5Conduit
+from DateTime import DateTime
from zLOG import LOG
class SubscriptionSynchronization(XMLSyncUtils):
@@ -93,12 +94,13 @@
xml_client = msg
if isinstance(xml_client, str) or isinstance(xml_client, unicode):
xml_client = Parse(xml_client)
- next_status = self.getNextSyncBodyStatus(xml_client, None)
- #LOG('readResponse, next status :',0,next_status)
- if next_status is not None:
- status_code = self.getStatusCode(next_status)
- #LOG('readResponse status code :',0,status_code)
- if status_code == self.AUTH_REQUIRED:
+ status_list = self.getSyncBodyStatusList(xml_client)
+ if status_list not in (None, []):
+ status_code_syncHdr = status_list[0]['code']
+ if status_code_syncHdr.isdigit():
+ status_code_syncHdr = int(status_code_syncHdr)
+ #LOG('readResponse status code :',0,status_code_syncHdr)
+ if status_code_syncHdr == self.AUTH_REQUIRED:
if self.checkChal(xml_client):
authentication_format, authentication_type = self.getChal(xml_client)
#LOG('auth_required :',0, 'format:%s, type:%s' % (authentication_format, authentication_type))
@@ -112,14 +114,13 @@
#LOG('readResponse', 0, 'Authentication required')
response = self.SubSyncCred(subscription, xml_client)
- elif status_code == self.UNAUTHORIZED:
+ elif status_code_syncHdr == self.UNAUTHORIZED:
LOG('readResponse', 0, 'Bad authentication')
return {'has_response':0,'xml':xml_client}
else:
response = self.SubSyncModif(subscription, xml_client)
else:
response = self.SubSyncModif(subscription, xml_client)
-
if RESPONSE is not None:
RESPONSE.redirect('manageSubscriptions')
Modified: erp5/trunk/products/ERP5SyncML/SynchronizationTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/SynchronizationTool.py?rev=14982&r1=14981&r2=14982&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/SynchronizationTool.py (original)
+++ erp5/trunk/products/ERP5SyncML/SynchronizationTool.py Tue Jun 26 16:49:39 2007
@@ -57,6 +57,7 @@
import string
import commands
import random
+from DateTime import DateTime
from zLOG import LOG
@@ -821,7 +822,7 @@
#LOG('sendResponse, to_url: ',0,to_url)
#LOG('sendResponse, from_url: ',0,from_url)
#LOG('sendResponse, sync_id: ',0,sync_id)
- #LOG('sendResponse, xml: \n',0,xml)
+ LOG('sendResponse, xml: \n',0,xml)
if isinstance(xml, unicode):
xml = xml.encode('utf-8')
if domain is not None:
@@ -891,6 +892,7 @@
opener = urllib2.build_opener(proxy_handler, proxy_auth_handler,
auth_handler, urllib2.HTTPHandler)
urllib2.install_opener(opener)
+ socket.setdefaulttimeout(3660)
to_encode = {}
head = '<?xml version="1.0" encoding="UTF-8"?>'
to_encode['text'] = head + xml
@@ -905,8 +907,8 @@
request = urllib2.Request(url=to_url, data=data)
#XXX only to synchronize with other server than erp5 (must be improved):
-# data=head+xml
-# request = urllib2.Request(to_url, data, headers)
+# data=head+xml
+# request = urllib2.Request(to_url, data, headers)
try:
result = urllib2.urlopen(request).read()
except socket.error, msg:
@@ -957,6 +959,7 @@
We will look at the url and we will see if we need to send mail, http
response, or just copy to a file.
"""
+ LOG('readResponse, text :', 0, text)
# Login as a manager to make sure we can create objects
uf = self.acl_users
user = uf.getUserById('syncml').__of__(uf)
Modified: erp5/trunk/products/ERP5SyncML/XMLSyncUtils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/XMLSyncUtils.py?rev=14982&r1=14981&r2=14982&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/XMLSyncUtils.py (original)
+++ erp5/trunk/products/ERP5SyncML/XMLSyncUtils.py Tue Jun 26 16:49:39 2007
@@ -453,6 +453,15 @@
next_anchor = next_anchor.encode('utf-8')
return next_anchor
+ def getSourceURI(self, xml):
+ """
+ return the source URI of the syncml header
+ """
+ subscription_url = xml.xpath('string(//SyncHdr/Source/LocURI)')
+ if isinstance(subscription_url, unicode):
+ subscription_url = subscription_url.encode('utf-8')
+ return subscription_url
+
def getStatusTarget(self, xml):
"""
Return the value of the alert code inside the xml_stream
@@ -590,34 +599,7 @@
tmp_dict['source'] = status.xpath('string(./SourceRef)').encode('utf-8')
tmp_dict['target'] = status.xpath('string(./TargetRef)').encode('utf-8')
status_list.append(tmp_dict)
-
return status_list
-
- def getNextSyncBodyStatus(self, xml_stream, last_status):
- """
- It goes throw actions in the Sync section of the SyncML file,
- then it returns the next action (could be "add", "replace",
- "delete").
- """
- first_node = xml_stream.childNodes[0]
- client_body = first_node.childNodes[3]
- if client_body.nodeName != "SyncBody":
- #LOG('getNextSyncBodyStatus',0,"This is not a SyncML Body")
- raise ValueError, "Sorry, This is not a SyncML Body"
- next_status = None
- found = None
- for subnode in client_body.childNodes:
- if subnode.nodeType == subnode.ELEMENT_NODE and \
- subnode.nodeName == "Status":
- # if we didn't use this method before
- if last_status == None:
- next_status = subnode
- return next_status
- elif subnode == last_status and found is None:
- found = 1
- elif found is not None:
- return subnode
- return next_status
def getDataText(self, action):
"""
@@ -642,24 +624,9 @@
"""
Return the node starting with <object....> of the action
"""
- for subnode in action.childNodes:
- if subnode.nodeType == subnode.ELEMENT_NODE and \
- subnode.nodeName == 'Item':
- for subnode2 in subnode.childNodes:
- if subnode2.nodeType == subnode2.ELEMENT_NODE and \
- subnode2.nodeName == 'Data':
- for subnode3 in subnode2.childNodes:
- #if subnode3.nodeType == subnode3.ELEMENT_NODE and subnode3.nodeName == 'object':
- if subnode3.nodeType == subnode3.COMMENT_NODE:
- # No need to remove comment, it is already done by FromXml
- #if subnode3.data.find('<!--')>=0:
- # data = subnode3.data
- # data = data[data.find('<!--')+4:data.rfind('-->')]
- xml = subnode3.data
- if isinstance(xml, unicode):
- xml = xml.encode('utf-8')
- return xml
-
+ comment_list = action.xpath('.//Item/Data[comment()]')
+ if comment_list != []:
+ return comment_list[0].childNodes[0].data.encode('utf-8')
return None
def getActionId(self, action, action_name):
@@ -1193,14 +1160,8 @@
simulate = 0 # used by applyActionList, should be 0 for client
if domain.domain_type == self.PUB:
simulate = 1
- for subnode in xml_header.childNodes:
- if subnode.nodeType == subnode.ELEMENT_NODE and \
- subnode.nodeName == "Source":
- for subnode2 in subnode.childNodes:
- if subnode2.nodeType == subnode2.ELEMENT_NODE and \
- subnode2.nodeName == 'LocURI':
- subscription_url = str(subnode2.childNodes[0].data)
- subscriber = domain.getSubscriber(subscription_url)
+ subscription_url = self.getSourceURI(xml_header)
+ subscriber = domain.getSubscriber(subscription_url)
# We have to check if this message was not already, this can be dangerous
# to update two times the same object
More information about the Erp5-report
mailing list