Commit 640654ed authored by Ivan Tyagov's avatar Ivan Tyagov

Extend remote method caller API.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29970 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent be553671
...@@ -75,7 +75,7 @@ def _isUserAcknowledged(cookiejar): ...@@ -75,7 +75,7 @@ def _isUserAcknowledged(cookiejar):
if cookie.name == '__ac' and cookie.value != '': if cookie.name == '__ac' and cookie.value != '':
return 1 return 1
return 0 return 0
def _getAcCookieFromServer(url, opener, cookiejar, username, password, header_dict = {}): def _getAcCookieFromServer(url, opener, cookiejar, username, password, header_dict = {}):
""" get __ac cookie from server """ """ get __ac cookie from server """
data = urllib.urlencode({'__ac_name': username, data = urllib.urlencode({'__ac_name': username,
...@@ -86,7 +86,7 @@ def _getAcCookieFromServer(url, opener, cookiejar, username, password, header_di ...@@ -86,7 +86,7 @@ def _getAcCookieFromServer(url, opener, cookiejar, username, password, header_di
class GeneratorCall(UserDict): class GeneratorCall(UserDict):
""" Class use to generate/interpret XML-RPC call for the wizard. """ """ Class use to generate/interpret XML-RPC call for the wizard. """
_binary_keys = ("data", "filedata", "previous", "next",) _binary_keys = ("data", "filedata", "previous", "next",)
_string_keys = ( "command", "server_buffer",) _string_keys = ( "command", "server_buffer",)
...@@ -95,7 +95,7 @@ class GeneratorCall(UserDict): ...@@ -95,7 +95,7 @@ class GeneratorCall(UserDict):
self.convert_data = {} self.convert_data = {}
for key in (self._binary_keys + self._string_keys): for key in (self._binary_keys + self._string_keys):
self.setdefault(key, None) self.setdefault(key, None)
def load(self, xmlrpccall): def load(self, xmlrpccall):
""" Convert the xmlrpccall into the object. """ """ Convert the xmlrpccall into the object. """
self.convert_data = xmlrpclib.loads(xmlrpccall)[0][0] self.convert_data = xmlrpclib.loads(xmlrpccall)[0][0]
...@@ -389,11 +389,14 @@ class WizardTool(BaseTool): ...@@ -389,11 +389,14 @@ class WizardTool(BaseTool):
transport = 'xml-rpc') transport = 'xml-rpc')
return handle.portal_witch return handle.portal_witch
def callRemoteProxyMethod(self, distant_method, server_url=None, use_cache=1, **kw): def callRemoteProxyMethod(self, distant_method, server_url=None, \
use_cache=1, ignore_exceptions=1, **kw):
""" Call proxy method on server. """ """ Call proxy method on server. """
configurator_user_preferred_language = self.getConfiguratorUserPreferredLanguage() configurator_user_preferred_language = self.getConfiguratorUserPreferredLanguage()
def wrapper(distant_method, **kw): def wrapper(distant_method, **kw):
return self._callRemoteMethod(distant_method, use_proxy=1, **kw)['data'] return self._callRemoteMethod(distant_method, \
use_proxy=1, \
ignore_exceptions=ignore_exceptions, **kw)['data']
if use_cache: if use_cache:
wrapper = CachingMethod(wrapper, wrapper = CachingMethod(wrapper,
id = 'callRemoteProxyMethod_%s_%s' id = 'callRemoteProxyMethod_%s_%s'
...@@ -402,7 +405,8 @@ class WizardTool(BaseTool): ...@@ -402,7 +405,8 @@ class WizardTool(BaseTool):
rc = wrapper(distant_method, **kw) rc = wrapper(distant_method, **kw)
return rc return rc
def _callRemoteMethod(self, distant_method, server_url=None, use_proxy=0, **kw): def _callRemoteMethod(self, distant_method, server_url=None, \
use_proxy=0, ignore_exceptions=1, **kw):
""" Call remote method on server and get result. """ """ Call remote method on server and get result. """
result_call = GeneratorCall() result_call = GeneratorCall()
user_name = None user_name = None
...@@ -426,6 +430,7 @@ class WizardTool(BaseTool): ...@@ -426,6 +430,7 @@ class WizardTool(BaseTool):
self._updateParameterDictWithServerInfo(parameter_dict) self._updateParameterDictWithServerInfo(parameter_dict)
## handle file upload ## handle file upload
self._updateParameterDictWithFileUpload(parameter_dict) self._updateParameterDictWithFileUpload(parameter_dict)
message = None
## call remote method ## call remote method
try: try:
method = getattr(witch_tool, distant_method) method = getattr(witch_tool, distant_method)
...@@ -457,6 +462,9 @@ class WizardTool(BaseTool): ...@@ -457,6 +462,9 @@ class WizardTool(BaseTool):
result_call.load(html) result_call.load(html)
command = result_call["command"] command = result_call["command"]
html = result_call["data"] html = result_call["data"]
if message is not None and not ignore_exceptions:
# raise last cought exception
raise
return result_call return result_call
def _setServerInfo(self, **kw): def _setServerInfo(self, **kw):
......
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